-
Notifications
You must be signed in to change notification settings - Fork 0
/
hiscorestuff.h
58 lines (48 loc) · 2.65 KB
/
hiscorestuff.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* Created: April 14, 2007
Due: April 24, 2007
Last Modified: April 14, 2007 by Jennifer
What was changed: Created.
*/
#ifndef _FUNCTION_PROTOTYPES_
#define _FUNCTION_PROTOTYPES_
using namespace std;
//////////////////////////////////////////////////////////////////////////////
//HISCORESTUFF.CPP
/*Purpose: This function checks to see if the user has earned a high score.
If the user has earned a high score, then that score replaces the
lowest high score, and the scores are sorted so that they are in order
from highest to lowest. The names and scores are then stored in files.
Data Abstraction: ***********
Input: Names and scores are read from the overall high score file. If the
user has received a high score, he or she inputs his name. If not, he
or she presses enter as a dummy character.
Process/Implementation: If the binary scores file does not exist, the file
is created with 10 dummy scores. Names are read from the binary file
into a HiScore array. If the user's score is lower than the lowest
high score, his or her name and score replaces the lowest high score.
The array is then sorted by score using the sortScores function.
Output: If the file does not exist, "Player" with a score of 0 is written
into the file 10 times. If the user has earned a high score, a
congratulatory message is displayed, and the user is prompted to enter
his or her name. After the HiScore array is sorted, the names and scores
are re-written into the original high score file (in binary form to
prevent the file from being easily changed). If the user has not earned
a high score, "Sorry," is printed, and the user is told to press enter
to continue.
Assumptions: The file contains the correct information. Also, the user
inputs a valid character string for his or her name. */
void checkForHiScores (int score);
/*This sorts the Hiscore array by score.
Data Abstraction: 1 Hiscore struct to temporarily hold the contents of
another Hiscore struct.
Input: Function is passed a Hiscore array and the size of the array.
Process/Implementation: A bubble sort is used through nested for loops.
If the score of the Hiscore struct in one element is greater than the
score of the Hiscore struct in the other, the Hiscore structs switch
places in the array. This continues until all elements have been
sorted.
Assumptions: The correct data types are passed. */
void sortScores (HiScore array[], int size);
void newHighScoreFile();
void highScoreScreen();
#endif // _FUNCTION_PROTOTYPES_