[ lab03.html ]
[ lab02bad.cpp ]
+ Four of my solutions:
[ lab02string.cpp ]
(use C++ 'string' type)
[ lab02get.cpp ]
[ lab02get2.cpp ]
(input one character at a time and discard the extra ones)
[ lab02getline.cpp ]
(use getline... and tidy up extra input if needed).
[ http://cse.csusb.edu/dick/cs202/ ]
Arrays are efficient but dangerous to use.
It is wise to wrap up a dangerous data structure inside a class.
We hide the data by making it private. We have only a few safe operations
that make public. Anything which might be abused is private.
So we forbid the dangerous operations and only allow the safe ones.
We use assert to protect our safe operations from abuse.
We provide the user with a safe Application Programmer Interface -- -- --(API)
We also provide common constructors and operators that application
By the end of the lab you should know more about coding classes that
include common constructors and operators.
A working program that uses a safe 8 character Buffer class
that does the useful things of the lab02 program
but does not permit the abuse possible in lab02.
[ lab04main.cpp ]
is a program that is designed to test a new safe Buffer class. Download a copy of this.
The safe buffer was defined in a file called buffer04.h.
It worked until I
deleted some functions header lines from the function definitions
and replaced them by
Here is the result
[ buffer04.h ]
Download this "header" file.
Your task is to use the book, the compiler, your brain, and my advice
to replace the DELETED lines
until it compiles and runs.
Do not change the main program. Do not change anything but the DELETED lines in
the .h file.
The buffer04.h file defines special meanings for the operators
<<, >>, ==, . You can find out more about this elegant technique in
section 14.1 of our text. All you need for today is to know that
is the name of a function that does the operation "=="!
There are things that still need improving in these two files.
Do not do these. We will tackle them in later labs.
If you have time at the end of the lab, work on
your next project.
[ lab05.html ]
you will add new features to a program, one step at a time, by deriving new classes from
. . . . . . . . . ( end of section CSci202 Laboratory 04 Classes) <<Contents | End>>
- accessor::=`A Function that accesses information in an object with out changing the object in any visible way".
In C++ this is called a "const function".
In the UML it is called a query.
- Algorithm::=A precise description of a series of steps to attain a goal,
[ Algorithm ]
- class::="A description of a set of similar objects that have similar data plus the functions needed to manipulate the data".
- constructor::="A Function in a class that creates new objects in the class".
- Data_Structure::=A small data base.
- destructor::=`A Function that is called when an object is destroyed".
- Function::programming=A selfcontained and named piece of program that knows how to do something.
- Gnu::="Gnu's Not Unix", a long running open source project that supplies a
very popular and free C++ compiler.
- mutator::="A Function that changes an object".
- object::="A little bit of knowledge -- some data and some know how". An
object is instance of a class.
- objects::=plural of object.
- OOP::="Object-Oriented Programming",
Current paradigm for programming.
- Semantics::=Rules determining the meaning of correct statements in a language.
- SP::="Structured Programming",
a previous paradigm for programming.
- STL::="The standard C++ library of classes and functions" -- also called the
"Standard Template Library" because many of the classes and functions will work
with any kind of data.
- Syntax::=The rules determining the correctness and structure of statements in a language, grammar.
- Q::software="A program I wrote to make software easier to develop",
- TBA::="To Be Announced", something I should do.
- TBD::="To Be Done", something you have to do.
- UML::="Unified Modeling Language".
- void::C++Keyword="Indicates a function that has no return".