<pre class="cpp" name="code">#include<iostream>
#include<cstring>
using namespace std;
class Student{
private:
int number;
char name[20];
char sex[10];
int grade,english,math;
public:
void InputData()
{
cout<<"请输入以下资料:"<<endl;
cout<<"学号:";cin>>number;
cout<<"姓名:";cin>>name;
cout<<"性别:";cin>>sex;
cout<<"年级:";cin>>grade;
cout<<"英语成绩:";cin>>english;
cout<<"数学成绩:";cin>>math;
cout<<" "<<endl;
}
void ShowData()
{
cout<<"以下为该学生的资料:"<<endl;
cout<<"学号:"<<number<<endl;
cout<<"姓名:"<<name<<endl;
cout<<"性别:"<<sex<<endl;
cout<<"年级:"<<grade<<endl;
cout<<"英语成绩:"<<english<<endl;
cout<<"数学成绩:"<<math<<endl;
}
};
int main()
{
Student stu1;
stu1.InputData();
stu1.ShowData();
return 0;
}
定义学生类
最新推荐文章于 2019-09-27 09:43:33 发布