C++ 实验八

本次实验深入探讨了C++编程的复杂性和挑战,涉及到大量概念的理解与应用,对思维能力提出了较高要求。
摘要由CSDN通过智能技术生成
#include <iostream>
#include <string>
using namespace std;

class MyDate
{
public:
    MyDate(int y,int m,int d){year=y;month=m;day=d;}
    void diffYear(){diffyear=((2010-year)*12.0-month+1)/12.0;}
    int getyear(){return year;}
    int getmonth(){return month;}
    int getday(){return day;}
    double getdiffyear(){return diffyear;}
private:
    int year, month, day;
    double diffyear;
};
class Person
{public:
    void setname(const string a,string b,string c){name=a;id=b;phonenumber=c;}
    void print(){cout<<name<<"  "<<id<<"  "<<phonenumber<<"  ";}
protected:
    string name,id,phonenumber;
};
class Student:public Person
{public:
    void setgrade(int a){grade=a;}
    void print(){   
        Person::print();
        string a[4]={"Freshman","Sophomore","Junior","Senior"};
        cout<<a[grade-1]<<endl;
    }
private:
   int grade;
};
class Employee:public Person
{public:
    void setoffice(string a){office=a;}
    void setdateHired(MyDate&c){year=c.getyear();month=c.getmonth();day=c.getday();}
    void getdiffyear(MyDate&c){diffyear=c.getdiffyear();}
    void print(){
        Person::print();
        cout<<"office:"<<office<<"  dateHired:"<<year<<"  "<<month<<"  "<<day<<endl;
    }
protected:
    string office;
    double salary;
    int year,month,day;
    double diffyear;
};
class Staff:public Employee
{public:
    Staff(){BasicWages=3000;Allowance=500;}
    void getsalary(){
        salary=BasicWages+Allowance*diffyear;
        cout<<"salary:"<<salary<<endl<<endl;
    }
    void print(){
        Employee::print();
        cout<<"BasicWages:"<<BasicWages<<"  Allowance:"<<Allowance<<endl;
    }
private:
    double Allowance, BasicWages;
};
class Faculty:public Employee
{public:
    Faculty(){BasicWages=3000;}
    void setrank(int a){rank=a;}
    void getsalary(){salary=BasicWages*rank;cout<<"salary:"<<salary<<endl<<endl;}
    void print(){
        Employee::print();
        string a[3] = {"Professor","AssociateProfessor ","AssistantProfessor"};
        cout<<a[rank-1]<<"  BasicWages:"<<BasicWages<<endl;
    }
private:
   int rank;
    double BasicWages;
};

int main()
{
    MyDate a(2000, 1, 1);
    Student stu;
    Faculty fac;
    Staff sta;
    stu.setname("张三","123","12345678901");
    stu.setgrade(2);
    stu.print();
    sta.setname("李四","213","10987654321");
    sta.setoffice("SSTA");
    fac.diffYear();
    sta.setdateHired(a);
        sta.getdiffyear(a);
    sta.print();
    sta.getsalary();
    fac.setname("王五","321","55589964823");
    fac.setoffice("SSTA");
    fac.setdateHired(a);
    fac.setrank(3);
    fac.print();
    fac.getsalary();
    return 0;
}


这次的实验需要大量的脑补内容啊...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值