创建学生类,类的数据成员名有名字,学号,期中成绩和期末成绩。本次测试软件为VC++6.0绿色版,不足地方欢迎斧正。
#include<iostream>
#include<string>
using namespace std;
class Student
{
public:
string name;
int id;
int mid_score;
int fin_score;
int ave_score;
void showStudent()
{cout<<"姓名:"<<name << " 学号 "<<id<< " 期中成绩:"<<mid_score << " 期末成绩:"<<fin_score <<" 平均成绩:"<<(mid_score+fin_score)/2.0<<endl;
}
};
int main()
{
Student st1;
st1.name="张三";
st1.id=2111001;
st1.mid_score=98;
st1.fin_score=99;
st1.showStudent();
Student st2;
st2.name="李四";
st2.id=2111002;
st2.mid_score=89;
st2.fin_score=93;
st2.showStudent();
Student st3;
st3.name="王五";
st3.id=2111003;
st3.mid_score=89;
st3.fin_score=94;
st3.showStudent();
return 0;
}