?? 程序12.4:例題與應(yīng)用.cpp
字號:
/* 程序12.4:例題與應(yīng)用.cpp:*/
#include<iostream> //包含頭文件
#include<string> //包含頭文件
using namespace std; //使用名字空間std
class Person //聲明基類Person
{
protected:
string cName;
int iAge;
string cBirth;
string cPhone;
public:
Person(string cName,int iAge,string cBirth,string cPhone)
{
this->cName=cName;
this->iAge=iAge;
this->cBirth=cBirth;
this->cPhone=cPhone;
}
virtual void Display() //聲明基類成員函數(shù)
{
cout<<"輸入的姓名是 : "<<cName<<endl;
cout<<"輸入的年齡是 : "<<iAge<<endl;
cout<<"輸入的生日是 : "<<cBirth<<endl;
cout<<"輸入的電話是 : "<<cPhone<<endl;
}
};
class Employee:public Person //聲明子類Employee
{
private:
float fSalary;
public:
Employee(string cName,int iAge,string cBirth,string cPhone,
float fSalary):Person(cName,iAge,cBirth,cPhone)
{
this->fSalary=fSalary;
}
void Display() //聲明子類成員函數(shù)
{
cout<<"\n------顯示職員的個(gè)人信息------"<<endl;
Person::Display();
cout<<"輸入的工資是 : "<<fSalary<<endl;
}
};
class Student:public Person//聲明子類Student
{
private:
float fScore;
public:
Student(string cName,int iAge,string cBirth,string cPhone,
float fScore):Person(cName,iAge,cBirth,cPhone)
{
this->fScore=fScore;
}
void Display() //聲明子類成員函數(shù)
{
cout<<"\n------顯示學(xué)生的個(gè)人信息------"<<endl;
Person::Display();
cout<<"輸入的分?jǐn)?shù)是 : "<<fScore<<endl;
}
};
int main()
{
Person *Ptr;
Ptr= new Employee("abc",20,"315","110",900.5);
Ptr->Display();
Ptr= new Student("efg",17,"610","119",99.5);
Ptr->Display();
delete Ptr;
return 0;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -