You can use a graphic library and build a GUI. This quarter we didn't do any of this seeing it is not standard and is not in the book.
Or you can write a whole library of functions to write out the symbols in large format:
X X
X X
X X
X
X X
X X
X XI figure you would need about 11 functions or a single function with an argument and a rather large selection of 11 different forms.
Give an example of a working function
In class we did one to switch the first and last names
of a person. See next question.
Please go over strings
In class we did a series of examples based on slicing up a string
containing a first name, and initial, and a surname. We turned this
into a string with the surname, a comma, and the firstname.
We used
string example(string name)
{ // assume name = "First Initial Last"
// return "Last, First"
int sp1 = name.find(' ');
int sp2 = name.rfind(' ');
return name.substr(sp2+1)+ ", "+ name.substr(0,sp1);
}[ texample.cpp ]
More on strings see:
[ 09.html ]
Please go over Classes
[ 15.html ]
[ 16.html ]
Do classes seem easy to me
As long as they only have simple member functions they are simple.
Thinking about classes is more abstract than trying to avoid them.
Practice makes it easier.
How do member functions effect classes and the rest of the program
A member function is always applied to an object:
object.function(data)Objects contain data members, The function accesses these data variables, for the object and can change them.
The class doesn't change -- the objects change.
Member functions can reutrn values that are used in the rest of the program.
Member functions
can also refer to global variables like cout and cin and som
make the program do things. The wise programmer avoids this if at all possible.
Is there a way to avoid overloading constructors
Mostly you want to!
Be careful with the definitions and default parameters. There is also an advanced declaration that stops the compiler providing the default constructor when you declare a variable.... CSci202 or 330.
Please go over Arrays
An array is a collection of elements -- all the same size, and
numbered from 0 upward. It has a fixed number elements. The size
of the array is fixed when we declare it and can not be changed.
Think of arrays as a series of boxes. One box per item. No space between them. Labeled with numbers: 0,1,2,3,....
See [ 07.html#More%20About%20Arrays ] for a simple example of declaring and using an array.
The following link
[ lookup.php?search=array&from=cs201.20 ]
will take you to a list of places in this course where we have talked
about arrays.
Please go over vectors
[ vectors.html ]
[ ../examples/vectors.cpp ]
Go over pointers
A pointer is a special type of data. It holds an address. It is used
to remember where the "real" data is kept. Think of it a variable that
has a cell phone number in it. You can dial the number and contat the phone
by putting the de-reference "*" operator in front of the variable. In
reverse the "&" is the address of operator and returns a value you
can store in a pointer:
Wise programmers often add a "p" to the ends of pointer variable names.
Go over new and delete
New T gives you a piece of storage the right size for an object
of type T. It returns the address of the block of storages and so you should
use it like this
T *tp = new T;From then on '*tp' is the new object.
You should return the storage when your prgram has finished with it like this
delete tp;Noticw the abscence of an asterisk. The machine needs to be given the address of the object to be returned.
You can also use new to get an array of objects...
. . . . . . . . . ( end of section Questions) <<Contents | End>>
Next Final Examination and Project 9