4.7.5.cpp
来自「通过从文件中录入学生成绩,对成绩进行分析.并将结果存入文件」· C++ 代码 · 共 41 行
CPP
41 行
//实现功能一(5):计算全部学生各门课程的平均分数,并输出到文件中
#include<iostream>
#include <fstream>
#include"CBaseStudent.h"
using namespace std;
//函数的实现
void gemenaver(CStudent st5[6])
{
ofstream outfile5("各科平均分数5.txt");
double av1=0,av2=0,av3=0,av4=0,av5=0,av6=0,av7=0;
for (int i=0;i<6;i++)
{
av1+=st5[i].Getmaths()/6 ;
av2+=st5[i].Getenglish()/6;
av3+=st5[i].Getphysics()/6;
av4+=st5[i].Getvc()/6;
av5+=st5[i].Getftenet()/6;
av6+=st5[i].Getsports()/6;
av7+=st5[i].Getpolitics()/6;
}
cout<<"数学的平均分为"<<av1<<endl;
cout<<"英语的平均分为"<<av2<<endl;
cout<<"物理的平均分为"<<av3<<endl;
cout<<"vc++的平均分为"<<av4<<endl;
cout<<"组成原理的平均分为"<<av5<<endl;
cout<<"体育的平均分为"<<av6<<endl;
cout<<"政治的平均分为"<<av7<<endl;
outfile5<<"数学的平均分为"<<av1<<endl;
outfile5<<"英语的平均分为"<<av2<<endl;
outfile5<<"物理的平均分为"<<av3<<endl;
outfile5<<"vc++的平均分为"<<av4<<endl;
outfile5<<"组成原理的平均分为"<<av5<<endl;
outfile5<<"体育的平均分为"<<av6<<endl;
outfile5<<"政治的平均分为"<<av7<<endl;
outfile5.close();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?