⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 this a good book.
💻 CPP
字号:
#include<fstream.h>
#include<assert.h>
#define N 10

class Student
{ 
  public:
	char name[20];
	double marks[5];
	double total;
};

class Test
{
  protected:
	 //  ** 1 **
	 
  public:
	 void Input();
	 void Total();
	 void Average();
};

void Test::Input()
{  
	ifstream in("records.txt");
	assert(in);
	for( int i=0; i<N; i++){ 
		in>>stu[i].name ;
		for(int j=0; j<5; j++)
			in>>stu[i].marks[j];
	}
}

void Test::Total()
{  
	double total=0;
    for(int i=0; i<N; i++) {  
		total=0;
		for(int j=0; j<5; j++)
           //** 2 **
		
	}
    ofstream out("mark.txt");
	assert(out);
    out<<"姓名\t总分\n";
    cout<<"姓名\t总分\n";
    for( i=0; i<N; i++)	
{
		out<<stu[i].name<<"\t"<<stu[i].total<<endl ;
cout<<stu[i].name<<"\t"<<stu[i].total<<endl ;
     }
}

void Test::Average()
{  
	double sum=0;;
	for(int i=0; i<5; i++) {
		sum=0;
		for(int j=0; j<N; j++) 
			sum+=stu[j].marks[i];
		average[i]=sum/N;
	}
	ofstream out("average.txt");
	assert(out);
	out<<"科目编号\t平均分"<<endl;
cout<<"科目编号\t平均分"<<endl;
    for(i=0; i<5; i++)	 
     {
		out<<i+1<<"\t"<<average[i]<<endl; 
cout<<i+1<<"\t"<<average[i]<<endl; 
}
}

int main()
{   
	Test test;
	//** 3 **
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -