+1(978)310-4246 credencewriters@gmail.com
  

Description

Write a program that generates a random number in the range of 0 ~ 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.”. If the user’s guess is lower than the random number, the program should display “Too low, try again.” When the user correctly guesses the random number, the program should display the number of guesses. The program should use a loop that repeats until the user correctly guesses the random number.

other requirements

make each task separately

make a flowchart for each task.

CSCI 201 Computer Science I
Spring 2021
1
Project 3 Random Number Guessing Game and Student Test Scores
Objectives
To provide students with the experience of
• writing C++ programs with selections and loops
• using files to deal with input and output
Problems
Task 1
Write a program that generates a random number in the range of 0 ~ 100 and asks the user to guess
what the number is. If the user’s guess is higher than the random number, the program should
display “Too high, try again.”. If the user’s guess is lower than the random number, the program
should display “Too low, try again.” When the user correctly guesses the random number, the
program should display the number of guesses. The program should use a loop that repeats until
the user correctly guesses the random number.
An Example of Test Runs
csci2>a.out
Let’s start this game. Please guess a number between 0 ~ 100.
your guess? 40
Too high, try again. your guess? 30
Too high, try again. your guess? 20
Too low, try again. your guess? 25
Too high, try again. your guess? 23
Too low, try again. your guess? 24
You got it! The answer is 24.
The number of times you tried is 6.
Thanks for playing this game.
Other requirements
• Insert comments in the program so that it can be read easily.
Task 2
Write a program that prompts the user to enter a list of test scores into a file. Use Ctrl+d to stop
input. Once all the scores have been read in, the program displays a message to indicate the end
of output.
Input Validation: Don’t accept a score less than 0 or greater than 100.
Input
• filename to store student scores
• test scores
Output
• a simple message.
CSCI 201 Computer Science I
Spring 2021
2
Hint:
1) An example to use Ctrl+d to stop input:
// Read a number from the keyboard and displays it to the
// screen until user’s input is ctrl+d
while (cin >> number)
{
cout a.out
What is the filename to store the students’ scores?
studentScores.dat
Enter the scores for students. To stop, use Ctrl+d.
Enter a score: 89
Enter a score: 101
Invalid score. A score must be between 0 to 100.
Enter a core: 100
Enter a score: 54
Enter a score: 98
Enter a score: 74
Enter a score: -10
Invalid score. A score must be between 0 to 100.
Enter a score: 64
Enter a score: Ctrl+d
A list of student scores have been saved into the file
“studentScores.dat”. Please open the file to check it.
Other requirements
• Insert comments in the program so that it can be read easily.
CSCI 201 Computer Science I
Spring 2021
3
Task 3
Write another program that displays all test scores in the file created in task2 and their average.
You must check the opening error before you process the data in the file.
An Example of Test Run
csci2>a.out
Input the file name: scores.dat
The file cannot be opened. Check the filename and run the
program again. Bye!
csci2>a.out
Input the file name: studentScores.dat
The test scores in the file are
89 100 54 98 74 64
The average is 79.83.
Other requirements
• Insert comments in the program so that it can be read easily.

Purchase answer to see full
attachment

error: Content is protected !!