1 / 17

Review for Final Exam

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

bolszewski
Download Presentation

Review for Final Exam

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Review for Final Exam

  2. 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)~(18) in class (on the course Web page) • Review problems for final exam (on the course Web page)

  3. Time & Place & Event • 5:45 pm -7:30 pm, May 8 (Tuesday) • ENGR 1.262 • 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

  4. 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

  5. Chapter 3: Input/Output • Declaration of input/output stream • Usage of cin and cout (as well as other istream/ostream variables)

  6. Chapter 4: Control Structures I (Selection) • Relational operators and precedence • Comparison operators • <, <=, >, >=, ==, != • String comparison • Logical operators • &&, | | • Evaluation of logical expression

  7. 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 { }

  8. Chapter 5: Control Structures II (Repetition) • Repetition structure • Syntax and usage of the "for" loop • The nested for loop

  9. 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

  10. 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

  11. 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

  12. 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]

  13. 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()

  14. 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];

  15. 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 opertions • Must use for loop to copy from one array to another

  16. 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

  17. Good Luck! Q/A

More Related