0 like 0 dislike
3.1k views

Please remember our 05-25 Lab Exercise 2: class Employee

How to use Virtual function to solve the problem?

Design a class Employee represent all kinds of employees. TheEmployeee class should contain a member function getPay. The function getPay will return a integer value as the pay
Design Intern class represent a intern that inherit Employee class and implement the member function in Employee class.
Design PartTime class represent a part-time that inherit Employee class and implement the member function in Employee class. This class include attribute Hours-od-duty.
Design Fulltime class represent full-time that inherit Employee class and implement the member function in Employee class. This class include attribute monthly pay.

#include<iostream>

using namespace std;

class Employee
{
    public:
        //Your code: put virtual function here
};

class Intern : public Employee
{
    public:
        //Your code: Constructor initialize 0 and override function
};

class PartTime : public Employee
{
    public:
        //Your code: Constructor initialize 120 and override function
};

class FullTime : public Employee
{
    public:
        //Your code: Constructor initialize 50000 and override function
};

int main()
{
    int money = 0;
    PartTime user;
    FullTime user2;
    Intern user3;

    money = user.getPay();
    cout<<"Partime : " << money<<endl;
    money = user2.getPay();
    cout<<"Full time monthly pay : " << money<<endl;
    money = user3.getPay();
    cout<<"Intern : " << money<<endl;
    return 0;
}
[Exercise] Coding (C) - asked in C++
ID: 24854 - Available when: Unlimited - Due to: Unlimited

edited by | 3.1k views
0 0
Called for Help

15 Answers

0 like 0 dislike
Hidden content!
* * * * ***** * ** *



using ***** std;



class Employee

{
* * * *** * *** ** **
* * ****** * * * **** ** * **** *** ** int getPay() ;//Your code: put virtual function here

};

int *** * ** *

{
* * * * ** *** * * **** amount;
** ** **** * ** * ** ** * amount;

}



class Intern : public Employee

{
**** *** * * *** **** ** **
* * * ** ** * * ***** ** * **** *** a;
****** ** *** * ** * * * *** **** * * * ** * * * ** * * = * * code: ** ** * ** 0 and override function
*** * ** * * ** * ** * **** * * * ** * * * getPay() {return a;}

};



class PartTime : public Employee

{
* * *** *** ** ******
* *** * ** ** ***** * *** * * ***** b;
* *** **** * * * * * *** ** * ** * * * ** * ** = * * code: ** ** * ** 120 and override ***
* **** * ** * ** * * ** ** **** *** * ***** getPay() {return b;}

};



class : public *

{
** * * * *** * * ** * **
** ** *** * * ** **** * * * * ***** ** * c;
* *** * ****** * * * * * * * * * * * = *** *** code: ** *** * * ** 50000 and override function
* * ****** * *** * * * ** * ** * *** getPay() {return c;}

};



int main()

{
* * * *** ** * ** * * money = 0;
*** ** ** * * ** **** * user;
** * *** **** ** *** ****** user2;
* * *** * * * * * user3;


** ** ** ** ** ***** * * = * *
* ***** ** ** **** ****** * * * : *** ***** * * ***
**** * ** *** ** *** = * ** *** *
*** * ** *** * *** ** * ** * * ** *** ** ** time monthly pay : **** * * * * ** *** ***
* ** ** * * * ** * ** = ****** *
* * * *** ****** * ***** *** ** * *** * * * : * *** * * * * ***** * *
* * ** * * **** ******** 0;

}
answered by (-298 points)
0 like 0 dislike
Hidden content!
* ** * * * *****



using ** std;



class Employee

{
* * * **** * ** ** ** *****
** * ** *** ***** * ** ** * ** * ***** *** int getPay() ;//Your code: put virtual function here

};

int ***** **

{
*** *** * ** *** * amount;
* *** * ***** * *** ** ** amount;

}



class Intern : public Employee

{
** ** * * * * * * **
**** * * * ** ** ** *** * * * a;
** * ** ** * * ** * *** * * * **** * * = **** ** code: *** * *** 0 and override function
* * * ** * * * ***** ** * * **** getPay() {return a;}

};



class PartTime : public Employee

{
** * *** * * *** ** * * ** *
** *** * ** * ** ** * * ** **** * ** ** * b;
* ** * ** * ** ** ** * * * * ** ** * * ****** ** = * * * code: * * **** 120 and override *
* * * * ** * * **** * * * ** ** * * getPay() {return b;}

};



class ** : public *

{
** *** **** *** ** ** **
** ** **** * ** * * ***** * * * * ** * ** * c;
**** **** * * **** * ** * * * **** ** ** ** * * * * = * *** code: ** * *** * 50000 and override function
*** ** ** * ** * * * ** **** ****** ** ** *** getPay() {return c;}

};



int main()

{
*** *** * * * *** * * money = 0;
** ** * ** * ** * *** * ** user;
**** * * *** * * * ** * user2;
***** * ** * * ** * *** user3;


* *** ***** * ** **** = ** ** * **
* * * *** ** * * ** * * * : ***** * * * * ** * * ** * ***
* * * *** * * * ** *** * = **** * *
** *** * * * *** ** *** * ** * * * *** **** time monthly pay : *** * ** **** *** * * ** ** **
* ** * ******* * ***** * = ** **** *
* ** *** ** * ** ** *** * ** * *** ** * * : ** * * *** * ** **** ** ***
** * * * *** ******** 0;

}
answered by (-215 points)
0 like 0 dislike
Hidden content!
* * ** * ** *



using ** * * std;



class * **

{
* * *** * * **** * ***
* * ** ***** * ****** * ** * ** * * *** ** * ** * int getPay() ;//Your code: put virtual function here

};

int * * * *

{
* **** * * ** * ** ** ***** amount;
* ** * ** * ** ** * amount;

}



class Intern : public Employee

{
* * * *** * * ** * ** *
* * * * * * ******* * ** * *** ** * * ** * a;
* * ******* * ***** ** * * *** * * *** * * * * = ** * code: ** * * * * * 0 and override function
* ** * * * * * ** * ******* ** ********* * getPay() {return a;}

};



class PartTime : public * **

{
** ***** ** ** * ** *
* ** ** * * ***** *** * * * * * * ** b;
*** * ***** **** **** * ** ***** *** * * ******* * ***** = *** code: **** *** ** 120 and override function
* ** * * * ** * * * ** ****** * * {return b;}

};



class ****** : public ** *

{
* * * ****** ***** ***
*** * * * * * * **** ** ** * ** * * **** ** ** * * c;
* ** *** **** ** * * * ** * * *** * * *** **** *** = ** ** * code: * * ** ** 50000 and override function
** * * ** * *** * **** * * * * * * * ******* getPay() {return c;}

};



int main()

{
* * * ** ** * ** * money = 0;
************* * * * user;
** * ** * * ** ** * user2;
* *** **** * ** *** * * ** user3;


** ** ** * * *** * ****** ** = ** * ** *
*** * ** ** *** * * *** * **** ****** *** : * * ** * * * *** * * * **
* * *** * * ** ** * * = * * **
* ***** * * * * * * ** * **** ** * * time monthly pay : * *** * * * * ** * ***
** * * * ** * * **** **** * * = * *
*** * * ** ***** * * ** * * ** * ** : * *** * * * ***** ** * **
*** ** ** * * *** * 0;

}

Isaias Majil
answered by (-215 points)
0 like 0 dislike
Hidden content!
* ***** *** * *



using ****** std;



class Employee

{
* * ***** ** *** *
* * ** * * ** * ** ******* * ** **** * * int getPay() ;//Your code: put virtual function here

};

int * ** * **

{
** * *** * ** ** * ** amount;
* ** * *** ** ** **** amount;

}



class Intern : public Employee

{
** ** * ** * ** ** ***
** * ** ** * *** ** ** * * **** * * **** * * a;
* **** ** **** * * ***** * ** * * * * *** * * = * * code: * *** * ** 0 and override function
* **** ** ** * * ** * *** * * * *** * getPay() {return a;}

};



class PartTime : public Employee

{
** * * ** **** *** * **
** ** ** * * *** *** * * * ** ** *** * * * b;
* * ****** * * *** * ** ** * ** **** * ** = ** ** code: ** * * 120 and override ** * *
* * * * * * *** * ** * * **** * * * getPay() {return b;}

};



class * *** : public ** *

{
* **** ***** * ***
* *** **** *** * * * ** *** ********** * * c;
* ** * *** ** ** *** ** ** ** * * * * * ** * * = * *** * code: ** * * * 50000 and override function
** * ** **** * * * * ***** ** * * ** getPay() {return c;}

};



int main()

{
** * * * *** *** money = 0;
* * * ** * ** * * ** * ** user;
* **** *** ** * ** * * * user2;
**** * ***** * * user3;


** * * *** ** * * * * * * = ** *
* ** *** * * * * ** * ** * * * * ** * * ** : *** ** * * * * ** ** *** *
** ** * **** ** ** * * ** = * **
** * * *** ** * *** * *** ** ** time monthly pay : ** * * * * * * * * *
* ***** ****** ** **** * *** * * = *** * **
*** ****** ***** * * * * * ** * ****** : * ** * * ** * **** ***
* ** * * * * * * ** 0;

}
answered by (237 points)
0 like 0 dislike
Hidden content!
***** ** * ** * ******



using *** *** std;



class Employee

{
*** * * ****** *** **
**** ** * * * *** *** * ** * * *** ******* ** int getPay() ;//Your code: put virtual function here

};

int ** *** **

{
** ** **** * *** **** * * amount;
** ** * ***** * * * * * amount;

}



class Intern : public Employee

{
* ***** * ** * **** * ** *
** *** ** *** *** * ** ** * * * ** * a;
* * ****** ***** * * **** * **** * * ** ** * **** = **** code: * ** ** ** 0 and override function
*** ** * *** **** ** ** ** *** **** ***** getPay() {return a;}

};



class PartTime : public Employee

{
**** * * * ***** *** * *
* * *** * * * * *** ** ** ** ** *** ** ** b;
***** *** * * * *** * ** ****** * * *** ** ** *** * = ** *** code: *** ** * * 120 and override * * *
* ** ** * ** * ** *** *** * * * *** getPay() {return b;}

};



class *** : public * * *

{
*** ** * *** * * * * *
* ** *** ** * * ** * * *** *** *** * * ** c;
* ** * ** ** ***** * * * ** * * *** * *** ** = *** * code: *** * ** * 50000 and override function
* **** *** ** ** **** ** ** ** *** **** * * ******* ** getPay() {return c;}

};



int main()

{
* * ** **** **** money = 0;
****** *** * * * * * ****** user;
* *** * * * ***** * * ** * * user2;
* * * * * * * ** ** ** * user3;


** *** **** * ** * * ** *** = * ***
* * ** ******** ** ** ** * * * * * * : * * ** ** ** * ** * ** * ****
* ***** **** *** * = **** ** *
* *** ** * ** ** * ** * ** * ** time monthly pay : ** * * ** * * *** * * * *
* *** * ** **** ** * ** ** ****** = ** * * *
* * * ** * * * * ** * * * *** : * * * **** * ** * * **
** ** * *** ** ****** * ***** 0;

}
answered by (126 points)
0 like 0 dislike
Hidden content!
* **** *** * ** *



using namespace std;



class Employee

{
* * * ***** ** *** **
* ** *** ** * * * * * ** ** * * * ****** * * * * **** * int getPay(){
** ** * ** * ****** * * ** ** ** ** ** ****** * ** *** * *** S;
* * *** * * ****** ** *** ** **** * *
******* * ***** ** ********
** *** **** ** ** * *** * * * ** * *** *** * ** S;

};



class Intern : public Employee

{
** ** * * * ** * * * *
* * ** ** * ** * * ****** * * * * *** ** * *
** ** * ** ** * ** ** ***** * *** ****** * * *** * * * * * * ** * = 0;
*** ***** ** ** * *** * * **** *** *



};



class PartTime : public Employee

{
* ** ** * * **** * ** **** **
* ******* * * * * * * * * * * * *** ** **
* *** * * * * * * ****** *** ** * * ** ***** * ** ** * ** = 120;
* * * * * *** * * *** * **** ** * * ** * *

};



class FullTime : public Employee

{
* **** *** ***** ** *
* ****** * ** * * * * * ** ** ** * * {
* **** ** * ** ** * ** * *** * **** * *** * * ** ***** * * **** = 50000;
* ** * * * ****** * * * * ** * ** ** ** ** ******* *

};



int main()

{
** ** ** * * *** * ** * money = 0;
** **** ** ** * ** *** user;
** * ** * ******* user2;
* * * ** * *** ** **** **** user3;


** * * **** * * ** * = user.getPay();
* * ** * * ***** * **** * *** ** * ** ** : " << money<<endl;
**** * *** ** **** * *** * = user2.getPay();
* * * ******** * ***** ** ******** time monthly pay : " << * ** *** ** *
**** *** ** ** * ** * ** * = user3.getPay();
** * ** ** * * *** *** *** ***** ** * : " << money<<endl;
* ** ** * * *** * * ** 0;

}
answered by (-249 points)
0 like 0 dislike
Hidden content!
** * * * **** *

using namespace std;



class Employee

{
** ** * ****** * ** *** **
* **** * ** * * ** * * ******* * * * code: put virtual function here
** ** **** * * * * ** * * *** ****** ***** ** ***** x){
** ** * * ** ** * ******* * * * * * * * * ** ** *** * *** = x;
** * * * * * * ** *** * *** *** ** * * * ******* *
* ** *** * ******** * * ** ** ***** ** * * * getpay(){
* *** ** * ***** * * ******* * * *** * ** *** ** * ** * * * pay;
*** * *** * ** ***** *** * ********* ** * * *
** * * ** ****** **** ** *
* * *** * * ** *** * * * * * *** * * *** * pay;

};



class Intern : public Employee

{
* ** * *** * * ** * ** * **
* ******* * * * *** ** * * ** **** * code: Constructor initialize 0 and override function
* ***** ** * * * ** *** *** ** * ** *
* *** * **** * ** ** * **** * * * ** ** ** * getPay(){
** * * ** *** *** ** ** ** ** * * ***** * *** ** * *** * 0;
** * * * **** * * ***** * * * * ** * *

};



class PartTime : public Employee

{
* *** ** *** ** * *
* ** * * * * * * * **** * *** * *** * * code: Constructor initialize 120 and override function
** ******* * ** * * * ** *** ** ** * *** * * ** * *
** ** ** ** * * * * * * ** *** ***** **** getPay(){
** **** * *** * * * ** * * * ** ** * ******* * * ** *** ** * 120;
** * **** * ** * * ** ** * **** * * * ****

};



class FullTime : public Employee

{
** ** * * * **** *******
** ** * * * * **** * * ** ** ** * * code: Constructor initialize 50000 and override function
** * *** **** * * ** *** **** **** **** * ** * * **** **
* * * ** * *** **** * *** * *** ** * getPay(){
* ** * * * * ** * ****** * * **** * * * * * * * * ** ** ** * ** 50000;
**** * ** ** * * ***** * *** * * ******* **

};



int main()

{
* ** ** ** *** * money = 0;
* * ** *** * * * * * * user;
*** ** *** *** ** * ** *** ** user2;
**** ** *** * ** * *** user3;
* **** ***** **** ** **
* * ** * ** * * ** *** = user.getPay();
* * ** **** **** * *** * * * *** * : " << money<<endl;
* * *** * * * ** * ** = user2.getPay();
* ** ** *** *** * * ** * *** ** time monthly pay : " << money<<endl;
** * * * ** *** * **** ** = user3.getPay();
*** * * **** * ***** **** ** *** : " << money<<endl;
* * * * * ****** * * ** 0;

}
answered by (-136 points)
0 like 0 dislike
Hidden content!
* * ** *** * *** *



using * * std;



class ***

{
* ** code here
* * *
**** * * **** * *
* ** ** * * ** * *** ***** * ** ** ** **** *
** * **** ******* **
*** **** * ****** ** *** ***
**** *********** **** * ** * * * * *** * ** * ** Money;
** * * * ** **** *
* * * *** *** * ****** Money;

};



class Intern : public * * *

{
* code here
*
** ** * **** * * ** *** * ***
* * ** ** *** ** ** * * * *
* * * ****** * * ** ****

};



class **** : public * **

{

//your code here
*
* * * *** * ***** * *** * *
* * ***** * * * **** * *
**** *** * ***** * **

};



class * : public **

{
* code here
* *
** *** ** * ** ** * **
** *** * * * **** * ***
** * * * * * * *

};



int main()

{

int money = 0;
** user;
***** * user2;

Intern user3;



money = * * * *
** * ** ** ** ** * : * * * * * * **** **** *

money = *** * *
** ** ** * * time * pay : ** * * ** * ** * * ** * * * * *

money = * * **
** ** ** * * * *** : * * * ******* *
* * 0;

}
answered by (-368 points)
0 like 0 dislike
Hidden content!
* *** ***** * ***** *



using * * std;



class Employee

{
* ** ***** * * ** ** * ***
* * ** * * **** ** * * * *** *** int getPay() ;//Your code: put virtual function here

};

int ** ** *

{
* * ***** * *** * * amount;
**** ******* ****** ** * amount;

}



class Intern : public Employee

{
* * ** * *** * * * * *
* ** *** * ** * ** * * **** * * * * ** ** a;
** * ** * *** *** ** **** ** ** ***** * ** * * = * ** code: ** * * *** 0 and override function
* * *** * * *** *** * ** * ***** ** * * *** getPay() {return a;}

};



class PartTime : public Employee

{
* ****** * ****** **
* * ** **** * **** ** **** ******** * * ** b;
** ** **** * **** * * * * * * ** ** * * ** * = **** * code: * * * *** * * 120 and override ** * *
* * * * * ** * ** **** ** ** ** * * getPay() {return b;}

};



class ** * : public *

{
** *** * * *** ***** * *
***** ***** ** * *** * ** ****** * *** * ** * **** c;
* ** ****** *** * *** ** * * ** **** * * ** ** * *** = **** code: ** * * * ** 50000 and override function
* ***** ** ** *** ** * *** * *** ** ** ** getPay() {return c;}

};



int main()

{
* **** * * **** ** * * * * * money = 0;
* *** ** ** ******* * * user;
* ** ** * * * * * ** * user2;
* ** **** ** ** ******** * * user3;


* * ** ** * ** * * ** = *** *
** * **** ***** ** * * * ** * * ** ** : * * ** * * * * * * ** *** * **
***** * * ** **** * = * *
* **** * * *** * ** * *** ** * * * * *** time monthly pay : **** * ** * * ** ** * ** *
* ** * * * * *** = *** **
** ** ** ** ******* * ***** *** * *** * **** : * ** * * ****** *** * * * ** ***
* *** ** * *** * * *** 0;

}
answered by (-189 points)
0 like 0 dislike
Hidden content!
* * ** *

using namespace std;



class Employee

{
* * * * * * ****** ** * **
* * * * ******** **** *** * ** **** ** * * ** code: put virtual function here
* ** *** **** ** ** * * **** * * * * *** x){
*** ** ** **** ** ** **** **** * *** ** * * * *** *   pay = x;
** * * * * ** *   }
* * *** ** * * *** * **** * *** ** * ** ****** * getpay(){
* * ** ** ******* *** * ** * * * * *** ** *** * **   return pay;
* ***       }
*** ****** ** ** *** **** * *
** ** * * *** * * * ** *** ** * * int pay;

};



class Intern : public Employee

{
*** * ** * ** *** * * * * **
* * * *** **** * * ***** * ** * * **** code: * initialize 0 and override function
** **** ** * ** * * * * * *** * * * *** ** **
* **** * ** **** * * * ** * * * ** ***** * ** ** getPay(){
*** **** * * * * * ** * *** ** * ********* *   return 0;
* ** * ** * * * ** ***** }

};



class PartTime : public Employee

{
* * ********** * ****** * *
* **** * * **** *** *** * * ** ** * ** *** code: ** *** * ** ** 120 and override function
**** *** * ******* * ** * ***** * ***** * **** ** ****
* ** **** *** ** * * * * ** * *** * *** * getPay(){
* *** * **** ** ****** * **** * * ****** * * ** return 120;
* * * ** * *** ***** }

};



class FullTime : public Employee

{
* * ** * ** * * * * ** **
** ** **** * **** * ** * * * * ** * *** * code: *** * * ** 50000 and override function
* * * * *** * * * * * ** ** ** * * * * ** *** *
* * ***** ****** * * * * * ****** ** * * ** ** ** getPay(){
**** **** **** ** *** * * ***** ** *** *   return 50000;
* * *       }

};



int main()

{
** * *** * * **** **** ** money = 0;
* * *** * ***** *** *** * user;
** * * ** ****** * * * * * user2;
* * * ** *** * **** ** user3;
*** * * *** *** ** *
***** *** ** ******** * = ** * ***
*** ** ** * * ** * **** * * ** * * * : " * ** * ** * * * ** ***
*** * *** * ****** * ** = ** ** *
* ** * * ** * * * * * ** ** ***** ***** * time monthly pay : * ** * * * ** * ** * * *** *
*** ******** * * * *** ***** = * * *** *
** *** *** * ** ** * * * * * * *** * *** : " * **** ** *** ***
** ****** * ** ** ** ** * 0;

}
answered by (-134 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.59.81
©2016-2025

Related questions

0 like 0 dislike
17 answers
[Exercise] Coding (C) - asked Jun 1, 2017 in C++
ID: 24855 - Available when: Unlimited - Due to: Unlimited
| 3.1k views
0 like 0 dislike
18 answers
[Exercise] Coding (C) - asked May 25, 2017 in C++
ID: 24828 - Available when: Unlimited - Due to: Unlimited
| 3.7k views
12,783 questions
183,442 answers
172,219 comments
4,824 users