#include "stdafx.h"
#include<iostream>
using namespace std;
void a1(int s);
class Student{
private:
int stunum;
string stuname;
int stuage;
int *p;
public:
Student(int num,int age,string name,int *t1){
stunum=num;
stuname=name;
stuage=age;
p=new int[3];
for(int i=0;i<3;i++){
p[i]=t1[i];
}
}
double average(){
int a=0,i=0;
for(i;i<3;i++){
a+=p[i];
}
return(a/3);
}
int max(){
int b=0;
for(int i=0;i<3;i++){
if(p[i]>=b){
b=p[i];
}
}
return b;
}
void display(){
cout<<"学生学号:"<<stunum<<endl;
cout<<"学生姓名:"<<stuname<<endl;
cout<<"学生年龄:"<<stuage<<endl;
cout<<"学生成绩:";
for(int i=0;i<3;i++){
cout<<p[i]<<" ";
}
cout<<endl;
}
};
int main(){
cout<<"请输入学生的人数:"<<endl;
int s;
cin>>s;
a1(s);
return 0;
}
void a1(int s1){
int s;
s=s1;
for(int v=0;v<s;v++){
int num,age;
int *t;
t=new int[3];
string name;
cout<<"请依次输入第"<<v+1<<"名学生的学号、年龄、姓名"<<endl;
cin>>num>>age>>name;
cout<<"请依次输入第"<<v+1<<"名学生3门课程的成绩"<<endl;
for(int i=0;i<3;i++){
cin>>t[i];
}
Student stu1(num,age,name,t);
stu1.display();
cout<<"学生的平均成绩为:"<<stu1.average()<<endl;
cout<<"学生的最高成绩为:"<<stu1.max()<<endl<<endl;
}
}
相关分类