0 like 0 dislike
1.8k 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 | 1.8k views
0 0
Called for Help

15 Answers

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



using * std;



class * * **

{

//your code here
** *
* * * * * ** * **** int ****
** * ** ** *** * * *** *
**** * * ***** * * * ** * ** * * * *** money;
* * * * *** * * ** * ***
* *
********* ** ** * ** * money;

};



class Intern : public * **

{

//your code here
** *
* * **** ** * * **** ** * * *
** ** * * ** * *** ** int * ***
**** ** *** * ** *** **
* *** **** ** *** *** *** *** **** ** **** * money1;
** ****** *** *** * ** *
*
**** ** * * * * money1;

};



class * ** : public **

{

//your code here
* **
* * ***** * ** * * ******* * ****
* * ** ** ** * ****** ** int * *
*** * * ** ** * * ** *
* * * * * * ***** ** * * *** * * * * *** * money2;
* * * ******* ** ***
* **
*** * ** *** *** ** money2;

};



class * * : public ** **

{

//your code here
**
* * ** * * * ** * ** * * * *
* **** ** * ** ** ** ** ** int *
* ** ****** ** *** *
******** * * ** *** ** ** ***** * * * ** money3;
* *** * * ** ** ** * *
* * *
* * *** * * **** * ** * money3;

};



int ***** * ** **** *pay )

{
* * * * *** ** **** * ** * *** * *

}

int main()

{

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

Intern user3;



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

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

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

return 0;

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



using namespace std;



class Employee

{
** ** * * * *** ******* *
* ** * ** * * ** **** ** * * ** * * * * ** pay;
******* *** ** * * * * * ******** * * int getPay()
* ** ** ** * ** * * * * * *** *** **** * ***
*** * * * ** ** ** ** * * ** * * **** * *** * ** * * * ** pay;
*** * ** * *** ** * * ** * * **** *** *

};



class Intern : public Employee

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

};



class PartTime : public Employee

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

};



class FullTime : public Employee

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

};



int main()

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


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

}
answered by (-364 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 (-581 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 (-384 points)
0 like 0 dislike
Hidden content!
* * ** * * *** * *



using namespace std;



class Employee

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

};



class Intern : public Employee

{
**** *** ** * * * * *******
** * * *** ** * **** ** ** ** * * ** code: Constructor initialize 0 and override function
* ** * * ***** ** * *** ** ***** * ** **
*** * ** ** ** ** ****** *** *** * * * *** * ** ******* * = 0;
** ** * ** **** ** * ** *** *** ** * *** * *****



};



class PartTime : public Employee

{
* ** * ** *** * * * *
* *** * *** **** * ** ******* **** *** *** * * code: Constructor initialize 120 and override function
*** ** * ** **** * **** * * *** ***** *** * *** *
* * *** * * * * * ****** ** * ** **** * ** ** * ***** **** * * *** ** = 120;
* * ** ** * * * *** **** * *** * * ***** * **

};



class FullTime : public Employee

{
* ** * ** * ** ** * *
**** * * ** * ** * ***** * * ** ** code: Constructor initialize 50000 and override function
* ** ***** * * * * ** * * ***** ** ** * ** * ** {
* * * * *** * ** ** * **** * ***** * ** * ** ** * * * * ** *** * * * = 50000;
*** ** * * * * * ** * **** ** ** * * ** *

};



int main()

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


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

}
answered by (5.2k points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.71.255.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
| 1.8k views
0 like 0 dislike
18 answers
[Exercise] Coding (C) - asked May 25, 2017 in C++
ID: 24828 - Available when: Unlimited - Due to: Unlimited
| 2.1k views
12,783 questions
183,442 answers
172,219 comments
4,824 users