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

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 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
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.
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.
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
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.