SlideShare a Scribd company logo
1 of 3
Download to read offline
Final Exam -- Object-Oriented Programming (FIT-II), Spring 2008 
Software Engineering Track, NTUT, Jun. 20, 2008 
Note: There are 7 questions worth a total of 100 points. You have 150 minutes. The 
exam is *open* book, but you have to do it on your own. Do NOT talk or discuss with 
anyone else. 
1 
Part I: Hand-written Questions (45%) 
(15 pt) 1. Given the definitions 
const int x = 17; 
class A 
{ 
public: 
A(); 
A(int n); 
int f() const; 
int g(const A& x); 
private: 
int i; 
}; 
Each of the three const keywords is a promise to the compiler that the compiler will 
enforce. What is the promise in each case? 
(10 pt) 2. What are the meanings of overloaded functions (as in operator overloading) 
and virtual functions? Explain their differences. 
(10 pt) 3. What are the purposes of public:, private: and protected: 
sections in a class definition? Explain their differences. 
(10 pt) 4. Suppose Child is a class derived from the class Parent and that the class 
Grandchild is a class derived from the class Child. This question is concerned with 
the constructors and destructors for the three classes Parent, Child, and Grandchild. 
When a constructor for the class Grandchild is invoked, what constructors are 
invoked and in what order? When the destructor for the class Grandchild is invoked, 
what destructors are invoked and in what order?
2 
Part II: Programming Questions (55%) 
(15 pt) 5. Define a class called Time. The time can be represented as two integers in 
24-hour notation. Include the following functions in your class: 
(1) two overloaded functions to set the time, in 12-hour and 24-hour notations. 
For example, calling set(20, 30) will store the corresponding time 20:30; while calling 
set(8, 30, ‘P’) will convert from 12-hour to 24-hour notation and store the same time 
20:30. 
(2) two overloaded functions to get the current time, in 12-hour and 24-hour 
notations. 
For example, if the current time is 14:25, then calling get(hr, min) will return two 
integers:14 and 25; while calling get(hr, min, ampm) will convert from 24-hour to 
12-hour notation and return two integers: 2, 25, and the A.M./P.M. information as a value 
of type char (‘A’ for A.M. and ‘P’ for P.M). Thus, this function will have a 
call-by-reference formal parameter of type char to record whether it is A.M. or P.M. 
(3) two overloaded functions to output the current time, in 12-hour and 24-hour 
notations. 
For example, if the current time is 23:15, then output() will show “23:15”; while 
output(HR12) will show “11:15PM”. (HR12 is defined as a boolean constant with 
value of true.) 
Finally, include the class in a test program. 
(20 pt) 6. Define a class for a type called Fraction. This class is used to represent a 
ratio of two integers. Include the following functions in your code: 
(1) a member function that allows the user to set the numerator and the denominator. 
(2) a member function that returns the value of the numerator divided by the 
denominator as a double. 
(3) a member function that outputs the value of the fraction reduced to lowest terms. 
For example, instead of outputting 20/60 the function should output 1/3. This will 
require finding the greatest common divisor (gcd) for the numerator and denominator, 
and then dividing both by the number. 
(3.1) the function for finding the gcd of two numbers can be implemented as 
follows. Working with the two numbers’ absolute values, we find the remainder of 
one divided by the other. Then, we calculate the remainder of the old divisor 
divided by the remainder found. We repeat this process until the remainder is zero. 
The last divisor is the gcd. 
Finally, embed your class in a test program.
(20 pt) 7. Define a base class called Worker that has two derived classes: Employee 
and Manager. For workers, we only have simple attributes such as their names and 
working hours. For employees and managers, each has specific attributes unique to 
the class. Employees have attributes such as the name of the department that they are 
working with, and their salaries. Managers have attributes such as the number of 
managed employees and the list of projects that they’re in charge. Also, define 
another class called Project that has attributes such as the name and the current 
progress (in %) of the project. 
(1) Write the corresponding constructors that initialize the attributes for classes. 
(2) Write the corresponding destructors that clean up the attributes for classes. 
(3) Write the corresponding member functions to set and get the attributes for classes. 
(4) Write a virtual function print_record() that will print all attributes related to 
the object. 
Finally, test the classes in a main program. In the test program, you should 
dynamically allocate some employees and managers, print their corresponding records 
using the virtual function print_record(), and then release the dynamically 
allocated objects in the end. 
3

More Related Content

What's hot

Sp 1418794917
Sp 1418794917Sp 1418794917
Sp 1418794917lakshmi r
 
Char word counter in Python with simple gui - PROJECT
Char word counter in Python with simple gui - PROJECTChar word counter in Python with simple gui - PROJECT
Char word counter in Python with simple gui - PROJECTMahmutKAMALAK
 
17432 object oriented programming
17432   object oriented programming17432   object oriented programming
17432 object oriented programmingsoni_nits
 
Sample Paper 2 Class XI (Computer Science)
Sample Paper 2 Class XI (Computer Science)Sample Paper 2 Class XI (Computer Science)
Sample Paper 2 Class XI (Computer Science)Poonam Chopra
 
Assignment Examples Final 07 Oct
Assignment Examples Final 07 OctAssignment Examples Final 07 Oct
Assignment Examples Final 07 OctSriram Raj
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna universitysangeethajames07
 
04. constructor & destructor
04. constructor & destructor04. constructor & destructor
04. constructor & destructorHaresh Jaiswal
 
CS106 Lab 9 - 1D array
CS106 Lab 9 - 1D arrayCS106 Lab 9 - 1D array
CS106 Lab 9 - 1D arrayNada Kamel
 
Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++Danial Mirza
 
pointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpppointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cppgourav kottawar
 

What's hot (20)

Ocs752 unit 4
Ocs752   unit 4Ocs752   unit 4
Ocs752 unit 4
 
Sp 1418794917
Sp 1418794917Sp 1418794917
Sp 1418794917
 
Ocs752 unit 5
Ocs752   unit 5Ocs752   unit 5
Ocs752 unit 5
 
Char word counter in Python with simple gui - PROJECT
Char word counter in Python with simple gui - PROJECTChar word counter in Python with simple gui - PROJECT
Char word counter in Python with simple gui - PROJECT
 
17432 object oriented programming
17432   object oriented programming17432   object oriented programming
17432 object oriented programming
 
Sample Paper 2 Class XI (Computer Science)
Sample Paper 2 Class XI (Computer Science)Sample Paper 2 Class XI (Computer Science)
Sample Paper 2 Class XI (Computer Science)
 
Assignment Examples Final 07 Oct
Assignment Examples Final 07 OctAssignment Examples Final 07 Oct
Assignment Examples Final 07 Oct
 
Ocs752 unit 2
Ocs752   unit 2Ocs752   unit 2
Ocs752 unit 2
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna university
 
04. constructor & destructor
04. constructor & destructor04. constructor & destructor
04. constructor & destructor
 
C# p8
C# p8C# p8
C# p8
 
Ocs752 unit 3
Ocs752   unit 3Ocs752   unit 3
Ocs752 unit 3
 
CS106 Lab 9 - 1D array
CS106 Lab 9 - 1D arrayCS106 Lab 9 - 1D array
CS106 Lab 9 - 1D array
 
I PUC CS Lab_programs
I PUC CS Lab_programsI PUC CS Lab_programs
I PUC CS Lab_programs
 
Java final lab
Java final labJava final lab
Java final lab
 
C language function
C language functionC language function
C language function
 
Data Type Conversion in C++
Data Type Conversion in C++Data Type Conversion in C++
Data Type Conversion in C++
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
pointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpppointers, virtual functions and polymorphisms in c++ || in cpp
pointers, virtual functions and polymorphisms in c++ || in cpp
 
Oops Quiz
Oops QuizOops Quiz
Oops Quiz
 

Viewers also liked

Viewers also liked (16)

P5
P5P5
P5
 
T4
T4T4
T4
 
Lo48
Lo48Lo48
Lo48
 
Lo17
Lo17Lo17
Lo17
 
E8
E8E8
E8
 
T3
T3T3
T3
 
E10
E10E10
E10
 
E9
E9E9
E9
 
P1
P1P1
P1
 
T1
T1T1
T1
 
P2
P2P2
P2
 
Lo39
Lo39Lo39
Lo39
 
P4
P4P4
P4
 
Lo27
Lo27Lo27
Lo27
 
T2
T2T2
T2
 
Lo37
Lo37Lo37
Lo37
 

Similar to E7

Assignment Java Programming 2
Assignment Java Programming 2Assignment Java Programming 2
Assignment Java Programming 2Kaela Johnson
 
Bis 311 final examination answers
Bis 311 final examination answersBis 311 final examination answers
Bis 311 final examination answersRandalHoffman
 
SE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUSSE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUSnikshaikh786
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning materialArthyR3
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docxrosemarybdodson23141
 
Book management system
Book management systemBook management system
Book management systemSHARDA SHARAN
 
friends functionToshu
friends functionToshufriends functionToshu
friends functionToshuSidd Singh
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxvrickens
 
Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make YASHU40
 
Getting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingGetting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingHock Leng PUAH
 
SPF Getting Started - Console Program
SPF Getting Started - Console ProgramSPF Getting Started - Console Program
SPF Getting Started - Console ProgramHock Leng PUAH
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answersQuratulain Naqvi
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directivesVikash Dhal
 

Similar to E7 (20)

Assignment Java Programming 2
Assignment Java Programming 2Assignment Java Programming 2
Assignment Java Programming 2
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Bis 311 final examination answers
Bis 311 final examination answersBis 311 final examination answers
Bis 311 final examination answers
 
C++ Lab Maual.pdf
C++ Lab Maual.pdfC++ Lab Maual.pdf
C++ Lab Maual.pdf
 
C++ Lab Maual.pdf
C++ Lab Maual.pdfC++ Lab Maual.pdf
C++ Lab Maual.pdf
 
SE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUSSE-IT JAVA LAB SYLLABUS
SE-IT JAVA LAB SYLLABUS
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning material
 
Unit-III.pptx
Unit-III.pptxUnit-III.pptx
Unit-III.pptx
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docx
 
Book management system
Book management systemBook management system
Book management system
 
friends functionToshu
friends functionToshufriends functionToshu
friends functionToshu
 
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docxJLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
JLK Chapter 5 – Methods and ModularityDRAFT January 2015 Edition.docx
 
Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make
 
Getting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingGetting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem Solving
 
SPF Getting Started - Console Program
SPF Getting Started - Console ProgramSPF Getting Started - Console Program
SPF Getting Started - Console Program
 
OOP program questions with answers
OOP program questions with answersOOP program questions with answers
OOP program questions with answers
 
Preprocessor directives
Preprocessor directivesPreprocessor directives
Preprocessor directives
 
Mmc manual
Mmc manualMmc manual
Mmc manual
 
Oop rosenschein
Oop rosenscheinOop rosenschein
Oop rosenschein
 
Object-Oriented Programming Using C++
Object-Oriented Programming Using C++Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
 

More from lksoo

More from lksoo (13)

Lo43
Lo43Lo43
Lo43
 
Lo12
Lo12Lo12
Lo12
 
L10
L10L10
L10
 
L9
L9L9
L9
 
L8
L8L8
L8
 
L7
L7L7
L7
 
L6
L6L6
L6
 
L5
L5L5
L5
 
L4
L4L4
L4
 
L3
L3L3
L3
 
L2
L2L2
L2
 
L1
L1L1
L1
 
E6
E6E6
E6
 

Recently uploaded

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 

Recently uploaded (20)

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 

E7

  • 1. Final Exam -- Object-Oriented Programming (FIT-II), Spring 2008 Software Engineering Track, NTUT, Jun. 20, 2008 Note: There are 7 questions worth a total of 100 points. You have 150 minutes. The exam is *open* book, but you have to do it on your own. Do NOT talk or discuss with anyone else. 1 Part I: Hand-written Questions (45%) (15 pt) 1. Given the definitions const int x = 17; class A { public: A(); A(int n); int f() const; int g(const A& x); private: int i; }; Each of the three const keywords is a promise to the compiler that the compiler will enforce. What is the promise in each case? (10 pt) 2. What are the meanings of overloaded functions (as in operator overloading) and virtual functions? Explain their differences. (10 pt) 3. What are the purposes of public:, private: and protected: sections in a class definition? Explain their differences. (10 pt) 4. Suppose Child is a class derived from the class Parent and that the class Grandchild is a class derived from the class Child. This question is concerned with the constructors and destructors for the three classes Parent, Child, and Grandchild. When a constructor for the class Grandchild is invoked, what constructors are invoked and in what order? When the destructor for the class Grandchild is invoked, what destructors are invoked and in what order?
  • 2. 2 Part II: Programming Questions (55%) (15 pt) 5. Define a class called Time. The time can be represented as two integers in 24-hour notation. Include the following functions in your class: (1) two overloaded functions to set the time, in 12-hour and 24-hour notations. For example, calling set(20, 30) will store the corresponding time 20:30; while calling set(8, 30, ‘P’) will convert from 12-hour to 24-hour notation and store the same time 20:30. (2) two overloaded functions to get the current time, in 12-hour and 24-hour notations. For example, if the current time is 14:25, then calling get(hr, min) will return two integers:14 and 25; while calling get(hr, min, ampm) will convert from 24-hour to 12-hour notation and return two integers: 2, 25, and the A.M./P.M. information as a value of type char (‘A’ for A.M. and ‘P’ for P.M). Thus, this function will have a call-by-reference formal parameter of type char to record whether it is A.M. or P.M. (3) two overloaded functions to output the current time, in 12-hour and 24-hour notations. For example, if the current time is 23:15, then output() will show “23:15”; while output(HR12) will show “11:15PM”. (HR12 is defined as a boolean constant with value of true.) Finally, include the class in a test program. (20 pt) 6. Define a class for a type called Fraction. This class is used to represent a ratio of two integers. Include the following functions in your code: (1) a member function that allows the user to set the numerator and the denominator. (2) a member function that returns the value of the numerator divided by the denominator as a double. (3) a member function that outputs the value of the fraction reduced to lowest terms. For example, instead of outputting 20/60 the function should output 1/3. This will require finding the greatest common divisor (gcd) for the numerator and denominator, and then dividing both by the number. (3.1) the function for finding the gcd of two numbers can be implemented as follows. Working with the two numbers’ absolute values, we find the remainder of one divided by the other. Then, we calculate the remainder of the old divisor divided by the remainder found. We repeat this process until the remainder is zero. The last divisor is the gcd. Finally, embed your class in a test program.
  • 3. (20 pt) 7. Define a base class called Worker that has two derived classes: Employee and Manager. For workers, we only have simple attributes such as their names and working hours. For employees and managers, each has specific attributes unique to the class. Employees have attributes such as the name of the department that they are working with, and their salaries. Managers have attributes such as the number of managed employees and the list of projects that they’re in charge. Also, define another class called Project that has attributes such as the name and the current progress (in %) of the project. (1) Write the corresponding constructors that initialize the attributes for classes. (2) Write the corresponding destructors that clean up the attributes for classes. (3) Write the corresponding member functions to set and get the attributes for classes. (4) Write a virtual function print_record() that will print all attributes related to the object. Finally, test the classes in a main program. In the test program, you should dynamically allocate some employees and managers, print their corresponding records using the virtual function print_record(), and then release the dynamically allocated objects in the end. 3