0% found this document useful (0 votes)
85 views4 pages

ECE 115.2 - Oop For Ece (Lab)

The document contains a 12 question exam on C++ programming concepts like loops, conditional statements, functions, and analyzing code snippets. Students are instructed to answer honestly and that cheating will not be tolerated. The questions cover topics ranging from simple math expressions to more complex logic problems analyzing code execution and output.

Uploaded by

Steve Clar
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)
85 views4 pages

ECE 115.2 - Oop For Ece (Lab)

The document contains a 12 question exam on C++ programming concepts like loops, conditional statements, functions, and analyzing code snippets. Students are instructed to answer honestly and that cheating will not be tolerated. The questions cover topics ranging from simple math expressions to more complex logic problems analyzing code execution and output.

Uploaded by

Steve Clar
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/ 4

ECE 115.

2 – OOP for ECE (LAB)


2nd Semester A.Y. 2019-2020 (Exam 1)

ID#: ________________ Course & Yr: ____________________ Score:

Read the questions/instructions carefully and write your answers on your answer sheets. Answer with
all your honesty, any form of cheating will not be tolerated and will be dealt with accordingly.

1. What would be the value of variable c and variable a after the user inputs a value 1?*
#include <iostream>
using namespace std;

int main()
{
int z, r, a,e;
double pi = 3.1416, c=2.7182;
cin>>r;
a = pi * (r * r);
c = r * a*a;
}
2. Write the equivalent C++ expression of the following mathematical equation? Assume the
values of R and h are either a positive whole number or a floating point number.*

(3𝑅 − ℎ)
𝑉 = 𝜋ℎ2 (4)
(3 − 2)
3. In the following code snippet, how many times will the string “hello” be displayed?*
int n = 1;

while (n <= 1)
{
for(int i =0; i <= n; ++i)
{
cout<<"hello";
}
n++;
}

4. What is the output after the execution of this code fragment below?*
int a=5, b=5, c=6;

a = (3 % (b * c) < (c / 3) < 7) - (3 % b * c > b / 4 >= 2);

switch(a)
{
case 0:
{cout<<"I'm the one."; break;}
case 1:
cout<<"I'm the correct answer. \n ";
case 2:
cout<<"No you're mistaken about me. \n "<<a;
default:
cout<<” But seriously I’m the correct answer! ”<<endl;
}
5. . Given the following code fragment below, how many asterisks will be displayed?**
int i,j,k;

for(i = 0; i < 3; i++){


for(j = 0; j < i; j++){
for(k = 0; k < j; k++){

cout<<"**********\n";
}
}
}

6. In the following program, the line numbers have been enabled. How many times is red, blue,
green and orange line of the program being executed?***

#include <iostream>
using namespace std;
int main()
{
int a = 12;
do
{
if(a == 15) {
a = a + 1;}
else if (a <17){
a = a + 1;}
else {
cout<<"value of a: %d\n"<< a;
continue;}

a++;
} while( a < 20 );
return 0;

7. Which of the given choices is logically equivalent to the following English statement:*

If the age is not more than 25 and the gender is male, increase the insurance rate by two folds.

a) if((age<25) && (gender=='M')) c) if((age<=25) && (gender=='M'))


insurance_rate = insurance_rate*2; insurance_rate = insurance_rate*2;

b) if((age<25) && (gender='M')) d) if(age<=25) && (gender=='M')


insurance_rate = insurance_rate*2; insurance_rate = insurance_rate*2;
8. Write a program that is logically equivalent to the following English statement: **
If the value of x is equal to 25, the value of timeLeft is increased by 30. Furthermore, the increase
also occurs only if the value of timeLeft will not exceed the value of maxTime.

9. In the following program, the line numbers have been enabled. How many times is line 11 of
the program being executed?**

#include <iostream>
Using namespace std;

int main()
{
int a = 12;

do
{ if(a == 18) {
8: a = a + 1;
}
else {
11: cout<<"value of \n";
}
a++;

13: } while( a < 20 );

Refer to the same program in Question #8. How many times is line 13 of the program being
executed?

10. Write a c++ program that will ask the user to enter an alphabet to check whether it is a vowel
or not, then display the result on the screen.***

11. Write a c++ program that will ask user to enter the two number to find the greatest or largest of
the two number, then display the result on the screen.***

12. Write a c++ program that will ask user to enter the year to check whether it is a leap year or
not, then display it on the screen.***

f
f
e
r
f
r
e
f

You might also like