1. Assuming a variable areaCode is of type int, one solution is to print a leading zero if the area code is less than 100:
if (areaCode << 100)
cout << 0;
cout << areaCode;
Another solution is to declare an area code to be a string rather than an int, thereby reading or printing exactly three characters each time I/O takes place.
Chapter 15
Exam Preparation Exercises
3. a. SomeClass and int b. Func1, Func2, Func3, and someIntc. objecti and object2 d. Func1, Func2, and Func3 e. Funcl and Func3 f. part (ii)
4. True
8. a. Only myprog.cpp must be recompiled. b. All of the object (.obj) files must be relinked. c. Only file2.cpp and file3.cpp must be recompiled. d. All of the object (. obj) files must be relinked.
Chapter 15
Programming Warm-Up Exercises
1. a. if ( !time1.Equal(time2) )
n = 1;
b.if (timel.LessThan(time2) || timel.Equal(time2))
n = 5;
c. if (time2.LessThan(timel))
n = 8;
d. if ( !timel.LessThan(time2) )
n = 5;
or
if (time2.LessThan(timel) || time2.Equal(time1))
n = 5;
3. Function specification (within the TimeType class declaration):
void WriteAmPm() const;
// Postcondition:
// Time has been output in 12-hour form
// HH:MM:SS AM or HH:MM:SS PM
Function definition (omitting the postcondition to save space):