Page 275 - Computer_Science_F5
P. 275
Computer Science 1. Identify errors made in the #include <iostream>
Exercise 4.11
Using namespace std;
int main()
following program
{
FOR ONLINE READING ONLY
if (marks > = 60) int input;
cin >> input;
Grade = ‘D’; if (input < 11) {
else if (marks > = 70)
if (input != 6)
Grade = ‘C’;
else if (marks > = 80) cout << “wow “;
else
Grade = ‘B’;
else if (marks > = 90) input++;
}
Grade = ‘A’; else {
else
if (input == 18)
Grade = ‘F’;
input += 11;
2. Use if statement to create a else
C++ program that allows the cout << “Oyaaa!”;
user to enter five numbers. }
Then, the program arranges
the number from the smallest cout << input << ‘\n’;
to the largest number. }
3. Write the program that What will the program print if the user
prompts the user to enter enters the following numbers as inputs?
a month and year. The (a) 4, (b) 20, (c) 6, (d) 18, (e) -6
program should display 5. Write a C++ program that requests six
the number of days of that integer values from the user. The program
month as output. should give the message to the user as
4. Study the following C++ follows: if any of the values entered are
program that prints one line duplicates, the message output should read
of the text, then answer the “DUPLICATE VALUES”; otherwise, it
questions that follows: prints “ALL ARE UNIQUE VALUES”.
(b) Switch case statement
If you have many options in a condition statement, you need more if…else statement
within nested...if statement. Overusing if…else for more options makes a program
very difficult to design. For that case, to reduce lines of codes, C++ programming
266
for Advanced Secondary Schools
Computer Science Form 5.indd 266 23/07/2024 12:34

