学生成绩的程序

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

写一个统计学生成绩的程序。分别用子函数求出:(1)输入n个学生m门功课的成绩(2)每个学生的平均分;(3)每门功课的平均分;(4)找出最高分所对应的学生和功课。

要求:(1)由四个单独的子函数完成上述功能

(2)用动态存储分配思想完成数组的定义

代码:

#include

#include

#include

using namespace std;

struct Course {

string c_name;

int c_number;

float m_score;

Course(){}

Course(string name, int number, float score) {

if(name != " " && number > 0)

{

c_name = name; c_number = number; m_score = score;

}

else

cout << "Error!!!" << endl;

}

}*p_course;

struct Student {

string m_name;

int m_number;

Course * p_course;

Student(){}

Student(string name, int number, Course *course) {

if(name != " " && number > 0)

{

m_name = name; m_number = number; p_course=course;

}

else

cout << "Error!!!" << endl;

}

}*p_student;

int stu_n, cou_m;

void printStudentInformation()

{

int n,m,i,j;

cout << "Please input the number of student£º" << endl;

cin >> n;

cout << "Please input the course of student: " << endl;

cin >> m;

Student *p_stu = new Student[n];

Course *p_cou = new Course[m];

for( i=0; i

p_stu[i].p_course = new Course[m];

cout << "Please input number and name of every student£º" << endl;

for( i=0; i

cin >> p_stu[i].m_number >> p_stu[i].m_name;

cout << "Please input number and name of every course£º" << endl;

for( i=0; i

cin >> p_cou[i].c_number >> p_cou[i].c_name;

cout << "Please input course garde of student: " << endl;

cout << endl;

cout <<"*********************************************************" << endl;

for( i=0; i

cout << " " << p_cou[i].c_name;

cout << endl;

for( i=0 ;i

{

cout << p_stu[i].m_name << " ";

for( j=0; j

cin >> p_stu[i].p_course[j].m_score;

}

cout << endl;

cout <<"*********************************************************" << endl;

p_student = p_stu;

p_course = p_cou;

stu_n = n;

cou_m = m;

}

void getStudentAverage()

{

int i,j;

float *p_average=new float[stu_n];

float sum=0;

for( i=0; i

{

for( j=0; j

{

sum+=p_student[i].p_course[j].m_score;

}

p_average[i] = sum/cou_m;

sum=0;

}

cout << fixed;

cout.precision(1);

cout <<"*********************************************************" << endl;

cout << endl;

cout << "Name " << "Number " << "AverageGrade " << endl;

cout << setiosflags(ios::left);

for( i = 0; i < stu_n ; i++)

cout<< setw(15) << p_student[i].m_name << setw(10) << p_student[i].m_number << setw(12) << p_average[i] << endl;

cout << endl;

cout <<"*********************************************************" << endl;

cout << endl;

}

void getCourseaver()

{

int i,j;

float *p_couAver= new float[cou_m];

float sum = 0;

for( i=0; i

{

for(j=0; j

sum += p_student[j].p_course[i].m_score;

p_couAver[i] = sum/stu_n;

sum = 0;

}

cout << "The average grade of course: " << endl;

相关文档
最新文档