您的位置:首页 > 其它

第4次上机作业

2016-05-03 21:15 260 查看
/*
* 文件名称:balabala
* 作    者:  郝荣雅
* 完成日期: 2016     年  5   月 1   日
* 版 本 号:v1.0
* 对任务及求解方法的描述部分:
* 输入描述:
* 问题描述:
* 程序输出:
* 问题分析:
* 算法设计:
*/

1,项目三

#include <iostream>      

#include <string>      

using namespace std;      

class CPerson      

{      

protected:      

    string m_szName;      

    string m_szId;      

    int m_nSex;     

    int m_nAge;      

public:      

    CPerson(string name,string id,int sex,int age);    

    void Show1();       

};      

class CEmployee:public CPerson      

{      

private:      

    string m_szDepartment;      

    double m_Salary;      

public:      

    CEmployee(string name,string id,int sex,int age,string department,double salary);    

    void Show2();    

};    

CPerson::CPerson(string name,string id,int sex,int age)    

{    

    m_szName=name;    

    m_szId=id;    

    m_nSex=sex;    

    m_nAge=age;    

}    

void CPerson::Show1()    

{       

    cout<<m_szName<<"    "<<m_szId<<"    ";    

    if(m_nSex==0)    

        cout<<"女      ";    

    else if(m_nSex==1)    

        cout<<"男    ";    

    cout<<m_nAge<<"      "<<endl;    

}    

CEmployee::CEmployee(string name,string id,int sex,int age,string department,double salary):CPerson(name,id,sex,age)       

{    

    m_szDepartment=department;    

    m_Salary=salary;    

}    

void CEmployee::Show2()    

{    

    cout<<"姓名 "<<"ID "<<"性别 "<<"年龄 "<<"部门 "<<"薪水"<<endl;    

    cout<<m_szName<<"    "<<m_szId<<"    ";    

    if(m_nSex==0)    

        cout<<"女      ";    

    else if(m_nSex==1)    

        cout<<"男      ";    

    cout<<m_nAge<<"    "<<m_szDepartment<<"   "<<m_Salary<<endl;      

}    

int main()      

{      

    string name,id,department;      

    int sex,age;      

    double salary;      

    cout
a04c
<<"请输入雇员的姓名,ID,性别(0:女,1:男),年龄,部门,薪水:\n";      

    cin>>name>>id>>sex>>age>>department>>salary;      

    CEmployee employee1(name,id,sex,age,department,salary);      

    employee1.Show2();      

    return 0;      

}      

2,项目二

#include <iostream>    

#include <string>    

using namespace std;    

class Stu   //声明基类    

{    

public:    

    Stu(int n, string nam ):num(n),name(nam){}  

    void display( )      

    {  

        cout<<"学号:"<<num<<endl;  

        cout<<"姓名:"<<name<<endl;  

    }  

protected:        //(*)访问权限为保护型的数据成员    

    int num;      //学生学号    

    string name;  //学生姓名    

};    

class StuDetail: public Stu              //声明派生类StuDetail    

{    

public:    

    //学生nam,学号n,a岁,家住ad,他的班长是nam1,学号n1    

    StuDetail(int n, string nam,int a, string ad,int n1, string nam1):Stu(n,nam),monitor(n1,nam1)  

    {  

        age=a;addr=ad;  

    }//派生类构造函数    

    void show( )  

    {  

        cout<<"学生信息:"<<endl;  

        display();  

        cout<<"年龄:"<<age<<endl;  

        cout<<"住址:"<<addr<<endl;  

    }//成员函数,输出学生的信息    

   void show_monitor( )  

   {  

      monitor.display();  

   }  

private:    

    Stu monitor;   //学生所在班的班长,班长是学生,是Stu类的成员    

    int age;       //学生年龄    

    string addr;   //学生的住址    

};    

int main( )    

{    

    //学生张三,10010号,19岁,家住江西南昌,他的班长是李四,学号10001    

    StuDetail s(10010,"张三",19,"江西南昌",10001,"李四");    

    s.show( );                       //输出学生信息   

    cout<<"班长信息:"<<endl;  

    s.show_monitor();                //输出班长信息    

    return 0;    

}    
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: