第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;
}
相关文章推荐
- 乱码问题总结
- 字典序全排列
- 《java入门第一季》之参数引用
- C#课后习题---消息对话框实验
- 《java入门第一季》之参数引用
- 驱动笔记15 - 键盘过滤驱动学习笔记
- hdu 5025 Saving Tang Monk【BFS+状态压缩+优先队列】
- Array of Leetcode: EASY
- 两个JFramen之间的通信
- 数组指针和指针数组的区别
- CSS3滤镜-水平和垂直翻转图片
- 【驱动笔记14】初步认识MDL
- 打印10行10列★
- redis性能优化
- C经典 使用选择排序排列字符串数组
- putty连接虚拟机
- 第一个缺失的整数
- spark 的reduce操作
- Spark组件之GraphX学习7--随机图生成和reduce最大或最小出度/入度/度
- Spring+Swagger文档无法排序问题解决