五、编程题(本大题共2小题,第1小题12分,第2小题16分,共28分) 1.参考程序: #include
class DateInfo {
private: int year, month, day;
public: DateInfo(): year(2010), month(6), day(8){ } DateInfo(int y, int m, int d): year(y), month(m), day(d){ } void Set(int y, int m, int d) { year = y; month = m; day = d; } void Show() { cout << year << \年\月\日\};
int main() { DateInfo d1, d2(1988, 8, 18); d1.Show(); d2.Show(); d2.Set(1999, 9, 19); d2.Show(); return 0; }
2.参考程序:
#include
class Staff {
protected: int num; char name[18]; double rateOfAttend; double basicSal ; double prize ;
static int count; public: Staff(){ } void Input() { num = ++count; cout << \请输入编号为\号员工的信息\ cout << \姓名:\ cin >> name; cout << \基本工资:\ cin >> basicSal; cout << \奖金:\ cin >> prize; cout <<\出勤率(0~1):\ cin >> rateOfAttend; } void Output() const { cout << \编号:\ cout << \姓名:\ cout << \基本工资:\元\ cout << \奖金:\元\ cout << \出勤率:\ } void OutputWage() const { cout << \实发工资:\ << basicSal + prize * rateOfAttend << \元\ } };
int Staff::count = 1000;
class Saleman : public Staff {
protected: float deductRate; float personAmount;
public: Saleman (){ }; void Input() {
Staff::Input(); cout << \个人销售额:\ cin >> personAmount; cout << \提成比例:\ cin >> deductRate; } void Output() const { Staff::Output(); cout << \个人销售额:\元\ cout << \提成比例:\ } void OutputWage() const { cout << \实发工资:\ << basicSal + prize * rateOfAttend + personAmount * deductRate << \元\ } };
class Manager: public Staff {
protected: double totalDeductRate; double totalAmount;
public: Manager(){ } void Input() { Staff::Input(); cout << \公司总销售额:\ cin >> totalAmount; cout << \提成比例:\ cin >> totalDeductRate; } void Output() const { Staff::Output(); cout << \公司总销售额:\元\ cout << \提成比例:\ } void OutputWage() const
{ cout << \实发工资:\ << basicSal + prize * rateOfAttend + totalAmount * totalDeductRate << \元\ } };
int main() { char flag = 'Y'; while (toupper(flag) == 'Y') { cout << \请选择录入类别(1.员工 2.销售员 3.经理)\ int n; cin >> n; if (n == 1) { // 员工 Staff objStaff; objStaff.Input(); objStaff.Output(); objStaff.OutputWage(); } else if (n == 2) { Saleman objSaleman; objSaleman.Input(); objSaleman.Output(); objSaleman.OutputWage(); } else if (n == 3) { Manager objManager; objManager.Input(); objManager.Output(); objManager.OutputWage(); } else { cout << \选择有误!\ }
}
}
cout << endl << \是否继续录入信息?(Y/N)\cin >> flag;
return 0;