C++课程设计学生成绩统计管理

2025-03-03 04:35:26
推荐回答(1个)
回答1:

这是在标准输出窗口输出的源码

#include
#include
#include

using namespace std;

ifstream fin("Salary.dat");

class stu
{
public:
char name[21];
int num,mark[3];
bool yx,jg;
stu(){for(int i=0;i<21;i++) name[i]='\0'; num=0; mark[0]=mark[1]=mark[2]=0; yx=jg=false;};
void set(int,char[],int,int,int);
};

void stu::set(int n,char na[],int q,int w,int e){
num=n;
for(int i=0;i<21;i++)
if(na[i] != '\0')
name[i]=na[i];
else
break;
mark[0]=q;
mark[1]=w;
mark[2]=e;
int x=mark[0]+mark[1]+mark[2];
if(x >= 85*3){
yx = true;
jg = true;
}
else if(x >= 60*3)
jg = true;
}

int main(){
int n,q,w,e;
char na[21];
int max[3]={0,0,0};
int min[3]={100,100,100};
int tot[3]={0,0,0};
int yx=0;
int jg=0;
cout << "number name courseA courseB courseC" << endl;;
for(int i=0;i<30;i++){
stu s;
fin >> n;
char p;
fin.get(p);
fin.get(na,21,' ');
fin >> q >> w >> e;
s.set(n,na,q,w,e);
if(s.yx)
yx++;
if(s.jg)
jg++;
for(int j=0;j<3;j++){
tot[j]+=s.mark[j];
max[j] = s.mark[j]>max[j]? s.mark[j]:max[j];
min[j] = s.mark[j] }
cout << s.num << ' ' << s.name << ' ' << s.mark[0] << ' ' << s.mark[1] << ' ' << s.mark[2] << endl;
}
cout << setprecision(3) << "平均 " << (float)(tot[0])/30 << ' ' << (float)(tot[1])/30 << ' ' << (float)(tot[2])/30 << endl;
cout << "最高 " << max[0] << ' ' << max[1] << ' ' << max[2] << endl;
cout << "最低 " << min[0] << ' ' << min[1] << ' ' << min[2] << endl;
cout << "优秀率 " << yx*100/30 << "%" << endl;
cout << "及格率 " << jg*100/30 << "%" << endl;
cout << "不及格率 " << (30-jg)*100/30 << "%" << endl;
return 0;
}