|
|
|
Question 1. |
|
|
|
class AccountClass |
{ |
|
|
|
public: |
|
|
AccountClass(); |
|
|
void redirect(); |
|
private: |
|
|
short status; |
}; |
|
|
|
|
|
AccountClass::AccountClass() |
{ |
|
|
|
status = -75; |
} |
|
|
|
|
|
void AccountClass::redirect() |
{ |
|
|
|
cout << status; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
AccountClass extraObject; |
|
extraObject.redirect(); |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 2. |
|
|
|
class ServiceClass |
{ |
|
|
|
public: |
|
|
void visualize(); |
|
|
~ ServiceClass(); |
|
protected: |
|
|
long double size; |
}; |
|
|
|
|
|
void ServiceClass::visualize() |
{ |
|
|
|
size = -18.584; |
} |
|
|
|
|
|
ServiceClass::~ServiceClass() |
{ |
|
|
|
cout << size; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
ServiceClass cloneObject; |
|
cloneObject.visualize(); |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 3. |
|
|
|
class ProductClass |
{ |
|
|
|
public: |
|
|
ProductClass(); |
|
|
~ProductClass(); |
|
private: |
|
|
int rating; |
}; |
|
|
|
|
|
ProductClass::ProductClass() |
{ |
|
|
|
rating = 689; |
} |
|
|
|
|
|
ProductClass::~ProductClass() |
{ |
|
|
|
cout << rating; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
ProductClass specialObject; |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 4. |
|
|
|
class EmployeeClass |
{ |
|
|
|
public: |
|
|
EmployeeClass(); |
|
|
void process(); |
|
|
~ EmployeeClass(); |
|
|
char units; |
}; |
|
|
|
|
|
EmployeeClass::EmployeeClass() |
{ |
|
|
|
units = 'O'; |
} |
|
|
|
|
|
void EmployeeClass::process() |
{ |
|
|
|
cout << units; |
} |
|
|
|
|
|
EmployeeClass::~EmployeeClass() |
{ |
|
|
|
cout << units; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
EmployeeClass supplementalObject; |
|
supplementalObject.process(); |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 5. |
|
|
|
class StudentClass |
{ |
|
|
|
public: |
|
|
StudentClass(); |
|
|
~StudentClass(); |
|
private: |
|
|
float limit; |
}; |
|
|
|
|
|
StudentClass::StudentClass() |
{ |
|
|
|
limit = 3.1; |
} |
|
|
|
|
|
StudentClass::~StudentClass() |
{ |
|
|
cout << limit; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
StudentClass copyObject; |
|
StudentClass specialObject; |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 6. |
|
|
|
class ProductClass |
{ |
|
|
|
public: |
|
|
ProductClass(); |
|
|
void process(); |
|
|
~ProductClass(); |
|
protected: |
|
|
short increment; |
}; |
|
|
|
|
|
ProductClass::ProductClass() |
{ |
|
|
|
increment = -7; |
} |
|
|
|
|
|
void ProductClass::process() |
{ |
|
|
|
increment = 7; |
} |
|
|
|
|
|
ProductClass::~ProductClass() |
{ |
|
|
|
cout << increment; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
ProductClass firstObject; |
|
firstObject.process(); |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 7. |
|
|
|
class StudentClass |
{ |
|
|
|
public: |
|
|
StudentClass(); |
|
|
~StudentClass(); |
|
protected: |
|
|
char status; |
}; |
|
|
|
|
|
StudentClass::StudentClass() |
{ |
|
|
|
status = '/'; |
|
cout << status; |
} |
|
|
|
|
|
StudentClass::~StudentClass() |
{ |
|
|
|
status = 'c'; |
|
cout << status; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
StudentClass lastObject; |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 8. |
|
|
|
class BrandClass |
{ |
|
|
|
public: |
|
|
BrandClass(); |
|
|
void select(); |
|
private: |
|
|
float length; |
}; |
|
|
|
|
|
BrandClass::BrandClass() |
{ |
|
|
|
Length = 8.2; |
} |
|
|
|
|
|
void BrandClass::select() |
{ |
|
|
|
cout << length; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
BrandClass cloneObject; |
|
cloneObject.select(); |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 9. |
|
|
|
class EmployeeClass |
{ |
|
|
|
public: |
|
|
EmployeeClass(); |
|
|
void read(); |
|
|
void print(); |
|
|
long double step; |
}; |
|
|
|
|
|
EmployeeClass::EmployeeClass() |
{ |
|
|
|
step = 68.123; |
|
cout << step; |
} |
|
|
|
|
|
void EmployeeClass::read() |
{ |
|
|
|
step = 98.02; |
} |
|
|
|
|
|
void EmployeeClass::print() |
{ |
|
|
|
cout << step; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
EmployeeClass newObject; |
|
newObject.read(); |
|
newObject.print(); |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 10. |
|
|
|
class
OrganizationClass |
{ |
|
|
|
public: |
|
|
OrganizationClass(); |
|
|
void read(); |
|
|
~OrganizationClass(); |
|
|
int depth; |
}; |
|
|
|
|
|
OrganizationClass::OrganizationClass() |
{ |
|
|
|
depth = 590; |
} |
|
|
|
|
|
void
OrganizationClass::read() |
{ |
|
|
|
depth = 596; |
} |
|
|
|
|
|
OrganizationClass::~OrganizationClass() |
{ |
|
|
|
cout << depth; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
OrganizationClass supplementalObject; |
|
OrganizationClass copyObject; |
|
supplementalObject.read(); |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 11. |
|
|
|
class CompanyClass |
{ |
|
|
|
public: |
|
|
CompanyClass(); |
|
|
void select(); |
|
|
~CompanyClass(); |
|
protected: |
|
|
char number; |
}; |
|
|
|
|
|
CompanyClass::CompanyClass() |
{ |
|
|
|
number = ')'; |
} |
|
|
|
|
|
void CompanyClass::select() |
{ |
|
|
|
number = '@'; |
} |
|
|
|
|
|
CompanyClass::~CompanyClass() |
{ |
|
|
|
cout << number; |
|
number = '3'; |
|
cout << number; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
CompanyClass newObject; |
|
newObject.select(); |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 12. |
|
|
|
class AccountClass |
{ |
|
|
|
public: |
|
|
void process(); |
|
|
~AccountClass(); |
|
protected: |
|
|
bool principal; |
}; |
|
|
|
|
|
void AccountClass::process() |
{ |
|
|
|
prinicipal = false; |
|
cout << principal; |
} |
|
|
|
|
|
AccountClass::~AccountClass() |
{ |
|
|
|
cout << principal; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
AccountClass cloneObject; |
|
cloneObject.process(); |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 13. |
|
|
|
class OrganizationClass |
{ |
|
|
|
public: |
|
|
void process(); |
|
|
~OrganizationClass(); |
|
protected: |
|
|
char rating; |
}; |
|
|
|
|
|
void OrganizationClass::process() |
{ |
|
|
|
rating = 'I'; |
} |
|
|
|
|
|
OrganizationClass::~OrganizationClass() |
{ |
|
|
|
cout << rating; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
OrganizationClass specialObject; |
|
specialObject.process(); |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 15. |
|
|
|
|
|
|
class StudentClass |
{ |
|
|
|
public: |
|
|
StudentClass(); |
|
|
void join(); |
|
|
~StudentClass(); |
|
|
long size; |
}; |
|
|
|
|
|
StudentClass::StudentClass() |
{ |
|
|
|
size = 8181; |
|
cout << size; |
} |
|
|
|
|
|
void StudentClass::join() |
{ |
|
|
|
size = -7137; |
|
cout << size; |
} |
|
|
|
|
|
StudentClass::~StudentClass() |
{ |
|
|
|
cout << size; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
StudentClass newObject; |
|
newObject.join(); |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 16. |
|
|
|
class ProductClass |
{ |
|
|
|
public: |
|
|
ProductClass(); |
|
|
void read(); |
|
|
~ProductClass(); |
|
|
double duration; |
}; |
|
|
|
|
|
ProductClass::ProductClass() |
{ |
|
|
|
duration = -15.97; |
|
cout << duration; |
} |
|
|
|
|
|
void ProductClass::read() |
{ |
|
|
|
duration = -38.97; |
} |
|
|
|
|
|
ProductClass::~ProductClass() |
{ |
|
|
|
cout << duration; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
ProductClass firstObject; |
|
ProductClass copyObject; |
|
copyObject.read(); |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 17. |
|
|
|
class OrganizationClass |
{ |
|
|
|
public: |
|
|
OrganizationClass(); |
|
|
void join(); |
|
|
~OrganizationClass(); |
|
private: |
|
|
bool number; |
}; |
|
|
|
|
|
OrganizationClass::OrganizationClass() |
{ |
|
|
|
number = true; |
} |
|
|
|
|
|
void OrganizationClass::join() |
{ |
|
|
|
number = false; |
} |
|
|
|
|
|
OrganizationClass::~OrganizationClass() |
{ |
|
|
|
cout << number; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
OrganizationClass specialObject; |
|
specialObject.join(); |
|
{ |
|
|
OrganizationClass copyObject; |
|
} |
|
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 18. |
|
|
|
class EmployeeClass |
{ |
|
|
|
public: |
|
|
EmployeeClass(); |
|
|
~EmployeeClass(); |
|
private: |
|
|
bool step; |
}; |
|
|
|
|
|
EmployeeClass::EmployeeClass() |
{ |
|
|
|
step = false; |
} |
|
|
|
|
|
EmployeeClass::~EmployeeClass() |
{ |
|
|
|
cout << step; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
EmployeeClass supplementalObject; |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Question 20. |
|
|
|
class AccountClass |
{ |
|
|
|
public: |
|
|
AccountClass(); |
|
|
void reorder(); |
|
|
~AccountClass(); |
|
|
short rating; |
}; |
|
|
|
|
|
AccountClass::AccountClass() |
{ |
|
|
|
rating = -68; |
|
cout << rating; |
} |
|
|
|
|
|
void AccountClass::reorder() |
{ |
|
|
|
cout << rating; |
} |
|
|
|
|
|
AccountClass::~AccountClass() |
{ |
|
|
|
cout << rating; |
} |
|
|
|
|
|
void main() |
{ |
|
|
|
AccountClass lastObject; |
|
lastObject.reorder(); |
} |
|
|
|
|
|
|
|
|
Output of the program: |
|
|
|
|
|
|
|
|
|
|
|
|
|
Problem Set 2: Answers to Odd-Numbered Questions |
|
|
|
Question 1. |
Output of the Program: |
-75 |
|
|
|
Question 3. |
Output of the Program: |
689 |
|
|
|
Question 5. |
Output of the Program: |
3.13.1 |
|
|
|
Question 7. |
Output of the Program: |
/c |
|
|
|
Question 9. |
Output of the Program: |
68.12398.02 |
|
|
|
Question 11. |
Output of the Program: |
@3 |
|
|
|
Question 13. |
Output of the Program: |
1 |
|
|
|
Question 15. |
Output of the Program: |
8181-7137-7137 |
|
|
|
Question 17. |
Output of the Program: |
10 |
|
|
|
Question 19. |
Output of the Program: |
M |
|
|
|
Problem Set 2: Answers to Even-Numbered Questions |
|
|
|
Question 2. |
Output of the Program: |
-18.584 |
|
|
|
Question 4. |
Output of the Program: |
00 |
|
|
|
Question 6. |
Output of the Program: |
7 |
|
|
|
Question 8. |
Output of the Program: |
8.2 |
|
|
|
Question 10. |
Output of the Program: |
590596 |
|
|
|
Question 12. |
Output of the Program: |
00 |
|
|
|
Question 14. |
Output of the Program: |
-253 |
|
|
|
Question 16. |
Output of the Program: |
-15.97-15.97-38.97-15.97 |
|
|
|
Question 18. |
Output of the Program: |
0 |
|
|
|
Question 20. |
Output of the Program: |
-68-68-68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|