









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Notes; Class: Introduction to Computer Science II; Subject: Computer/Information Sciences; University: University of Delaware; Term: Unknown 1989;
Typology: Study notes
1 / 16
This page cannot be seen from the preview
Don't miss anything!










three ways to do it
some operators only work with some ways
parameters and return values - thinking about const and references
mixing types - adding Money and int
how could we make it easier to work with the Store example?
overload << to make it easier to display
overload +=, -= for deposit/withdrawal
a sequence of characters
two different kinds
C-style string (char arrays)
string class
int toupper(char)
int tolower(char)
bool isalpha(char)
and many more! (p. 380)
be very careful when using the ones that return ints!
an array of characters: char str[] = “Hi”;
in this case (no array size), it picks the size automatically
null terminator - the end of the string is a special character ‘\0’
as a numeric value, this is 0
significance of the null terminator
loops use it to process a string: int i = 0; while (str[i] != ‘\0’) cout << str[i] << “ “;
if the null terminator is overwritten somehow, it’ll just keep going through memory
= and == don’t work like normal
= just fails in normal settings, use strcpy(to, from) in cstring instead
strcpy(to, from, num_chars) is another form
== will just check that the array pointers are the same, which isn’t comparing contents
can use with cout (works normally)
can use with cin (gets one word)
if you want to get multiple words, use cin.getline(string, max_chars)
be careful about using both >> and getline in the same program!
cin has some other handy functions:
cin.get() - gets a char
cin.peek() - looks at the next char but doesn’t change the buffer
cin.putback(char) - puts a char back
cin.ignore(int num_chars, char terminator) - ignores up to num_chars on the stream or until it hits the terminator char
C++ string class
pointers overview
midterm review