The material presented in this guide covers the concepts emphasized on the final examination. It is meant to guide students studying and reviewing for the final examination; it is not guaranteed to be comprehensive. Actual test questions will differ from any examples given here. Students should use this guide in addition to other study activities (like reading Chapters 8-17, reviewing completed lab assignments, old quizzes, etc.) Knowledge of Chapters 1-7 is assumed, but the emphasis is on material in Chapters 8-17.
For example, given the function
int func(int a, int b) { int s = 0; while (a < b) { s++; a++; b--; } return s; }what is the value of the expression func(3, 12)?
Be able to write a C++ function given its specification. The code may involve any of the concepts in Chapters 2-16. Thus, in order to write the code you may need to:
For example, complete the following function named is_reduced that accepts two integer parameters, numerator and denominator. The function returns true if numerator/denominator represents a fraction reduced to lowest terms; otherwise, the function returns false if the fraction numerator/denominator can be reduced. For example, the expression is_reduced(1, 2) would evaluate to true, but is_reduced(2, 4) would evaluate to false. Improper fractions are acceptable (7/3 is reduced, but 9/3 is not). The function should return false when denominator is zero.
bool is_reduced(int numerator, int denominator) { }
As another example, complete the following function named sum used to compute the sum of all the values in a vector of integers.
int sum(const vector<int>& v) { }
For example, the following code fragment
cout << sum({3, 1, 5}) << endl;
should display 9, since 3 + 1 + 5 = 9.
Beware! Any problems that states that "the function should do no I/O" means you should not get input from the user nor should you print anything on the screen. This means you must use neither the cout nor cin objects within the function.
Given a specification for a simple C++ object, provide the class definition that implements the object specification.
For example, complete the following class definition for simple counter objects.
class Counter { };
Each counter object keeps track of a count (0 or higher). The class constructor requires clients to specify the highest value that the counter object can attain. All counter objects begin with a count of zero. Clients can increment a counter object only via an increment method. The increment method enforces the limit the client specifies in the constructor. Clients can see a counter's value only though its get method. Clients may reset the counter to zero at any time via the reset method. Clients may not influence a counter object's value is any other way.
The following client code fragment
Counter my_counter(3); cout << my_counter.get() << " "; my_counter.increment(); cout << my_counter.get() << " "; my_counter.increment(); cout << my_counter.get() << " "; my_counter.increment(); cout << my_counter.get() << " "; my_counter.increment(); cout << my_counter.get() << " "; my_counter.increment(); cout << my_counter.get() << " "; my_counter.reset(); cout << my_counter.get() << " "; my_counter.increment(); cout << my_counter.get() << " ";
would print 0 1 2 3 3 3 0 1. Observe that due to the limit specified to the constructor (3) this my_counter counter object cannot count above 3.
There may be a few general questions about programming or C++ that do not involve reading or writing code.
Also, take time to review all the code we have developed in class.
It has all been uploaded to the standard repository
(
http://www.cs.southern.edu/halterman/repository/ClassCode/124/).