程序我已经弄好了,现在帮忙弄个简单的界面,改一下,使他看起来更舒服点,麻烦了!!!
#include <iostream>
#include <fstream>
using namespace std;
#include <stdlib.h>
struct student
{
int num;
char name[20];
double Chinese;
double math;
double English;
double totel;
double ave;
};
void main()
{
int n,j;
double sum=0;
double ave=0;
struct student stu[5];
struct student stutemp;
cout<<"请输入学生总数:";
cin>>n;
ofstream outfile;
outfile.open("file.dat",ios::binary);
if(! outfile)
{
cout<<"can not open file.dat";
abort();
}
for(int i=0;i<n;i++)
{
cout<<"请输入: 学号,姓名,语文,数学,英语:\n"<<endl;
cin>>stu[i].num>>stu[i].name>>stu[i].Chinese>>stu[i].math>>stu[i].English;
stu[i].totel=stu[i].Chinese+stu[i].math+stu[i].English;
stu[i].ave=stu[i].totel/3;
outfile.write((char*)&stu[i],sizeof(struct student));
}
outfile.close();
ifstream infile;
infile.open("file.dat",ios::binary);
if(! infile)
{
cout<<"can not open file.dat";
abort();
}
cout<<"学生数据如下:\n"<<endl;
for(i=0;i<n;i++)
{
infile.read((char*)&stu[i],sizeof(struct student));
cout<<stu[i].num<<","<<stu[i].name<<","<<stu[i].Chinese<<","<<stu[i].math<<","<<stu[i].English<<endl;
}
cout<<"语文总分 平均分\n";
for(i=0;i<n;i++)
{
sum=sum+stu[i].Chinese;
#include <iostream>
#include <fstream>
using namespace std;
#include <stdlib.h>
struct student
{
int num;
char name[20];
double Chinese;
double math;
double English;
double totel;
double ave;
};
void main()
{
int n,j;
double sum=0;
double ave=0;
struct student stu[5];
struct student stutemp;
cout<<"请输入学生总数:";
cin>>n;
ofstream outfile;
outfile.open("file.dat",ios::binary);
if(! outfile)
{
cout<<"can not open file.dat";
abort();
}
for(int i=0;i<n;i++)
{
cout<<"请输入: 学号,姓名,语文,数学,英语:\n"<<endl;
cin>>stu[i].num>>stu[i].name>>stu[i].Chinese>>stu[i].math>>stu[i].English;
stu[i].totel=stu[i].Chinese+stu[i].math+stu[i].English;
stu[i].ave=stu[i].totel/3;
outfile.write((char*)&stu[i],sizeof(struct student));
}
outfile.close();
ifstream infile;
infile.open("file.dat",ios::binary);
if(! infile)
{
cout<<"can not open file.dat";
abort();
}
cout<<"学生数据如下:\n"<<endl;
for(i=0;i<n;i++)
{
infile.read((char*)&stu[i],sizeof(struct student));
cout<<stu[i].num<<","<<stu[i].name<<","<<stu[i].Chinese<<","<<stu[i].math<<","<<stu[i].English<<endl;
}
cout<<"语文总分 平均分\n";
for(i=0;i<n;i++)
{
sum=sum+stu[i].Chinese;