Simulate a referee to score the contestant

Source: Internet
Author: User

// Function: Enable the referee to score <br/> // Description: The program requirements are as follows: <br/>/************************ <br/> simulate a referee to score the contestant. <Br/> 1. requirements: <br/> (1) the number of referees is umpire. <br/> (2) the contestants are anyone. <br/> (3) the referees score the contestants; <br/> (4) Remove the highest score and the lowest score. The average score is the score of the contestant. <br/> the lowest score is displayed based on the contestant's serial number; <br/> the score is displayed by ranking (sorted by insertion ). <Br/> 2. tip: <br/> (1) define a score classification with the class name "result" as a contestant score. Data members include at least contestant numbers (in integer form) and names (in character arrays), the referee scores and scores for the contestants (using a real array), and so on. The member function is customized (must have a constructor), and the class definition is saved in "result. h "; <br/> (2) the test program (stored in exp_206.cpp) adopts the interactive mode: <br/> ① enter the contestant count; <br/> ② prompt to enter the numbers and names of all contestants; <br/> ③ show the start of the competition. Score the contestants. <br/> ④ display: the highest score, lowest score, And contestant score are removed. <br/> 5. The score of the contestant is displayed by number at the end of the competition. <br/> 6. The score is displayed by rank. <Br/> ************************************ **/<br/> # include <iostream> <br/> # include <string> <br/> # include <algorithm> <br/> using namespace STD; <br/> const int umpire = 5; <br/> class result {<br/> Public: <br/> result (int n, char * P) // No, name <br/> {<br/> If (strlen (p) <= 0) <br/> cout <"error" <Endl; <br/> num = N; <br/> strcpy (name, P); <br/> score = 0; <br/> memset (judgescore, 0, Umpire ); <br/>}< br/> result () <br />{< Br/> num = 0; <br/> name [0] = '/0'; <br/> score = 0; <br/> memset (judgescore, 0, Umpire); <br/>}< br/> result (const Result & RHs) <br/>{< br/> num = RHS. num; <br/> strcpy (name, RHS. name); <br/> score = RHS. score; <br/> memcpy (judgescore, RHS. judgescore, Umpire); <br/>}< br/> void initresult (int n, char * P) <br/>{< br/> If (strlen (P) <= 0) <br/> cout <"error" <Endl; <br/> num = N; <br/> strcpy (name, P ); </P> <p> score = 0; <br/> Memset (judgescore, 0, Umpire); <br/>}< br/> void setjudgescore (int * s) <br/>{< br/> int IX = 0; <br/> while (IX <umpire) <br/>{< br/> judgescore [ix] = s [ix]; <br/> IX ++; <br/>}</P> <p> int * getjudgescore () <br/>{< br/> return judgescore; <br/>}< br/> int getscore () <br/>{< br/> return score; <br/>}< br/> int getnumber () <br/>{< br/> return num; <br/>}< br/> void showname () <br/>{< br/> cout <name; <br/>}< br/> Int findhighpos (); <br/> int findlesspos (); <br/> int findhweigh () <br/>{< br/> return judgescore [findhighpos ()]; <br/>}< br/> int findless () <br/> {<br/> return judgescore [findlesspos ()]; <br/>}< br/> void docalculatorscore (); </P> <p> friend ostream & operator <(ostream & out, result); <br/> ~ Result () {}< br/> PRIVATE: <br/> int num; // contestant id <br/> char name [10]; // name <br/> int judgescore [Umpire]; // score the referee <br/> int score; // score </P> <p> }; <br/> ostream & operator <(ostream & out, result RHs) <br/>{< br/> // due to older versions of vc6, private Data members cannot be directly accessed <br/> // out <RHS. num <"/t" <RHS. name <br/> // <"/t" <RHS. score <Endl; <br/> // here, the access member function is used to access private members. <br/> out <RHS. getnumber () <"/t"; <br/> RHS. showname (); <br/> O Ut <"/t" <RHS. getscore () <Endl; <br/> return out; <br/>}< br/> int result: findhighpos () <br/>{< br/> int * Pmax = max_element (judgescore, (judgescore + umpire); <br/> return Pmax-judgescore; <br/>}< br/> int result: findlesspos () <br/>{< br/> int * pmin = min_element (judgescore, (judgescore + umpire )); <br/> return pmin-judgescore; <br/>}< br/> void result: docalculatorscore () <br/>{< br/> int maxpos = findhighpo S (); <br/> int minpos = findlesspos (); <br/> cout <"maxpos:" <maxpos <Endl; <br/> cout <"minpos:" <minpos <Endl; <br/> for (INT I = 0; I <umpire; I ++) <br/>{< br/> If (I! = Maxpos) & (I! = Minpos) <br/>{< br/> score + = judgescore [I]; <br/>}< br/> cout <"total score =" <score <Endl; </P> <p> If (findhweigh () = findless () <br/> score = score/(umpire); <br/> else <br/> score = score/(Umpire-2 ); </P> <p >}< br/> bool lessbyscore (Result & L, Result & R) <br/>{< br/> If (L. getscore () <R. getscore () <br/> return true; <br/> else <br/> return false; <br/>}< br/> bool lessbynumber (Result & L, result & R) <br/> {<B R/> If (L. getnumber () <R. getnumber () <br/> return true; <br/> else <br/> return false; <br/>}< br/> int Init (result * & P); <br/> void sortbyplayernumber (); <br/> void sortbyplayerscore (); <br/> int Init (result * & P) <br/>{< br/> cout <"Number of contestants:" <Endl; <br/> int N; <br/> CIN> N; <br/> cout <Endl; </P> <p> If (! (P = new result [N]) <br/>{< br/> cout <"error" <Endl; <br/> exit (1 ); <br/>}< br/> result * PMV = P; </P> <p> int number; <br/> char name [10]; <br/> for (INT I = 0; I <n; I ++, PMV ++) <br/>{< br/> cout <"Enter the numbers and names of all contestants:" <Endl; <br/> CIN> number> name; <br/> PMV-> initresult (number, name ); </P> <p> cout <"starts to score" <I + 1 <"scores of contestants" <Endl; <br/> int tmpix = 0; <br/> int pjudgescore [Umpire]; <br/> while (tmpix <umpire) <br/> {<br/> cout <"Enter the" <(tmpix + 1) <"score of each REFEREE :"; <br/> CIN> pjudgescore [tmpix ++]; </P> <p >}< br/> cout <"end-to-end" <n <"score of contestant" <Endl; <br/> PMV-> setjudgescore (pjudgescore); <br/> PMV-> docalculatorscore (); <br/> cout <"the highest score is: "<PMV-> findhigh () <"/T: "<br/> <PMV-> findless () <"/T:" <PMV-> getscore () <Endl; <br/> tmpix = 0; <br/>}< br/> return N; <br/>}< br/> void sortbyplayernumber (result * P, int N) <br/>{< br/> sort (p, p + N, lessbynumber); <br/>}< br/> void sortbyplayerscore (result * P, int N) <br/>{< br/> sort (p, p + N, lessbyscore); <br/>}< br/> int main () <br/>{< br/> result * r; <br/> int n = Init (R ); </P> <p> cout <"The result is as follows:" <Endl; <br/> sortbyplayernumber (R, N ); <br/> for (INT I = 0; I <n; I ++) <br/>{< br/> cout <R [I]; <br/>}< br/> cout <Endl; <br/> cout <"The result is as follows:" <Endl; <br/> sortbyplayerscore (R, n); <br/> for (INT I = 0; I <n; I ++) <br/>{< br/> cout <R [I]; <br/>}</P> <p> return 0; <br/>} 

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.