Weekly project 2-score processing, weekly project 2-
/** Copyright (c) 2014, School of Computer Science, Yantai University * All rights reserved. * file name: test. cpp * Author: Liu Chang * Completion Date: July 15, November 21, 2014 * version number: v1.0 ** Problem description: The score of a group's C ++ program design will be stored in the array score .; * Description: Number of Students and scores. * program output: output the maximum score, minimum score, average score, number of people with the highest and low scores of the group, and standard deviation of their student IDs and scores of all students.
# Include <iostream> # include <cmath> using namespace std; int main () {int score [50]; int num, I, n1 = 0, n2 = 0, max, min, sum = 0; double total = 0, S; cout <"How many students are there in the group? "; Cin> num; cout <" Enter the Student Score: "<endl; for (I = 0; I <num; ++ I) {cout <"Enter the number" <I <"score:"; cin> score [I]; if (score [I]> 100 | score [I] <0) {I-= 1; continue;} sum + = score [I] ;}cout <endl; for (I = 1, max = score [0]; I <num; ++ I) {if (score [I]> max) {max = score [I];} elsecontinue;} for (I = 1, min = score [0]; I <num; ++ I) {if (score [I] <min) {min = score [I];} elsecontinue;} for (I = 0; I <num; ++ I) {if (score [I] = max) n1 ++; if (score [I] = min) n2 ++;} sum = sum/num; cout <"top score: "<max <", minimum score: "<min <", average score: "<sum <endl; cout <"highest score" <max <"Total" <n1 <", whose student ID is:"; for (I = 0; I <num; ++ I) {if (score [I] = max) cout <I <";}cout <endl; cout <"lowest score" <min <"Total" <n2 <", whose student ID is:"; for (I = 0; I <num; ++ I) {if (score [I] = min) cout <I <";}cout <endl; for (I = 0; I <num; ++ I) {total + = (score [I]-sum) * (score [I]-sum);} S = total/(num-1 ); S = sqrt (S); cout <"standard deviation:" <S; return 0 ;}
Learning Experience:
It is slow but the process is clearer. Unfortunately, the program is not concise enough. I feel like I can optimize it, but I don't know where to start...