Question
Q1) Write a program in a file called sleeping.cpp that reads a 4-digit time (HHMM, 24-hour time), and prints out Awake if the time is
Q1) Write a program in a file called sleeping.cpp that reads a 4-digit time (HHMM, 24-hour time), and prints out "Awake" if the time is between 0600 and 2300 (inclusive), and "Asleep" otherwise. (2 marks)
Example of running your program:
Time: 0330
Asleep
Time: 1650
Awake
Time: 2301
Asleep
Q2) Use the while statement to print out the multiplication table of a number that is given by the user (i.e., cin). For example if the number entered by the user is 2, then the output will look like: (4 marks)
2 x 1 = 2
2 x 2 = 4
2 x 10 = 20
Q3) Design a game Guess my number!. The player has three attempts to guess a hidden random number following the instructions: (4 marks)
Prompt a welcoming message, and explain that the player has three attempts to guess that number
Prompt a message to guess the hidden number that ranges between two values, for example, 1 and 10
If the entered number is higher than the correct number then prompt a message such as You are too high, and if the entered number is lower than the correct number then prompt a message like You are too low. If the correct number is entered then prompt a message Congratulations, you won!!. If the player was unsuccessful to guess the number then prompt a message you Lose
The player might be able to guess the number in the first or second trial, therefore, the program should stop after guessing the number although not all three trials were used. To achieve this goal use either:
Nested IF conditions to check both number of trials and if the user won or not
In case you are using the WHILE statement, you need the BREAK statement to exit the WHILE loop if the correct number is guessed. For example, you can write inside the WHILE loop:
if (entered_number == hidden_number) {break}
Use the following function to generate a hidden random number (num) between 1 and 10 :
srand (time(NULL));
num = rand()% 10 + 1;
Have fun!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started