121213 Seventh Chapter Exercise 5.cpp: Defines the entry point for a console application.
* * Copyright (c) 2012, Computer College of Yantai University * All rights reserved. * Author: Liu Tongbin * Completion date: December 13, 2012 * Version Number: v1.0 * * Input Description: There are 10 students, each student's data including number, name, 3 course results. Input 10 student data from the keyboard, request to print out 3 course total average grade, as well as the highest score student's data (including study number, name, 3 course grade, average score) * Problem Description: * Program output: * Problem analysis: slightly * algorithm design: Slightly * * * #include
"StdAfx.h" #include <iostream> #include <string> using namespace std;
const int n=6;
struct student//definition struct variable {string name;
int num;
Double score[3];
Double average;
}student1[n];
int main () {int i,j;
for (i=0;i<n;i++) {cout<< "Please enter the" <<i+1<< "Student's information:"; Cin>>student1[i].num >>student1[i].name >>student1[i].score[0]>>student1[i].score[1]>
>student1[i].score[2];
Double sum=0;
Average score for each student for (i=0;i<n;i++) {for (j=0;j<3;j++) {sum=sum+student1[i].score[j];
} STUDENT1[I].AVERAGE=SUM/3;
sum=0; //Print out each studentInformation cout<< "Output information for each student:" <<endl; for (i=0;i<n;i++) {cout<<student1[i].num<< "<<student1[i].name<<" << student1[i].score[0]<< "" <<student1[i].score[1]<< "" <<student1[i].score[2]<< ""
; <student1[i].average <<endl;
//Find the student with the highest score and output its information double max=student1[0].average;
int row=0;
for (i=0;i<n;i++) {if (max<student1[i].average) {max=student1[i].average;
} row=i;
cout<< "Highest score of student data:" <<endl; cout<<student1[row].num<< "" <<student1[row].name<< "" <<student1[row].score[0]<& lt; ""
<<student1[row].score[1]<< "" <<student1[row].score[2]<< "" <<student1[row].average
<<endl;
The average score of each section average1[3];//defines an array of sum=0 for the average score of 3 courses;
for (j=0;j<3;j++) {for (i=0;i<n;i++) {sum=sum+student1[i].score[j];
} average1[j]=sum/n;
sum=0; } cout<<endl;
for (i=0;i<3;i++)//output average score of each course {cout<< "<<i+1<<" The average score of the course: "<<endl;
Cout<<average1[i] <<endl;
return 0;
}