Week 13 - Exercises
Week 13 - Exercises
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:
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)