CSCI 123 – Exam 3 – Final Exam Study Guide
Exam Date: Wednesday, December 6th, 2023, at 4:15pm
Permitted Materials:
• Pen(s), pencil(s), eraser(s)
• One (1) handwritten 3-inch x 5-inch index card. Both sides of this index card may be used for your hand-
written notes, (i.e. written in your handwriting, not typed). If you do not comply with these instruc-
tions, you will not be permitted to use your index card during the exam.
• A scientific calculator. No graphing calculators, phones, or smart devices are permitted.
Topics
• Input/Output via iostream - (Chapter 1-2)
◦ cout and insertion operator <<
◦ cin and extraction operator >>
◦ Insert new lines via endl or "\n"
◦ Print complex output via multiple <<
◦ std namespace
• Program Structure – (Chapter 1-2)
◦ The main() function
◦ Inclusion of libraries
◦ The placement of function declarations and definitions in a program file
• Variable Declaration and Assignment – (Chapter 2)
◦ Define what a variable actually is
◦ Declaration statements
▪ initialization of variables within a declaration statement
◦ Assignment statements
◦ Values assignable to variables
▪ type-specific literals
▪ other variable’s values
▪ results of expressions and function calls (see Chapter 4)
◦ The const modifier
• Data Types – (Chapter 2)
◦ Values and ranges
◦ Implicit vs. explicit conversions
▪ know what triggers an implicit conversion
▪ static_cast()
Page 2 of 6
• Expressions – (Chapter 2-3)
◦ Arithmetic expressions
◦ Boolean expressions
◦ Precedence of arithmetic and boolean operators
◦ Evaluation and use of expressions in statements
◦ Use of function calls in expressions (see Chapter 4)
• Control Structures – (Chapter 2-3)
◦ if
◦ else-if
▪ add else-if to select from multiple options
◦ switch
▪ alternative to if/else-if
▪ use of break and default keywords
◦ while vs. do-while
◦ for
▪ initialization of dedicated loop variable
▪ iterate an arbitrary number of times
▪ different ways to iterate through loop (i++, i--, i = i+2)
▪ nested for loops
◦ The break keyword in loops
◦ Know when you would use while loop vs. for loop
• Calling Functions Defined in Libraries – (Chapter 4)
◦ <cmath>
▪ pow()
▪ sqrt()
▪ ceil()
▪ floor()
◦ <cstdlib>
▪ srand()
▪ rand()
▪ understand the need for a unique seed per program execution
◦ <ctime>
▪ time()
• Scope – (Chapter 4)
◦ Block scope and locality
◦ Scope within functions
◦ Local variables
◦ Scope within nested blocks
Page 3 of 6
• Defining Functions – (Chapters 4-5)
◦ Function definition vs. function declaration vs. function call
◦ Flow of program control to function body
◦ Arguments vs. parameters
◦ Selecting a return type that aligns with a function's purpose
◦ Values that can be returned from a function:
▪ Literals
▪ Variables
▪ Expressions
▪ Values returned from other functions
◦ Call-by-value parameters
▪ A copy of an argument's value passed in during a function call
▪ Allows literals as arguments
◦ Call-by-reference parameters
▪ A reference to the memory address of an argument passed in during a function call
▪ In other words, a function will directly manipulate an argument's value
▪ Forbids literals as arguments
◦ Function overloading
▪ Know how to write an overloaded function
▪ Minimum requirements for overloading
• Input/Output via <fstream>/<iostream> libraries – (Chapter 6)
◦ Create <ifstream>/<ofstream> stream objects via constructor functions
• calling the default constructor function
• calling the one-argument constructor function – what does this argument initialize?
◦ Insertion operator (<<)
◦ Extraction operator (>>)
▪ how to continuously read until the end of the file
▪ potential issues related to input
◦ Stream object member functions
▪ .open()
▪ .close()
◦ .getline() - non-member function
◦ Stream objects as function parameters
▪ call-by-reference required
▪ ofstream/ifstream vs. ostream/istream
◦ Character functions – require <cctype> library
▪ toupper()
▪ tolower()
▪ isalpha()
▪ isdigit()
Page 4 of 6
• One-dimensional Arrays – (Chapter 7)
◦ Declaration
◦ Initialization
◦ Upper and lower bounds
◦ Access and modification of individual elements via indexing
◦ Arrays as function parameters – pass array and size
◦ Limitations of compile-time arrays
• Strings – (Chapter 8)
◦ requires <string> library
▪ .length()
▪ .find()
▪ .substr()
◦ String concatenation with addition operator (+)
◦ String variables as function parameters, how to return a string from a function
• Vectors – (Chapter 8)
◦ Advantages of vectors compared to arrays
◦ How to construct a vector object
▪ specifying the data type of vector
▪ difference between calling the default constructor vs. passing in an argument
◦ Vectors as function parameters
▪ when to use call-by-value vs. call-by-reference
◦ Member functions:
▪ .size()
▪ .at() - compare with traditional array indexing
▪ .push_back()
▪ .pop_back()
• Pointers – (Chapter 9)
◦ How to declare a pointer variable
▪ what type of value does a pointer store?
◦ How to assign addresses to pointers
▪ the values of other pointers
▪ references to stack-allocated variables
• the reference operator - (&)
▪ arrays
▪ accessing an array through a pointer
◦ How to dereference a pointer via * to access a pointed-to variable - *<pointer identifier>
◦ Use of new keyword to dynamically allocate variables and arrays (using [])
Page 5 of 6
• Pointers – (Chapter 9) – (continued)
◦ Deletion of dynamically-allocated variables and arrays
▪ delete keyword – no-[] vs. []
▪ dangling pointers
▪ memory leaks
◦ [TO BE DETERMINED]
▪ Pointers to class objects (i.e. object pointers)
• use of the arrow operator ( -> ) - see Chapter 13
• Structures – (Chapter 10)
◦ Adding member variables
◦ Creating a structure variable
◦ Accessing a structure’s members
◦ Modifying a structure’s members
• Classes – (Chapter 10)
◦ Defining member functions:
▪ inside of the class definition
▪ outside of the class definition
• use of the scope resolution operator (::)
• ability to use private members in definition
▪ calling member functions
▪ what does the term “calling object” mean with respect to a called member function?
◦ Constructor functions
▪ how to include a default constructor in your class definition
▪ initialization section syntax (p. 584) - <member data>(<constructor parameter>)
◦ Access modifiers
▪ public vs. private
▪ when you can and cannot use a private member
▪ encapsulation – Savitch 566
◦ Accessor/”getter” and mutator/”setter” member functions
▪ used to access or modify private member data
▪ by convention, use the words get or set in function names
▪ return types of getters: think about what type of value you’re trying to get
• Classes (advanced) – (Chapter 11)
◦ Dynamic arrays in classes
▪ initializing via a constructor function
◦ The copy constructor function – Savitch 678-679
▪ Know when it is used
▪ shallow copy vs. deep copy
Page 6 of 6
• Classes (advanced) – (Chapter 11) - (continued)
◦ Destructor function
◦ Friend functions
◦ Constant parameters within member functions
◦ Constant member functions
◦ Binary Operator Overloading (+, -, <<, >>)
• Inheritance – (Chapter 15)
◦ How to derive a class from a base class via public inheritance
▪ Inheriting member variables and functions
• As a derived class, do I have access to my base class’ private members?
▪ Adding member variables and functions
▪ Redefining member functions
▪ Calling a base version of a redefined function
▪ Calling a base constructor in a derived constructor’s definition
▪ The use of a base class’ destructor in a derived destructor’s definition