//HW_CH04_57
/*
定义一个Teacher类,该类有以下成员函数:
两个构造函数,一个用于值初始化教师姓名和ID号,一个用于初始化教室姓名、ID号、基本工资、奖金和所得税;
一个输入基本工资、奖金和所得税的函数;一个计算实际发放数的函数;一个输出教师信息的函数。
编写主函数,调用第一个构造函数声明一个教师对象并输入其工资,再调用第二个构造函数声明一个教师对象。
最后分别计算两个教师的实际发放数,并在屏幕输出。
*/
#include<iostream>
#include<string>
using namespace std;
class Teacher {
private:
string name;
string ID;
float basepay;
float bonus;
float tax;
float realpay;
public:
//用于值初始化教师姓名和ID号
Teacher(string name, string ID) {
this->name = name;
this->ID = ID;
}
//用于初始化教室姓名、ID号、基本工资、奖金和所得税
Teacher(string name, string ID, float basepay, float bonus, float tax) {
this->name = name;
this->ID = ID;
this->basepay = basepay;
this->bonus = bonus;
this->tax = tax;
}
//输入基本工资、奖金和所得税的函数
void set();
//计算实际发放数的函数
float calculate();
//输出教师信息的函数
void show();
};
void Teacher::set() {
cout << "please input basepay,bonus and tax:" << endl;
cin >> basepay;
cin >> bonus;
cin >> tax;
}
float Teacher::calculate() {
realpay = basepay + bonus - tax;
return realpay;
}
void Teacher::show() {
cout << "name:" << name << endl;
cout << "ID:" << ID << endl;
cout << "realpay:" << realpay << endl;
cout << endl ;
}
int main() {
Teacher t1("liulu","123456");
t1.set();
t1.calculate();
t1.show();
Teacher t2("wangfang", "223456", 5200, 1800, 50);
t2.calculate();
t2.show();
return 0;
}