Review for Final Exam
Contents 5 questions (20 points each) + 1 bonus question (20 points) Basic concepts in Chapters 1-4 Chapters 5-9 Bonus: Chapter 5 Question types Write down the output of the code Write the code Debug errors in the code Review Lecture slides Exercises (1)~(19) in class (on the course Web page) Review problems for final exam (on the course Web page)
Time & Place & Event Time: 5:45pm - 7:30 pm, May 6 (Tuesday) Place: Math & General Classroom 2.206 Closed-book exam You can take a piece of cheating paper with A4 size Write down whatever that you think is important (on both sides) with any font size
Chapter 2: Basic Elements of C++ Special symbols, keywords, rules of identifiers Basic data types int, float, double, char, string Operators Arithmetic operators and their precedence +, -, *, /, %, +=, -=, *=, /= Increment/decrement operator ++, -- Declaration of variables int first=13, second=10; char ch=' '; Input/Output statement cin and cout
Chapter 3: Input/Output Declaration of input/output stream Usage of cin and cout (as well as other istream/ostream variables)
Chapter 4: Control Structures I (Selection) Relational operators and precedence Comparison operators <, <=, >, >=, ==, != String comparison Logical operators &&, | | Evaluation of logical expression
Chapter 4: Control Structures I (Selection, cont'd) Syntax and usage of the selection structure One-way selection: if () { } Compound statements Two-way selection: if () { } else { }
Chapter 5: Control Structures II (Repetition) Repetition structure Syntax and usage of the "for" loop The nested for loop
Chapters 6 & 7: User-Defined Functions Two types of user-defined functions Value-returning functions and void functions Differences Syntax of function heading Function prototype Function heading without the body of the function
Chapters 6 & 7: User-Defined Functions (cont'd) Function call Use function name together with the actual parameter list Two types of formal parameters Value parameters Reference parameters Differences Scope of an identifier Local identifier Global identifier
Chapters 6 & 7: User-Defined Functions (cont'd) Function overloading several functions with the same name but different parameter lists Default parameters in function prototype Places of default values Default values cannot be assigned to reference parameters See legal and illegal examples in lecture slides
Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type Syntax of declaring an enumeration data type Syntax of declaring a namespace String data type Syntax of declaring and initializing a string variable string name = "William Jacob"; Syntax of accessing characters in the string using array subscript operator [] name[0]
Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type (cont'd) Basic operations/methods of string data type str = name + " Day"; name.length()
Chapter 9: Arrays and Strings* Declaration and initialization of arrays Syntax and usage Accessing array components array subscripting operator [ ] How to use for loops to access array elements for (i = 0; i < 100; i++) Initialization: list[i] = 0.0; read data: cin >> list[i]; Print data: cout << list[i]; Search a key item from the array find the sum, average, largest See lecture slides int num[5];
Chapter 9: Arrays and Strings* (cont'd) Array initialization during the declaration double sales[] = {12.25, 32.50, 16.90, 23, 45.68}; int list[10] = {0}; int list[10] = {8, 5, 12}; int list[] = {5, 6, 3}; int list[25]= {4, 7}; See lecture slides Restrictions of array Does not allow aggregate operations Must use for loop to copy from one array to another
Chapter 9: Arrays and Strings* (cont'd) C-String (character array) C-strings are null-terminated ('\0') character arrays Declaration and initialization char name[16] = "John"; char name[] = "John"; Access the character in the C-String name[0] ~ name[3] '\0' is not counted at the length of the C-String Parallel arrays Two (or more) arrays holding related information in the corresponding components 2-dimensional arrays
Good Luck! Q/A