ECE 115.2 - Oop For Ece (Lab)
ECE 115.2 - Oop For Ece (Lab)
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;
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;
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.
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++;
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