Secj 1013 Lab Exercise 2
Secj 1013 Lab Exercise 2
LAB EXERCISE 2
Name: __________________________________
Matric Number: ___________________________
(1) Based on the given declaration, evaluate the following expression either it is TRUE or
FALSE.
a) !flag
b) (num >= y_double) && (num >= x_double)
c) (found || flag)
d) (x_int == y_int)
e) ‘N’ < = ch && ch <= ‘Z’
a)
int n=8;
if (!n>9)
cout << “Yes”;
else
cout << “No”;
b)
int main()
{
for(int i=3; i>=1; i--){
string output(i, '+');
cout << output << "\n";
}
c)
int main() {
int x1 = 2, x2 = 5, m = 13;
bool b1, b2, b3=true;
b1 = x1 == x2; // false
b2 = x1 < x2; // true
cout << "b1 = " << b1 << " and b2 =
" << b2 << "\n";
if (b3 == true) cout << "Yes" <<
"\n";
else cout << "No" << "\n";
int x3 = false + 3 * m - b3;
cout << x3;
return 0;}
d) for ( int i = 10, j = 13 ; i * j >= 130 ; i++, j-- ) { cout << "i
* j = " << (i * j) <<”\t”; }
(3) Write an if statement that displays the message “Valid number. Proceed to next input”, if
the variable value is within the range of 20 to 50.
(4) Write and if …. else statement that display “PASS!”, if the marks variable is greater than
50, if not, display, “FAIL!”
(6) Elaborate the difference between while, for and do … while statement?
(7) Convert the following for loop statement to while and do … while statement
int total = 0;
for (int count = 0; count <= 30; count++)
{
total += count;
}
(8) Write a program with nested loop to display the following output: