Professional Documents
Culture Documents
Assignment 2 (Assigned: Monday, October 8, 2018, Due: Monday, October 15, 2018)
Exercises (No programming is required. Your submission should be a word or pdf document.)
Question 1: (2 Marks)
Which of the following are valid statements?
1. char ch1 = 47;
2. char ch2 = '65';
3. int ch3 = 'y';
4. string str1 = "1234";
5. string str2 = "1\t2\t3\t4";
Question 2: (2 Marks)
What is wrong with this code?
int v = false;
if (v == true);
cout << " The variable v is true" << endl;
Question 3: (3 Marks)
Write an if-else statement that outputs to the screen the remainder of x/y, where x and y are two
integer variables. If the denominator (y) is zero, it outputs a string “ERROR”; otherwise it outputs the
remainder of x/y. You assume that x and y are already declared and initialized.
Question 4: (2 Marks)
Given the following C++ instruction:
string str = "Welcome to C";
Using string concatenation, add one instruction that changes the content of str into
"Welcome to C++". That is, after adding this instruction, if your send str to the screen, the output
should be: Welcome to C++
Programming:
Note: Besides a cpp file, your submission should include a screenshot of the execution of the
program using each of the values: mark = 33, 82,120)
1. Program 1: (6 Marks)
Write a C++ program that prompts the user to enter a mark between 0 and 100, and outputs its
equivalent in text.
For example, if the user enters 95, the program should output this text: “Exemplary performance”.
If the user enters 71, the output should be: “Proficient performance”, and so on.
1
The marks should be declared integer.
The mark classes are as follows:
[80 - 100]: “Exemplary performance”.
[70 - 79]: “Proficient performance”.
[60 - 69]: “Adequate performance”.
[50 - 59]: “Limited performance”.
[0 - 49]: ”Week performance”.
If the user enters a mark that is not between 0 and 100, the program outputs the following
text: “This is not a valid mark”
Hint: use nested if-else statement.