?? 課程設計第9題.cpp
字號:
#include<iostream.h>
class person
{
protected:
char name[20];
static int num;
public:
person();
static int getnum(){return num;}
};
class student:public person
{
private:
float score;
public:
student();
void display();
friend void gertotal();
};
class teacher:public person
{
private:
char sub [30];
public:
teacher();
void display();
friend void gertotal();
};
int person::num=0;
person::person()
{
cin>>name;
num++;
}
student::student()
{
cout<<"請輸入"<<name<<"同學的分數:"<<endl;
cin>>score;
}
void student::display()
{
cout<<name<<"同學的分數為: "<<score<<endl;
}
teacher::teacher()
{
cout<<"請輸入"<<name<<"老師的專業:"<<endl;
cin>>sub;
}
void teacher::display()
{
cout<<name<<"老師的專業為: "<<sub<<endl;
}
void gettotal()
{
cout<<"此時老師和學生的總數為:"
<<student::getnum()+teacher::getnum()
<<endl;
}
void main()
{
char x,c1,c2;
do
{
do
{
cout<<"請選擇您要輸入人員的身份(s(S):學生,t(T):老師)"
<<endl;
cin>>x;
if(x=='s'||x=='S')
{
cout<<"請輸入該學生的姓名:"<<endl;
student stu;
c1='n';
stu.display();
}
else if(x=='t'||x=='T')
{
cout<<"請輸入該老師的專業"<<endl;
teacher tea;
c1='n';
tea.display();
}
else
{
cout<<"輸入錯誤!"<<endl
<<"是否要重新輸入?(y:是,n:否):";
cin>>c1;
}
}while(c1=='y');
cout<<"是否要結束錄入?(y(Y):結束,n(N):繼續)"<<endl;
cin>>c2;
}while(c2=='n'||c2=='N');
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -