0% found this document useful (0 votes)
2 views

Week 13 - Exercises

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Week 13 - Exercises

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Full Name _______________________________________________

Student’s ID _____________________________________________

Week 13 - Exercises

Exercise 1: (2 points)

Write a C++ program that reads the current temperature (in degrees Celsius) from
the user. If the temperature is below 0°C, the program should print "It's freezing!".
If the temperature is 0°C or higher, the program should print "It's not freezing.".

Exercise 2: (2 points)

Write a C++ program that reads a student's score (integer value) from the user and
prints the corresponding grade based on the following rules:

 If the score is 90 or above, print "A".


 If the score is 80 or above but less than 90, print "B".
 If the score is 70 or above but less than 80, print "C".
 If the score is 60 or above but less than 70, print "D".
 Otherwise, print "F".

Exercise 3: (2 points)

Write a C++ program that generates a random number between 1 and 100. The
program should repeatedly ask the user to guess the number (each time the user
needs to enter a number between 1 and 100). If the user's guess is too high, print
"Too high, try again." If the guess is too low, print "Too low, try again." The loop
should continue until the user guesses the correct number, and the program will
then print "Congratulations, you guessed the number!".

Exercise 4: (2 points)

Write a C++ program that simulates a simple password validation system. The
program should ask the user to enter a password. If the password is incorrect, the
program should ask for it again. The loop should continue until the correct
password is entered. The correct password is "Cplusplus". After the user enters the
correct password, the program should print "Access granted."
Exercise 5: (2 points)
Write a C++ program that calculates and prints the sum of all even numbers
between 1 and a positive integer number (namely N) entered by the user. The
program should ask the user for the value of N, and then it will use a for loop to
calculate the sum of all even numbers in the range from 1 to N.

P/S: Please submit the Answer Sheet in Word format with file name is your full
name and student ID (e.g. Tran Van An – 12345678)

You might also like