Code

 

Data Files - Used in the code example below!

prices prices.dat
shipped shipped.dat
test test.dat

 

Header Files: <anything.h>

custom_1 class custom_1.h
customer (2) class customer.h
pump class pump.h

 

Lecture Notes - Supplementary Code

Pendulum Code pendulum.cpp
Integer Overflow ex. int_overflow.cpp
Integer Underflow ex. int_underflow.cpp
Accumulator accumulator.cpp
if-else if-else vs switch example perc_to_grade.cpp
infinite loop repetitions_infinite.cpp

 

Further Examples (mainly from Bronson Book)

Basic C++ Operations - Programs

Hello World Program pgm2-1.cpp
Double cout pgm2-2.cpp
Use of newline character in cout pgm2-3.cpp
Simple Expressions pgm2-5.cpp
Average between two numbers pgm2-6.cpp
Similar to above pgm2-6a.cpp
Using char data type pgm2-7.cpp
Displaying an integer variable pgm2-8.cpp
The address also! in RAM of the int variable pgm2-9.cpp
Bytes used for int and char pgm2-10.cpp
Circumference of circle given radius pgm2-11.cpp
Another calculation pgm2-12.cpp
More calculations pgm2-13.cpp

Formatting Output and Basic Functions

Volume of a cylinder given radius and height pgm3-1.cpp
Incrementing counters pgm3-2.cpp
Use of the same variable pgm3-3.cpp
++ Operator pgm3-4.cpp
Demonstration of cout pgm3-5.cpp
Demonstration of setw pgm3-6.cpp
Demonstration of setiosflags to print in octal and hexadecimal pgm3-7.cpp
Displaying decimal values from octal and hexadecimal pgm3-8.cpp
Using the math library pgm3-9.cpp
Printing a variable-expression pgm3-10.cpp
without a variable pgm3-11.cpp
Inserting from the keyboard - cin pgm3-12.cpp
More cin pgm3-13.cpp
Formatting output with iomanip.h pgm3-14.cpp
math library pgm3-15.cpp
math & formatting output pgm3-16.cpp
compound interest program pgm3-17.cpp

Selection Statements

Tax program pgm4-1.cpp
Temperature Conversion program pgm4-2.cpp
Simple if demonstration pgm4-3.cpp
+, =, == demo pgm4-4.cpp
if-else if program pgm4-5.cpp
Another if-else if-else example pgm4-6.cpp
Simple menu program pgm4-7.cpp
Square root & reciprocal pgm4-8.cpp
Finding the roots of a quadratic equation pgm4-9.cpp
if else very simple example pgm4-10.cpp

Loops

simple while loop pgm5-1.cpp
another one - decrementing pgm5-2.cpp
another while loop example pgm5-3.cpp
degrees-fahrenheit table pgm5-4.cpp
Entering x numbers pgm5-5.cpp
Calculating total of x numbers pgm5-6.cpp
& average pgm5-7.cpp
use of sentinel number to stop looping pgm5-8.cpp
for loop table pgm5-9.cpp
another for loop example pgm5-10.cpp
with initialisation part missing pgm5-10a.cpp
with incrementing inside loop pgm5-10b.cpp
another for loop table pgm5-11.cpp
total & avg of x numbers using a for loop pgm5-12.cpp
+ve vs -ve total pgm5-13.cpp
another for loop example pgm5-14.cpp
with different formatting pgm5-15.cpp
table of numbers pgm5-16.cpp
nested for loops pgm5-17.cpp

Functions & random numbers

function declaration & call pgm6-1.cpp
findmax function of 2 nums pgm6-2.cpp
function declaration-definition pgm6-3.cpp
function using template classes pgm6-4.cpp
another findmax function example pgm6-5.cpp
fahrenheit to celsius pgm6-6.cpp
same as an inline function pgm6-7.cpp
global vs local variables pgm6-8.cpp
another one  pgm6-9.cpp
demonstration of :: pgm6-9a.cpp
simple function pgm6-10.cpp
another one pgm6-11.cpp
call by reference example pgm6-12.cpp
call by value vs by reference pgm6-13.cpp
call by reference - swap function pgm6-14.cpp
factorial function pgm6-15.cpp
generating ten pseudo-random numbers pgm6-16.cpp
tossing a coin pgm6-17.cpp
a game of guessing the right number using random numbers pgm6-18.cpp

simple Classes

simple Date Class pgm7-1.cpp
Another Date Example pgm7-2.cpp
Another Date Example pgm7-3.cpp
An elevator Class pgm7-4.cpp
class Pump pgm7-5.cpp

constructors & overloading & friend functions

Constructor with default values pgm8-1.cpp
assignment operator overload pgm8-2.cpp
copy constructor pgm8-3.cpp
Employee class pgm8-4.cpp
continued pgm8-5.cpp
complex numbers class pgm8-6.cpp
date class with == overloaded pgm8-7.cpp
with + operator overloaded pgm8-8.cpp
with [] operator overloaded pgm8-9.cpp
Date class example pgm8-10.cpp
Date class with conversion operator pgm8-11.cpp
Another conversion operator ex pgm8-12.cpp
including .h files pgm8-13.cpp
friend functions pgm8-14.cpp

Inheritance & virtual functions

class Circle pgm9-1.cpp
class One & Two public inheritance pgm9-2.cpp
virtual functions pgm9-3.cpp
class Date pgm9-4.cpp
continued pgm9-5.cpp
class Customer pgm9-6.cpp
using Pump & Customer classes pgm9-7.cpp
class Test pgm9-8.cpp
class Book pgm9-9.cpp

File I/O and string streams

opening an input file stream pgm10-1.cpp
writing to an output file pgm10-2.cpp
read from a file and print on screen pgm10-3.cpp
same but line by line pgm10-4.cpp
using offsets pgm10-5.cpp
from keyboard to output file pgm10-6.cpp
pollen reading from a file pgm10-8.cpp
another file update example pgm10-9.cpp
using string streams pgm10-10.cpp
successful opening of a file pgm10-1a.cpp
similar pgm10-1b.cpp

Arrays

Simple integer array pgm11-1.cpp
calculating the sum of elements pgm11-2.cpp
maximum value of array elements pgm11-3.cpp
passing array as function argument pgm11-4.cpp
slightly different pgm11-5.cpp
2D array pgm11-6.cpp
another 2D array pgm11-7.cpp
2D array as a function argument pgm11-8.cpp
array addresses and size pgm11-9.cpp
average & standard deviation pgm11-10.cpp
inserting new values in an array pgm11-11.cpp
linear search pgm11-12.cpp
binary search pgm11-13.cpp
selection sort pgm11-14.cpp
bubble sort pgm11-15.cpp
partition pgm11-16.cpp
quicksort using partition pgm11-17.cpp

String Functions

reading a line to a string pgm12-1.cpp
string copy function pgm12-2.cpp
get a line character by character pgm12-3.cpp
get a line function pgm12-4.cpp
demonstration of string.h functions pgm12-5.cpp
lowercase character to uppercase pgm12-6.cpp
string to integer & double pgm12-7.cpp
count characters in a line pgm12-8.cpp
count words pgm12-9.cpp
cstrings pgm12-10.cpp

Addresses & Pointers

address of a variable pgm13-1.cpp
simple pointer to an integer pgm13-2.cpp
reference variable pgm13-3.cpp
same pgm13-4.cpp
displaying array elements pgm13-5.cpp
same using pointer arithmetic and dereferencing pgm13-6.cpp
as above pgm13-7.cpp
dynamic arrays pgm13-8.cpp
another pointer arithmetic example pgm13-9.cpp
while loop example pgm13-10.cpp
another example pgm13-11.cpp
swap function using pointers pgm13-12.cpp
findmax function of array pgm13-13.cpp
simple character array pgm13-14.cpp
another example of a character array pgm13-15.cpp

Structs

simple struct birth pgm14-1.cpp
struct Date pgm14-2.cpp
struct Payrecord pgm14-3.cpp
struct Employee oblect passed as an argument to a function pgm14-4.cpp
by reference! pgm14-4a.cpp
as a pointer pgm14-5.cpp
another example pgm14-6.cpp
struct Test pgm14-7.cpp
struct TeleType pgm14-8.cpp
display function for above struct pgm14-9.cpp
more functions pgm14-10.cpp
another example pgm14-11.cpp
struct Customer pgm14-12.cpp
struct PayRecord pgm14-13.cpp

classes Stack & Queue

class Stack pgm15-1.cpp
more functions pgm15-2.cpp
class Queue pgm15-3.cpp
more functions pgm15-4.cpp

Miscellaneous

using namespaces pgmf-1.cpp
vectrom & algorithm example pgmg-1.cpp
enumerated Colour type pgmj-1.cpp
command prompt arguments pgmj-2.cpp
displays command line arguments pgmj-3.cpp