CIS 554
Spring 2003
Doctor Baruch
Examples
Bottom of page
-
January 14
-
January 16
-
someinput, illustrating input of char, int, and float, assignment,
standard input (cin) and output (cout).
-
January 21
-
input streams with cin for char, int, float
-
logical operators: = = , <=, >=, !=, !, &&, || for use in an
if
-
true (non-zero), false (zero)
-
get and set functions
-
public vs private data
-
function return values
-
writing implementations of member functions
-
January 23
-
lending example: functions, reference and value parameters, boolean type,
while loop, +=
-
continue and break example: for loops, ++, %, continue,
break
-
January 28
-
Discuss the game in HW 2
-
continue with contAndBreak example
-
choices example: more on ifs, switch statement, char as int
-
January 30
-
swapper example: more on reference vs value parameters, function overloading
-
boxes example: writing a class; constructors - default and alternate;
static_cast<float>; nested for loops.
-
February 4
-
BetterTime. The Time class revisited, done with multiple files.
#ifndef, #define, #endif (around .h files); operators as member functions
and operators as global functions;
-
The following files all have to be put in the same project.
-
February 6
-
Discussion of what is needed for Homework 3. Please make sure you
read the updated assignment page.
-
Further discussion of the BetterTime project.
-
binary operators as member functions and as non-member functions.
-
How to write an operator function.
-
How to call an operator function from another function (like main)
-
How the compiler knows which function is being called.
-
private is private to class, not to object.
-
Parameters of functions can be of a class. This is true for member
functions of that class, global functions, or even member functions of
another class.
-
forward declaration.
-
multiple file projects.
-
upcoming exam
-
types of questions
-
multiple choice where you circle all the correct answers (there could be
more than one correct answer)
-
true/false where you have to explain
-
write program or function
-
write a code segment - this is just a few lines of code that would be part
of a more substantial function.
-
you give the output of some code I provide
-
short answers
-
you may bring an 8.5 in by 11 in piece of paper with anything you want
on it. These may not be shared.
-
You may bring a foreign language dictionary. They may not be shared.
-
Bring plenty of pencils and erasers.
-
exam topics posted. See announcement page.
-
February 11
-
more discussion of BetterTime project
-
discuss exam topics.
-
constructors and destructors
-
February 13
-
February 18
-
arrays
-
addanint :Declaring an array; accessing its elements; assigning to elements;
keeping track of how full it is; moving elements within an array
-
arrayoftimes: Arrays of objects; array items calling member functions;
whole arrays as parameters and arguments; array items as arguments
-
February 20
-
more discussion of arrays
-
input and output streams
-
inoutfiles.cpp
a program than uses input from both the keyboard (cin) and a file on the
hard drive and sends output to both the monitor and a file on the hard
drive.
-
myindata.txt
the input file. It must be in your project folder.
-
myoutdata.txt
the output file produced by the program or overwritten by the program.
If you try open to see it after you run your program, and it isn't there,
make sure under "Objects of Type" all file types are listed, or at least
.txt
-
inoutfilesout.txt
What you see on the monitor.
Note: If you want a function to have a parameter that could be
an input file stream or could be cin, declare the parameter as an istream.
Similarly, if you want a function to have a parameter that could be an
output file stream or could be cout, declare the parameter as an ostream.
istream and ostream paramenter
istreams and ostreams should always be passed by reference with &.
-
February 25
-
more on streams
-
house example. Composite (conglomerate, aggregate) class; overloading
<< ; friend functions; ( warning about friends in some VC++
compilers.);
-
February 27
-
enumerated types, static member data, static member functions
-
random number generators, rand(), srand() and seeding functions, accessing
the computer's time
-
March 4
-
discuss HW 4
-
discuss composite classes
-
femalestudent::makenoise(), malestudent::makenoise(), team::makenoise()
-
random number generators, proper modeling, simulation
-
March 6
-
more discussion of the house class
-
pointer, &, *
-
March 11 and 13
-
March 18
-
the freestore: dynamic memory allocation - new, delete, and delete[ ];
dangling pointers, null pointer, memory leaks; using a variable to set
the size of an array;
-
default parameters - order used
-
pointers and member functions: -> for (* ... ).
-
some notes on strings for hw5 part 1: strings.html
-
March 20
-
nodes and linked lists
-
The node class. Use nodetest.cpp to test it
-
Now add the linklist file to the same project (comment the #define
in nodetest.cpp)
-
March 25
-
in depth look at linklist.
-
March 27
-
April 1
-
stings Cstrings vs C++ strings (see also March 18)
-
using arrays of pointers to sort
-
April 3
-
inheritence, derived classes, polymorphism. The following is one
project. Make sure you only have one active main.
-
mammal.hmammal.cpp
The base class
-
dog.h
dog.cpp
A derived class
-
output is part of classtestout.txt
-
bynameorpointer.cpp
a program using derived classes, accessed by name and by pointers to the
derived class and pointers to the base class (polymorphism)
-
April 8
-
discuss exam 2
-
finish discussion of the mammal example: objects accessed through pointers
and virtual functions.
-
April 10
-
developing a card catalogue data base, polymorphism
-
card.h
card.cpp
base class and derived classes, virtual destructor
-
maincat.cpp
array of pointers to objects of both base and derived classes, polymorphism,
how to delete the objects from an array of pointers.
-
somecards.txt
an input file, designed to be read by a computer
-
nicelook.txt
an output file, designed to be read by people
-
April 15
-
finish discussing the card catalogue
-
screenbuffer example: graphics ideas, two dimensional arrays
-
April 17
-
April 22
-
a get around for a bug in Visual C++ when using getline with C++ strings
and cin
-
checking_getline.cpp You can use the
C string version of getline, then easily copy from C string to a C++ string.
-
copy constructor and operator=, static variables as counters, static variable
for ofstream, return by value versus return reference
-
April 24
-
copy constructor and operator= when there is data that is attached to a
class through a pointer.
-
deepcopy.cpp the family class. Run
with #define GOODCOPY commented out, and run again with it active (i.e.
not commented out). The output from each run is appended in
a file familyout.txt.
-
familyout.txt the output of two runs
with two line inserted to separate the output.
-
working with multidimensional arrays
-
Here is the program that you will be asked about for the final. Make
a printout. Run several times. Check the output on screen and
in the output file it creates, AllSales.txt. The program runs, but
leaves a lot to be desired. You may discuss the program with others,
ask me questions, etc. For the final, I will be handing out a fresh
copy for you to use. You will not be able to use your annotated versions.
-
April 29
-
template functions
-
template classes
-
multiple inheritance