Weekly project 3-score processing function version, weekly project 3-Function

Source: Internet
Author: User

Weekly project 3-score processing function version, weekly project 3-Function

/** Copyright (c) 2014, School of Computer Science, Yantai University * All rights reserved. * file name: test. cpp * Author: Liu Chang * Completion Date: July 15, November 23, 2014 * version No.: v1.0 ** Problem description: The score of a group's C ++ program will be stored in the array score. (Completed using functions); * input Description: Number of students and student 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; void input_score (int s [], int n ); // input the scores of n students in the group into the array Sint get_max_score (int s [], int n ); // returns the maximum score int get_min_score (int S [], int n) of n students in array s ); // returns the lowest score of n students in array s, double get_avg_score (int s [], int n ); // returns the average score of n students in array s, double get_stdev_score (int s [], int n ); // return the standard offset int count (int x, int s [], int n) of n students in array s ); // returns the number of people in the n-member array in the array s to score x (when the real parameter provides the highest or lower value, the highest or lower score can be obtained. (Number of students) void output_index (int x, int s [], int n); // outputs the student ID (subscript) of the n students in the array s in the function) int main (void) {int score [50]; int num; int max_score, min_score; cout <"How many students are there in the group? "; Cin> num; cout <endl <" Enter the Student score: "<endl; input_score (score, num); max_score = get_max_score (score, num ); cout <endl <"Maximum score:" <max_score <", total" <count (max_score, score, num) <. "; min_score = get_min_score (score, num); cout <endl <" minimum score: "<min_score <", total "<count (min_score, score, num) <"person. "; cout <endl <" average score: "<get_avg_score (score, num); cout <endl <" standard deviation: "<get_stdev_score (score, num); cout <endl <" students with the highest scores (student ID): "; output_index (max_score, score, num ); cout <endl <"students with the lowest scores (student ID):"; output_index (min_score, score, num); cout <endl; return 0 ;}

Void input_score (int s [], int n) {int I = 0; while (I <n) {cout <"Enter the number" <I <"name score:"; cin> s [I]; if (s [I]> 100 | s [I] <0) continue; I ++ ;}} int get_max_score (int s [], int n) {int I, max; for (I = 1, max = s [0]; I <n; ++ I) if (s [I]> max) max = s [I]; return max;} int get_min_score (int s [], int n) {int I, min; for (I = 1, min = s [0]; I <n; I ++) if (s [I] <min) min = s [I]; return min;} double get_avg_score (int s [], int n) {int I; double sum = 0, avg; for (I = 0; I <n; ++ I) sum + = s [I]; avg = sum/n; return avg ;} double get_stdev_score (int s [], int n) {int I; double stdev, total = 0, S; stdev = get_avg_score (s, n); for (I = 0; I <n; ++ I) total + = (s [I]-stdev) * (s [I]-stdev); total/= (n-1 ); S = sqrt (total); return S;} int count (int x, int s [], int n) {int I, iCount = 0; for (I = 0; I <n; ++ I) {if (s [I] = x) iCount ++;} return iCount;} void output_index (int x, int s [], int n) {int I; for (I = 0; I <n; ++ I) {if (s [I] = x) cout <I <"";} return ;}






 

Learning Experience:

This is not difficult to do because I have made an ordinary version before. Even though the standard deviation between the two is different, I did not go into details if it is caused by different data types. Sorry. In the previous article, several predecessors gave me a lot of suggestions, and I am working hard to improve them. I hope this article will also provide guidance and suggestions on how to improve my performance.

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.