Solutions Manual Data Structures With C++ Using STL 2nd Edition Ford PDF
Solutions Manual Data Structures With C++ Using STL 2nd Edition Ford PDF
2. A _____________ is a computer professional who serves as an intermediary between the client and the software
engineer
(a) Design analyst (b) Systems analyst (c) Client consultant (d) Software engineering designer
4. Suppose that we know that the day corresponding to January 1 of the current year is 3 (Wednesday). Describe
the algorithm that determines the day corresponding to August 1 of the current year.
5. Verifying that we are solving the correct problem is called _______________; testing that we are solving the
problem correctly is called _________________
6. __________ testing focuses on the input and output behavior of a program without concern for the internal
structure of its classes and functions
8. The function slideBack () scans elements in an array starting at the first element. The function looks at
successive pairs of elements and exchanges their values if the first element is greater than the second element.
At the end of the scan, the largest element should appear at the back (end) of the array. We provide the
following incorrect implementation for slideBack().
9. The function contains() scans an array to determine if an item is in the list. The function returns true if the item
is found and false otherwise. The following implementation works but is not a good solution.
return itemFound;
}
10. The object-oriented programming design model views a software system as a set of objects that interact to carry
out a task. The top-down design model views the system as a hierarchical set of subprograms that decomposes
the problem into separate components. Discuss how these two models might be used in a program design .
11. Good and bad input for a program often fall within ranges. Data that lie between these ranges are called
______________ values and represent values that are one step away from changing program behavior.
12. When a program identifies an input error, good design dictates that the programmer should immediately
terminate execution with an "exit()" statement so that the user does not obtain erroneous output.
(a) True (b) False
14. Assume function f() might throw an exception. In order to handle the exception, a programmer must include
the call to f() in a _________________; the program handles the exception in a code segment called a
__________________________.
15. (a) The statements in a try block may generate only one exception.
(i) True (ii) False
(b) There must be a one to one correspondence between a try block and a catch block in the sense that each try
block may include only one catch block to handle an exception.
(i) True (ii) False
16. In the employee class, the member function setPayRate() throws an employeeError exception with the message
"Below minimum wage". Assume the constant real number MINPAYRATE defines the current minimum
wage.
CHAPTER 2 SAMPLE TEST OBJECT DESIGN TECHNIQUES 3
class employee
{
public:
. . .
void setPayRate(double pay);
private:
. . .
double payRate;
};
(b) Assume empObj is an object of type employee. Fill in the missing statements in a code sequence that calls
the member function and outputs the error message if an exception occurs.
__________________
{
empObj.setPayRate(6.50);
}
______________________________________
{
// Output the message
_______________________________________
}
17. What C++ object technology concept is involved when a class has a data member which is itself an object of
class type. ________________________________________________________
18. With object composition, a class that is included by composition is called the ________________ class and the
class that includes an object by composition is called the ____________ class.
19. The cylinder class provides measurement of a cylinder object, which we can view as a 3-dimensional figure
created by a circle sliding vertical upward along a line denoting the height. A cylinder is defined by the radius
of the circular base and the height. Using object composition, we represent the base using a circle object.
class cylinder
{
public:
height
cylinder(double r, double h): _______, height(h)
{} radius
private:
circle base;
double height;
};
class circle
{
public:
circle(double r = 0.0): radius(r)
{}
void setRadius(double r)
{ radius = r; }
private:
double radius;
};
(a) In the implementation of the cylinder constructor, complete the initialization list.
(b) Give the return value for getRadius().
(c) Implement the member function volume().
20. Companies hire "temp" workers at an hourly rate and pay them at the end of the day. The tempWorker class
uses the composition of two time24 objects to indicate when the worker begins work and ends work. The third
data member is the hourly pay rate.
class tempWorker
{
public:
// constructor has arguments to initialize both time24 data
// values and the rate per hour
tempWorker(double rate, int sthour, int stminute,
int endhour, int endminute);
// return pay for the day using time24 data and rate per hour
double pay() const;
private:
double ratePerHour;
time24 startwork, endwork;
};
class testCL
{
public:
. . .
// overloaded compound addition operator
testCL& operator+= (const testCL& obj);
private:
. . .
};
Assume that a and b are objects of type testCL. The operation b += a is implemented as
(a) b = a.operator+=(b) (b) b.a.operator+=()
(c) b.operator+=(a) (d) b = b.operator+=(a)
23. The following is the declaration of the operator +, which is overloaded as a friend function in the time24 class.
(a) Modify the declaration so that the operator becomes a member function of the class.
(b) Implement the member function using inline code.
24. The class length stores the linear measure of an object with integer data members feet and inch.
class length;
{
public:
// constructor initializes feet and inches
length(int ft = 0, int in = 0);
(b) In the implementation of operator-, which of the following statements throws a rangeError exception.
(c) In the declaration of the stream output operator, why is the ostream argument ostr not declared using
constant reference?
(f) Give the output that results from the (cout) statements in the following code.
Test Solutions
1. (a) OOD (b) OOA (c) OOP (d) OOA (e) OOP (f) OOD (g) OOD
2. (b)
3. (c)
4. January 1 of 2003 is a Wednesday. Using this year as an example, the following code determines the integer
value of the first day of August.
Date d(8,1,2003);
int n = d.numberOfDays();
int firstDay = 3;
int firstAugust = (firstDay + n)%7;
6. Blackbox testing
7. Whitebox testing
9. (a) Use a profiler or a debugger to count the number of iterations. Note all calls to the function require n
iterations independent of item.
if (arr[i] == item)
return true;
10. Often the design of a public member function partitions the operation into a series of tasks that are performed
by private member functions. This partitioning process employs a top-down model.
12. (b)
13. (b)
payRate = pay;
}
CHAPTER 2 SAMPLE TEST OBJECT DESIGN TECHNIQUES 8
(b) try
{
empObj.setPayRate(6.50);
}
(b) base.getRadius()
20. Companies hire "temp" workers at an hourly rate and pay them at the end of the day. The tempWorker class
uses the composition of two time24 objects to indicate when the worker begins work and ends work. The third
data member is the hourly pay rate.
class tempWorker
{
public:
// constructor has arguments to initialize both time24 data
// values and the rate per hour
tempWorker(double rate, int sthour, int stminute,
int endhour, int endminute);
// return pay for the day using time24 data and rate per hour
double pay() const;
private:
double ratePerHour;
time24 startwork, endwork;
};
21. Functions can be overloaded provided they have distinct argument lists.
22. (c)
23. The following is the declaration of the operator +, which is overloaded as a friend function in the time24 class.
24. (a) bool operator< (const length& lhs, const length& rhs)
{
return (lhs.feet*12 + lhs.inch) < (rhs.feet*12 + rhs.inch);
}
(b) (iv)
(c) All streams have state changes during an operation and can never be const.
return *this;
}