The pairing program I was with the classmate Wang Xin classmate Group, the topic is to design a golden point game, originally looked at the teacher suggested interface and server design, want to use Java to write, but we are not too familiar with Java, busy for two days no results, simply use my two people common language C language to achieve, So I decided to use C language to achieve this game.

The rules of the game that require design are: There are n students (n usually greater than ten), each person writes a rational number between 0~100 ( excluding 0 or), to the referee, the referee calculates the average of all the numbers, Then multiplythe 0.618 (the so-called Golden Partition constant) and get the G value. The number of the submitted nearest to G(absolute value) of the students get n points, the farthest from the G students get-2 points, the other students get 0 points

First, design ideas:

I decided to use two one-dimensional array to save the game input number (number[]) and each classmate's score (student[]), first we think the game's people need to enter the number of games (n) and the number of games (j).

The number of each player input is then credited to the number[] array with a For loop implementation and the sum is assigned to a, as shown in:

for (i=1; i<=n;i++) {printf (" Please enter the number of the person%d:", I); scanf (" %d", &number[i-1+ = number[i-1];}

The next step is to find the G-value of the game, because these numbers are already calculated as a, so the G value can be used printf ("G Value:%.3f \ n", b=a/n*0.618); This statement prints out the G value and assigns the G value to B (exactly 3 digits after the decimal point).

After doing this, we begin to determine how to find the nearest and farthest distance from the G value, and our idea is to use the Fabs () method to figure out the absolute value of the difference between the number of each player's input and the G value, and to assign the minimum and maximum absolute values to max and Min respectively. We first assign Max and min A value of 0 and 100 and then use the for loop to implement the assignment, such as:

if (Fabs (Number[i]-b) <min) {min=fabs (number[i]-b);}} for (i=0; i<n;i++) {if(fabs (number[i]-b) >max) {max=fabs (number[i]-b);}

Because these players will have some players input the same data, so the distance from the nearest G value and the farthest value will have the same player. Then we find the number of players and G values in a For loop is the same as Max and Min (the player with Max is the player at the farthest distance from the G value, Min is nearest) and the corresponding score is credited to the player's corresponding fractional array student[], such as:

for (i=0; i<n;i++) {if(fabs (number[i]-b) = =min) {if(fabs (number[i]-b) = =max) { student[i]=student[i]+N;} Student[i]2;}

}

Next, we will print out the results of each person through a for loop. The whole again through a For loop implementation game can continue J round. After the game has run the J-wheel, find the highest score Maxscore by A for loop and print out which player wins, such as:

for (i=0; i<n;i++) {if(student[i]>maxscore) {Maxscore=student[i];}} printf (" Game Over! The results are as follows: \ n");p rintf (" Congratulations to%d students for winning! \ n"

Finally, a while loop is added to the overall implementation of whether the game continues.

Second, error analysis:

Through the above design we write the code and then start testing the program, then found a lot of problems.

1, the game player's score and G value error occurred.

Solution: Through our research, we found that the values of a (the sum of the players ' inputs and the maximum absolute value of the difference to g) min (the most absolute value of the G difference) are not reset in each round of games, Cause the next game to start when these three values are continued on the basis of the previous round, resulting in the final calculation of the game player score and G value when an error occurs. So the two of us reset these necessary values at the end of each round of the game. The result is normal when running again.

2, the game completed once after the input Y again game when the last to find the winner error.

Solution: Because of the previous error experience we think this is the same problem, re-collation of the code after the same problem is found, that is, after the end of each game is not the highest score Maxscore reset, after the modified program perfect run no more errors.

Third, the operation:

Start entering data as follows:

The first game end result graph is as follows:

After the game is over, continue with the game as follows:

Iv. Summary:

For programming we all have above his business problem, because we all started to learn Java, just started to use Java to implement the program, although the main function is finished the basic function is also implemented, but for the interface and server A little foundation, and he was learning the eclipse and I am learning Android Studio is not quite the same, obviously not proficient for a few days feel some difficulty, we return to the C language, first realize all the basic functions. Through this experiment found that many of their own things will not, to supplement their knowledge as soon as possible, because some students have been far ahead. In the course of two weeks we often do a research process, respectively, put forward their own ideas, understanding of their different ideas, improve the friendship between classmates, and there is a difference of experience, feel learned a lot of things. Thank you very much for being able to arrange such an experiment.

I'm the two of us. Photos when discussing code:

V. SOURCE program code:

#include <stdio.h>#include<math.h>voidMain () {inti,n,j,k;Chars='Y';intA=0;intMaxscore;intstudent[ -];intnumber[ -];Doubleb=0;DoubleMin = -, max =0; while(s=='Y') {Maxscore=- +;p rintf ("Please enter the number of games:"); scanf ("%d",&N);p rintf ("Please enter the number of game boards:"); scanf ("%d",&j); for(i=0; i<n;i++)//assigning a score array to a value of 0{Student[i]=0;} for(k=0; k<j;k++)//number of board cycles{ for(i=1; i<=n;i++)//Enter the number of each classmate and sum it up{printf ("Please enter the number of person%d:", i); scanf ("%d", &number[i-1]); a+ = number[i-1];} printf ("the G value is:%.3f \ n", b=a/n*0.618);//Output g value for(i=0; i<n;i++) {if(Fabs (number[i]-b) <min)//subtract the G value by each number and take the absolute value to find the maximum absolute value max and Min min{min=fabs (number[i]-b);}} for(i=0; i<n;i++){if(Fabs (Number[i]-b) >max) {Max=fabs (number[i]-b);}} for(i=0; i<n;i++)//find the farthest and most recent number from the G-point with Max and Min, and revise the results of your classmates{if(Fabs (number[i]-b) = =min) {if(Fabs (number[i]-b) = =max) {Student[i]=student[i]+N;} Student[i]-=2;}} A=0;//end of each round to reset some necessary valuesb=0; Max=0; min= -;p rintf ("*******************************\n"); for(i=0; i<n;i++)//print out each student's score{printf ("* The score for%d students is%d\n", i+1, Student[i]);} printf ("*******************************\n");} for(i=0; i<n;i++)//find the highest score{if(student[i]>Maxscore) {Maxscore=student[i];}} printf ("Game Over! The results are as follows: \ n");p rintf ("Congratulations to%d of the students win! \ n", Maxscore);//Output Game Resultsprintf"____________________________________________________________________\n");p rintf ("do you want to continue the game? y/n\n");//game over to determine whether to continue the gamescanf"%s",&s);}}

Pair Programming Gold Dot Game