Weekly project 2-score processing, weekly project 2-

Source: Internet
Author: User

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...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.