An Introduction to Programming with C++: Eighth Edition
Chapter 15 Answers
Review Questions
1. a class
2. d A class is considered an object.
3. c private
4. c public
5. b only through the public members of the class
Exercises Pencil and Paper
1. The answer to this TRY THIS Exercise is located at the end of Chapter 15 in the book.
2. The answer to this TRY THIS Exercise is located at the end of Chapter 15 in the book.
3.
//declaration section
class Employee
{
public:
Employee();
Employee(string, double);
void setEmployee(string, double);
double getSalary();
string getName();
void Employee::setEmployee(string n, double s)
{
name = n;
salary = s;
} //end of setEmployee method
double Employee::getSalary()
4.
//declaration section
class Employee
{
public:
Employee();
Employee(string, double);
{
name = “”;
salary = 0.0;
} //end of default constructor
Employee::Employee(string n, double s)
{
name = n;
salary = s;
} //end of constructor
string Employee::getName()
{
return name;
} //end of getName method
5.
Square::getArea(int l, int w)
{
return l * w;
} //end of getArea method
Square::getArea(double l, double w)
{
return l * w;
} //end of getArea method
//implementation section
Item::Item()
{
name = “”;
price = 0.0;
} //end of default constructor
Exercises Computer
7. The answer to this TRY THIS Exercise is located at the end of Chapter 15 in the book. The code is entered
in the TryThis7.cpp and TryThis7 Employee.h files, which are contained in either the
Cpp8\Chap15\TryThis7 Project-IM folder (Microsoft) or the Cpp8\Chap15 folder (non-Microsoft).
8. The answer to this TRY THIS Exercise is located at the end of Chapter 15 in the book. The code is entered
in the TryThis8.cpp file and TryThis8 FormattedDate.h files, which are contained in either the
Cpp8\Chap15\TryThis8 Project-IM folder (Microsoft) or the Cpp8\Chap15 folder (non-Microsoft).
9. See the ModifyThis9.cpp and ModifyThis9 FormattedDate.h files, which are contained in either the
13. See the Introductory13.cpp and Introductory13 Square.h files, which are contained in either the
Cpp8\Chap15\Introductory13 Project-IM folder (Microsoft) or the Cpp8\Chap15 folder (non-Microsoft).
14. See the Intermediate14.cpp and Intermediate14 Rectangle.h files, which are contained in either the
Cpp8\Chap15\Intermediate14 Project-IM folder (Microsoft) or the Cpp8\Chap15 folder (non-Microsoft).
15. See the Intermediate15.cpp and Intermediate15 Rectangle.h files, which are contained in either the
Cpp8\Chap15\Intermediate15 Project-IM folder (Microsoft) or the Cpp8\Chap15 folder (non-Microsoft).
16. See the Intermediate16.cpp and Intermediate16 Rectangle.h files, which are contained in either the
Cpp8\Chap15\Intermediate16 Project-IM folder (Microsoft) or the Cpp8\Chap15 folder (non-Microsoft).