0 喜歡 0 不喜歡
2.6k 瀏覽

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;
}
[練習] Coding (C) - 最新提問 分類:C++ |
ID: 24854 - 從幾時開始: 無限制 - 到幾時結束: 無限制

修改於 用戶: | 2.6k 瀏覽
0 0
Called for Help

15 個回答

0 喜歡 0 不喜歡
內容已隱藏
* ** * ** *



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;

}
最新回答 用戶: (-298 分)
0 喜歡 0 不喜歡
內容已隱藏
* * * ****** *



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;

}
最新回答 用戶: (-215 分)
0 喜歡 0 不喜歡
內容已隱藏
* ** ** * *** ** *



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
最新回答 用戶: (-215 分)
0 喜歡 0 不喜歡
內容已隱藏
*** ** *** **



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;

}
最新回答 用戶: (237 分)
0 喜歡 0 不喜歡
內容已隱藏
* * * * ** *



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;

}
最新回答 用戶: (126 分)
0 喜歡 0 不喜歡
內容已隱藏
***** ****



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;

}
最新回答 用戶: (-249 分)
0 喜歡 0 不喜歡
內容已隱藏
* * ** **** *****

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;

}
最新回答 用戶: (-136 分)
0 喜歡 0 不喜歡
內容已隱藏
* ** * **** * ** * *



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;

}
最新回答 用戶: (-368 分)
0 喜歡 0 不喜歡
內容已隱藏
* * **** ** * * *



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;

}
最新回答 用戶: (-189 分)
0 喜歡 0 不喜歡
內容已隱藏
* * ** * *

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;

}
最新回答 用戶: (-134 分)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.214.38
©2016-2025

相關問題

0 喜歡 0 不喜歡
17 回答
[練習] Coding (C) - 最新提問 6月 1, 2017 分類:C++ |
ID: 24855 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 2.6k 瀏覽
0 喜歡 0 不喜歡
18 回答
[練習] Coding (C) - 最新提問 5月 25, 2017 分類:C++ |
ID: 24828 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 3.1k 瀏覽
12,783 問題
183,442 回答
172,219 留言
4,824 用戶