姓名
学号
班级
年级
指导教师王浩鸣
西安财经学院信息学院
《面向对象程序设计》实验报告
实验名称实验一:多态性实验室学校机房实验日期
实验目的及要求
。
。
。
。
实验环境
DEV-C++
三、实验内容
#include<iostream>
using namespace std;
class Employee{
private:
string name;
int ID;
public:
Employee(string a,int i){
name=a;
ID=i;
}
~Employee(){
}
void setname(string a){
name=a;
}
void setID(int i){
ID=i;
}
string getname(){
return name;
}
int getID(){
return ID;
}
virtual int getsalary()=0;
virtual void getshow()=0;
};
class Manager:public Employee{
private:
int salary;
public:
Manager(string a,int i,int s):Employee(a,i){
salary=s;
}
~Manager(){
}
void setsalary(int s){
salary=s;
}
void getshow(){
cout<<"姓名为:"<<Employee::getname()<<endl;
cout<<"员工编号为"<<Employee::getID()<<endl;
cout<<"经理"<<endl;
}
int getsalary(){
cout<<"月薪为:"<<salary<<endl;
}
};
class Technician:public Employee{
private:
int wage;
int hours;
public:
Technician(string a,int i,int w,int h):Employee(a,i){
wage=w;
hours=h;
}
~Technician(){
}
void setwage(int w){
wage=w;
}
void sethours(int h){
hours=h;
}
void getshow(){
cout<<"姓名为:"<<Employee::getname()<<endl;
cout<<"员工编号为"<<Employee::getID()<<endl;
cout<<"技术人员"<<endl;
}
int getsalary( ){
int s;
s=wage*hour
C 实验多态性 来自淘豆网m.daumloan.com转载请标明出处.