ex0304.cpp
来自「Visual+C+++6[1].0实用教程代码 Visual+C+++6[1]」· C++ 代码 · 共 139 行
CPP
139 行
// ex0304.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream.h>
#include <string.h>
class person
{
char stu_no[10]; //学号
char name[10]; //姓名
char sex[3]; //性别
char birth[12]; //出生年月
public:
person(char *stu_no1, char *name1,char *sex1,char *birth1)
{
strcpy(stu_no,stu_no1);
strcpy(name,name1);
strcpy(sex,sex1);
strcpy(birth,birth1);
}
void display1()
{
cout<<"学号:"<<stu_no<<endl;
cout<<"姓名:"<<name<<endl;
cout<<"性别:"<<sex<<endl;
cout<<"出生年月:"<<birth<<endl;
}
void display2()
{
cout<<stu_no<<"\t";
cout<<name<<"\t";
}
};
class score
{
float chine, math, eng, gym;
public:
score(float chine1, float math1, float eng1, float gym1)
{
chine=chine1;
math=math1;
eng=eng1;
gym=gym1;
}
void display1()
{
cout<<"语文:"<<chine<<endl;
cout<<"数学:"<<math<<endl;
cout<<"英语:"<<eng<<endl;
cout<<"体育:"<<gym<<endl;
}
void display2()
{
cout<<chine<<"\t";
cout<<math<<"\t";
cout<<eng<<"\t";
cout<<gym<<"\t";
}
};
class student: public person, public score
{
float average;
char grade[7];
public:
student(char *stu_no1, char *name1,char *sex1,char *birth1,float chine1, float math1, float eng1, float gym1)
:person(stu_no1, name1, sex1, birth1),score(chine1, math1, eng1, gym1)
{
average=(chine1+math1+eng1+gym1)/4;
int a=average/10;
switch(a) {
case 10:
case 9:
strcpy(grade,"优秀");
break;
case 8:
strcpy(grade,"良好");
break;
case 7:
strcpy(grade,"中等");
break;
case 6:
strcpy(grade,"及格");
break;
default:
strcpy(grade,"不及格");
break;
}
};
void display1()
{
person::display1();
score::display1();
cout<<"平均分:"<<average<<endl;
cout<<"成绩等级:"<<grade<<endl;
}
void display2()
{
person::display2();
score::display2();
cout<<average<<"\t";
cout<<grade<<"\n";
}
};
int main(int argc, char* argv[])
{
student myclass[10]={student("0321001","张军","男","1997-11-01",75,85,95,90),
student("0321002","李浩","男","1997-11-12",76,85,79,90),
student("0321003","李明","男","1997-12-02",68,75,86,83),
student("0321004","刘芳","女","1997-12-22",84,65,59,78),
student("0321005","王乐","女","1998-01-21",87,65,73,82),
student("0321006","高天","男","1998-03-11",54,55,68,53),
student("0321007","李山","男","1998-04-24",59,63,85,59),
student("0321008","王强","男","1998-04-28",56,65,86,53),
student("0321009","刘欣","女","1998-06-30",84,65,59,78),
student("0321010","袁乐","女","1998-08-13",97,95,93,92)};
cout<<"<=== 单一学生信息 ===>\n";
myclass[0].display1();
cout<<"\n<=== 所有学生信息 ===>\n";
cout<<"学号\t姓名\t语文\t数学\t英语\t体育\t平均分\t等级\n";
for(int a=0; a<10;a++) {
myclass[a].display2();
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?