Review Exercise Chapter 2 and 3
Review Exercise Chapter 2 and 3
Review Exercise Chapter 2 and 3
1|Page
b. Operators
i. Determine the value, true or false, of each of the following Boolean
expressions, assuming that the value of the variable count is 0, x is 5, y
is 8 and limit is 10. Give your answer as one of the values true or false.
1. (count == 0) && (limit < 20)
2. count == 0 && limit < 20
3. (limit > 20) || (count < 5)
4. !(count == 12)
5. (count == 1) && (x < y)
6. (count < 10) || (x < y)
7. !( ((count < 10) || (x < y)) && (count >= 0) )
8. ((limit/count) > 7) || (limit < 20)
9. (limit < 20) || ((limit/count) > 7)
10. ((limit/count) > 7) && (limit < 0)
11. (limit < 0) && ((limit/count) > 7)
12. (5 && 7) + (!6)
2|Page
b. Displaying output
i. What is the output of the following program lines when embedded in a
correct program that declares number to be of type int?
number = (1/3) * 3;
cout << "(1/3) * 3 is equal to " << number;
ii. What output would be produced by the following two lines (when
embedded in a complete and correct program)?
//cout << "Hello from";
cout << "Self-Test Exercise";
iii. Write the output of the following C++ program
int m = 10, n=5;
n = ++m;
cout << "m = " << m << ", n = " << n << endl;
n = m++;
cout << "m = " << m << ", n = " << n << endl;
cout << "m = " << m++ << endl;
cout << "m = " << m << endl;
cout << "m = " << ++m << endl;
c. Identifying error
i. Basic Syntax
#include<iostream>
using namespace std;
void main(){ /* This is the main function
cout<<'C++ Programming questions and answers';
}
------------
#include<iostream>
using namespace std;
void main(){ // This is the main function
integer a;
float b;
}
-------------
#include<iostream>
using namespace std;
int main(){ // This is another C++ program with some errors
a,b,s int;
d float;
cout<<"The end of the program";
return 0;
}
3|Page
ii. Accept two number and calculate the five arithmetic operation
int sum,sub,mult,div,module;
int a,b;
cout<<"Enter value of a ="
cin<<a;
cout<<"Enter value of b =;
cin<<b;
sum=a+b;
sub=a-bmult=a*b;
div=a/'b';
module=a%b;
4|Page