#include
#include
#include
using namespace std;
struct student {
int no;
string name;
int s_m;
int s_cn;
int s_en;
int sum;
float avg;
}stu[5];
int main()
{ int i;
cout<<"打开文件f3.txt"<
if(!out){cout<<"open output file error"<
{ cin>>stu[i].no>>stu[i].name>>
stu[i].s_m>>stu[i].s_cn>>stu[i].s_en;
out<
cout<<"写入文件"<
cout<<"读取文件"<
if(!in){cout<<"open input file error"<
{ in>>stu[i].no>>stu[i].name>>
stu[i].s_m>>stu[i].s_cn>>stu[i].s_en;
if(!in){cout<<"read file error"<
stu[i].avg=stu[i].sum/3;
cout<
in.close();
}
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"从键盘输入5个学生的学号、姓名,以及数学、语文和英语成绩\n";
int StudentNum[5];
char** name=new char*[5];
double math[5],chinese[5],english[5],totalmarks[5],averagemarks[5];
for (int i=0;i<5;i++)
{
name[i]=new char[10];
totalmarks[i]=0;
}
for (int i=0;i<5;i++)
{
cout< cin>>StudentNum[i]>>name[i]>>math[i]>>chinese[i]>>english[i];
}
ofstream outfile("f3.txt");
outfile<<"学号 姓名 数学 语文 英语\n";
for (int i=0;i<5;i++)
{
outfile<
outfile.close();
ifstream infile("f3.txt");
char numStr[10],nameStrp[10],mathStr[10],chineseStr[10],englishStr[10];
infile>>numStr>>nameStrp>>mathStr>>chineseStr>>englishStr;
for (int i=0;i<5;i++)
{
infile>>StudentNum[i]>>name[i]>>math[i]>>chinese[i]>>english[i];
totalmarks[i]+=math[i]+chinese[i]+english[i];
averagemarks[i]=totalmarks[i]/3;
}
cout<<"学号 姓名 数学 语文 英语 总成绩 平均分\n";
for (int i=0;i<5;i++)
{
cout<
return 0;
}
#include
#include
#include
using namespace std;
struct student {
int no;
string name;
int s_m;
int s_cn;
int s_en;
int sum;
float avg;
}stu[5];
int main()
{ int i;
cout<<"打开文件f3.txt"<
if(!out){cout<<"open output file error"<
{ cin>>stu[i].no>>stu[i].name>>
stu[i].s_m>>stu[i].s_cn>>stu[i].s_en;
out<
cout<<"写入文件"<
cout<<"读取文件"<
if(!in){cout<<"open input file error"<
{ in>>stu[i].no>>stu[i].name>>
stu[i].s_m>>stu[i].s_cn>>stu[i].s_en;
if(!in){cout<<"read file error"<
stu[i].avg=stu[i].sum/3;
cout<