0 thích 0 k thích
614 đã xem

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) - đã hỏi trong C++
ID: 24854 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn

đã sửa bởi | 614 đã xem
0 0
Called for Help

15 Trả lời

0 thích 0 k thích
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;

}
trả lời bởi (-298 điểm)
0 thích 0 k thích
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;

}
trả lời bởi (-215 điểm)
0 thích 0 k thích
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
trả lời bởi (-215 điểm)
0 thích 0 k thích
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;

}
trả lời bởi (237 điểm)
0 thích 0 k thích
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;

}
trả lời bởi (126 điểm)
0 thích 0 k thích
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;

}
trả lời bởi (-249 điểm)
0 thích 0 k thích
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;

}
trả lời bởi (-136 điểm)
0 thích 0 k thích
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;

}
trả lời bởi (-368 điểm)
0 thích 0 k thích
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;

}
trả lời bởi (-189 điểm)
0 thích 0 k thích
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;

}
trả lời bởi (-134 điểm)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.178.131
©2016-2024

Những câu hỏi liên quan

0 thích 0 k thích
17 trả lời
[Exercise] Coding (C) - đã hỏi ngày 1 tháng 6 năm 2017 trong C++
ID: 24855 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 655 đã xem
0 thích 0 k thích
18 trả lời
[Exercise] Coding (C) - đã hỏi ngày 25 tháng 5 năm 2017 trong C++
ID: 24828 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 798 đã xem
12,783 câu hỏi
183,443 trả lời
172,219 bình luận
4,824 thành viên