Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Programming Assignment 3: Golf Tournament Statistics

COP 3363 - Spring Term 2022

Learning Objectives

o     To utilize looping structures for the first time in a C++ program

o     To develop more sophisticated control structures using a combination of

selection and looping

o     To read data from an input file

o     To calculate some basic statistics given a set of data

Problem Statement

The Seminole-9 Tournament Golf Course has nine holes. At each hole, a player is expected    to be able to sink the ball in the hole in 1 to 5 shots. The course expected average or "par" is 30. A player's score for the course is the sum of the numbers of shots for each hole.                  Depending on his or her past performance, a player is granted a "handicap" which is               subtracted from his or her score to give the actual result for a game. Players are very              interested in knowing whether they have scored under par or not. When players play             together, the winner is the one with the lowest score.

Your task is to write a program which will read in data, from a file, for multiple players in a tournament and find the highest, lowest, average score and standard deviation using the      handicapped results. You must also show for each player his/her total score, the                      handicapped result score, and whether or not he/she was over or under par for the course. In addition, print out the player number of the winner, and the number of players counted  in the results.

You may only have ONE return(0) statement and NO exit(0) statements in your code.  You may only use break statements inside a switch statement in the manner demonstrated in class; you      may not use break statements inside loops.

The primary control structure that is new in this project is the loop.  You will use loop(s) to         repeat sections of code such as input of the file data. We will study looping in detail both during class lectures and recitations.

Provided Input Files Containing Test Data

You may test your program using the data files golfdataSML.txt and golfdata.txt, provided on the course UNIX space. Note that the grader may test your program using additional data files.

How to obtain the test datafiles: The sample files are provided to you on UNIX.  Use the UNIX cp command to copy these files and put them in the correct UNIX directory where you have        saved your program files on your own CS UNIX account, as shown in lecture.  You may want to test your program using other files that you create yourself.  The grader may use other files in      testing your program.

Note: the data files will be stored on UNIX in your course instructor's directory, which will be permitted for you to read from and hence copy the files.  The files path will be like this:

/home/faculty/aftyson/COP3363ClassFiles/golfdata.txt

It is important that you transfer the text data files to your UNIX account directly using UNIX.      Text files have different line-ending formats on UNIX, Windows and Mac, and the line endings  can sometimes be corrupted with file transfers.  While this won't affect most tasks, it may affect  whether your program can read provided text files correctly or not.  So, get them from the UNIX account directly and transfer them to a UNIX account directly using cp.

Tip: you can use

cp /home/faculty/aftyson/COP3363ClassFiles/golfdata.txt golfdata.txt

to copy into your file space into your current active directory.  You may need to then use the mv command to place the file where you really need it to be able to run your program and read from it using the simple commands shown in lectures.

You may assume that any data files used as input to this program have at least one complete data line (i.e. you may assume the file is not empty) but your program must be able to      process any number of data lines greater than or equal to 1. Each data line will have the  following format:

<integer><blank(s)><integer><blank(s)><9 integers separated by blanks>

The first integer gives the player number, the second gives his or her handicap, and the last 9 integers give the player's score on each of the 9 holes.

You must prompt the user to enter a file name and then open they file they have requested.  File names must not contain any blanks.

Bad Data Checking

To earn full credit for this project, your program must adhere to the following rules for bad data   checking. It is possible that some input lines contain invalid data, which could consist of        either a negative number for the handicap or negative or zero scores. Ifyou read a data line with bad data in it, you must still echoprint the input line, but do not use that data line in calculating any ofthe tournament results. You must also output an error message               indicating that bad data was found. Note: when counting how many players were used in the results, you only count players with completely valid data lines.

In addition, when you prompt the user for an input file name, you must then try to open that  file.  If it does not open, you must re-prompt the user for a file name until they provide a file name which results in a data file opening successfully.

CALCULATING THE MEAN SCORE AND STANDARD DEVIATION OF SCORES

The mean score is the sum of all valid scores divided by the number of all valid scores.      Given that N is the number ofvalues in a data set, and that xi represents the ith value, the mean is given by

 

The standard deviation is specified by the following formula:

 

Note that the mean and the standard deviation must be calculated as real numbers.  Note

also that there is another formula for the standard deviation; in this program you must use   the formula provided above. [Here we are using what is known as the sample variance formula, not the population variance formula, which uses N-1 in the denominator]

In this project we will use the above formula for the standard deviation, however note that we will actually calculate it using what is called the computationalformula. This is an equivalent formula but is easier to program at this early point in the course. The computational formula is as follows:

 

Example of Standard Deviation Calculation

Here is an example of calculating the standard deviation, using the computational formula, for the following set of 20 data values:

64

48

55

68

72

59

57

61

63

60

60

43

67

70

65

55

56

64

61

60

    The sum of all the squared scores is 73894

    The sum of all the scores is 1208

 

    The sum of all the scores, squared, is 1459264

    N is 20

    Hence the standard deviation is the square root of

(73894 - (1459264 / 20)) / 20

which gives a final result of approximately 6.8

Output Contents and Format: Example

Let's say you read the following data for 4 players:

1        6         1 3 6 2 1 4 3 2 4

2        3          2 2 2 2 4 4 4 2 2

3       -1          3 3 4 5 3 4 2 5 2

4        2          4 5 4 3 4 1 3 5 4

Your output could look something like this:

----------------------------------

SEMINOLE-9 GOLF TOURNAMENT RESULTS

----------------------------------

Scores

-----------------

1 3 6 2 1 4 3 2 4

2 2 2 2 4 4 4 2 2

3 3 4 5 3 4 2 5 2

4 5 4 3 4 1 3 5 4

Number of Players Counted in Results: 3

Lowest Score: 20

Highest Score: 31

Average Score: 24.00

Standard Deviation: 4.97

Winning Player Number: 1

Total

-----

26

24

***

33

Result

------

20

21

Under Par?

----------

yes

yes

invalid data  ***

31        no

Note that a neatly formatted output table should be used to echoprint the input as well as to output many of the results found.

What File To Turn In, File Naming Requirements, and Turning In Your Work to Canvas

Turn in your C++ program source file which must be named as follows.  Use this format: yourLastNameLowerCase_FSUID_p3.cpp

Your FSUID will be unique to you, will typically be your FSU email ID, and will be something like "ab23c." Hence file names will look something like "smith_ab23c_p3.cpp"

Submit your single C++ file (.cpp) to Canvas using the Submit button for this assignment.

Be sure to download the file from Canvas also after you submit it in order to verify that    you submitted the correct program file to Canvas and that it was successfully received by Canvas.

Remember that if you do not verify your file submissions properly, it is possible to receive a zero score on any course assignment.