/*
* Copyright and version Declaration of the program:
* Copyright (c) 2012, computer College, Yantai University
* All rights reserved.
* File name: student achievement statistics. cpp
* Author: Mao Tong
* Completion date: January 1, December 11, 2012
* Version No.: v1.0
* Description of tasks and solutions: Requirements
(1) define a two-dimensional array to store each student's course score
(2) calculate the average score of students in each course (each column), save and Output
(3) calculate the average score (per line) of each course for each student, save and Output
The score is as follows:
Course 1 course 2 course 3
Student 1 89 78 56
Student 2 88 99 100
Student 3 72 80 61
Student 4 60 70 75
* Input Description: None
* Problem description:
* Program output: ""
* Problem Analysis: omitted
* Algorithm Design: omitted
*/
[Cpp]
# Include <iostream>
# Include <iomanip>
Using namespace std;
Int main ()
{
// Define a two-dimensional array to store each student's course score
Double a [5] [4] =
{
{89, 78, 56 },
{88, 99,100 },
{72, 80, 61 },
{60, 70, 75 },
};
Int val, flag; // val row flag Column
// Calculate the sum of each column based on the average value of each column and divide it by 4
Double sum_1 [3];
For (int I = 0; I <3; I ++)
{
Sum_1 [I] = 0;
}
For (flag = 0; flag <3; flag ++)
For (val = 0; val <4; val ++)
Sum_1 [flag] = sum_1 [flag] + a [val] [flag];
For (flag = 0; flag <3; flag ++)
A [4] [flag] = sum_1 [flag]/4;
// Average score (per row) of each course for each student, save and output:
Double sum_2 [4];
For (I = 0; I <4; I ++)
{
Sum_2 [I] = 0;
}
For (val = 0; val <4; val ++)
For (flag = 0; flag <3; flag ++)
Sum_2 [val] = sum_2 [val] + a [val] [flag];
For (val = 0; val <4; val ++)
A [val] [3] = sum_2 [val]/3;
// Output the orders table
Cout <"tables Table" <"";
For (I = 1; I <= 3; ++ I)
Cout <"Course" <I <"\ t ";
Cout <"average score ";
Cout <endl;
I = 1;
Cout <"Student 1" <"\ t" <"";
For (val = 0; val <4; val ++)
{
For (flag = 0; flag <4; flag ++)
{
Cout <setprecision (4) <a [val] [flag] <"\ t ";
}
I = I + 1;
If (I = 5)
Break;
Cout <endl <"student" <I <"\ t" <"";
// Continue
}
Cout <endl;
Cout <"average score" <"\ t" <"";
For (flag = 0; flag <4; flag ++)
{Www.2cto.com
Cout <setprecision (4) <a [4] [flag] <"\ t ";
}
Cout <endl;
Return 0;
}
/*
Experience:
Knowledge Point summary:
*/