[go: up one dir, main page]

0% found this document useful (0 votes)
162 views3 pages

Secj 1013 Lab Exercise 2

The document contains a lab exercise with questions on C++ programming concepts like loops, conditional statements, and basic operations. It asks the student to evaluate expressions, write code for different loops and conditional statements, and explain differences between loops. The questions cover basic but important concepts like loops, conditional statements, and logical/relational operators.

Uploaded by

khalid loda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
162 views3 pages

Secj 1013 Lab Exercise 2

The document contains a lab exercise with questions on C++ programming concepts like loops, conditional statements, and basic operations. It asks the student to evaluate expressions, write code for different loops and conditional statements, and explain differences between loops. The questions cover basic but important concepts like loops, conditional statements, and logical/relational operators.

Uploaded by

khalid loda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

SECJ 1013 PROGRAMMING TECHNIQUE 1

LAB EXERCISE 2

Name: __________________________________
Matric Number: ___________________________

(1) Based on the given declaration, evaluate the following expression either it is TRUE or
FALSE.

bool found = true;


bool flag = false;
char ch = ‘R’;
double x_double = 22.0;
double y_double = 200.0;
double num = 15.3;
int x_int = 22;
int y_int = 200;

a) !flag
b) (num >= y_double) && (num >= x_double)
c) (found || flag)
d) (x_int == y_int)
e) ‘N’ < = ch && ch <= ‘Z’

(2) What is the output of the following intermediate C++ codes?

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";
}

for (int i=1; i<=3; i++){


string output(i, '+');
cout << output << "\n";
}
return 0;
}

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!”

(5) Based on Question 4, write if … else … if statement if we have five conditions to be


checked as below:
- marks greater than or equal 80, display A
- marks greater than or equal 60, display B
- marks greater than or equal 40, display C
- other than that, 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:

You might also like