1. Which of the following C++ variable names are incorrect? Give the reasons. a) X1 b) 1X c) _X1 d) _1X 2. Write the equivalent C++ statement for the following Math formula: [(b-lnK/c)+L]e^(L) 3. Write the equivalent C++ statement for the following Math formula: -(2/3)x^(4)y^(2)(-9xy+12x^(3)y^(2)0 4. Assume that num1=2, num2=5 and num3=25. What is the output of the following statement? num3 = num3 % (num1 * num2); a) 0 b) 5 c) 10 d) There will be no output due to a run-time error. 5. Assuming that the user inputs an integer value of 25 for the price and an integer value of 10 for the discount rate in the following code snippet, what is the output? cout << price - price * (discount / 100); a) 25 b) 15 c) 22.5 d) 20.0 6. Which of the following options is valid with reference to the code snippet? double d = 45.326; double r = d % 9.0; cout << r; a) The value inside the variable r will be 0.326 b) The value inside the variable r will be 5.036 c) Variable r has to be defined as an integer as the % operator always returns an integer d) The assignment statement for variable r is wrong, as the % operator expects integer values as operands 2 7. What is the output of the following code snippet? int value = 25; value--; value = value * 2; cout << value << endl; a) 50 b) 49 c) 48 d) No output due to syntax error 8. Assuming that the user provides 100 as input, what is the output of the following code snippet? int a, b; a = 0; cout << "Please enter b: "; cin >> b; if (b >= 100); { a = b; } cout << "a= " << a << endl; a) a= 0 b) a= 99 c) a= 100 d) There is no output due to compilation errors. 9. Assuming that the user provides 300 as input, what is the output of the following code snippet? int x; int y; x = 0; cout << "Please enter y: "; cin >> y; if (y > 303) { x = y; } else { x = 0; } cout << "x= " << x << endl; a) x= 0 b) x= 300 c) x= 303 d) There is no output due to compilation errors. 3 10. What is the output of the following code snippet? int main() { int num = 100; if (num != 100) { cout << "100" << endl; } else { cout << "Not 100" << endl; } return 0; } a) There is no output due to compilation errors. b) 100 c) Not 100 d) 100 11. Which of the following code snippets would you use to test for equality of variables a and b? a) if (a = b) { ...... } b) if (a == b) { ...... } c) if (a != b) { ...... } d) if (a ! b) { ...... } 12. Assuming that a user enters 64 as his marks obtained, what is the output of the following code snippet? int main() { int score = 0; cout << "Enter your score: "; cin >> score; if (score < 40) { cout << "F" << endl; } else if (score < 50) { cout << "D" << endl; } else if (score < 60) { cout << "C" << endl; } else if (score < 70) { cout << "B" << endl; } else if (score < 80) { cout << "B+" << endl; } else { cout << "A" << endl; } return 0; } a) D b) C c) B d) A 4 13. How many times will the following loop run? int i = 0; while (i < 9) { cout << i << endl; i++; } a) 0 b) 8 c) 9 d) 10 14. What is the output of the code snippet given below? int i = 0; while (i != 9) { cout << i << " "; i = i + 2; } a) No output b) 0 2 4 6 8 c) 10 12 14 16 18 …. (infinite loop) d) 0 2 4 6 8 10 12 14 …. (infinite loop) 15. How many times is the text "Let us C" printed if the code snippet given below is run? int i = 0; do { cout << "Let us C" << endl; i++; if (i % 2 == 0) { i = 11; } }while (i <= 10); a) 1 b) 2 c) 10 d) 11 5
1. Which of the following C++ variable names are incorrect? Give the reasons.
a) X1
b) 1X
c) _X1
d) _1X
2. Write the equivalent C++ statement for the following Math formula: [(b-lnK/c)+L]e^(L)
3. Write the equivalent C++ statement for the following Math formula: -(2/3)x^(4)y^(2)(-9xy+12x^(3)y^(2)0
4. Assume that num1=2, num2=5 and num3=25. What is the output of the following statement?
num3 = num3 % (num1 * num2);
a) 0
b) 5
c) 10
d) There will be no output due to a run-time error.
5. Assuming that the user inputs an integer value of 25 for the price and an integer value of 10 for the
discount rate in the following code snippet, what is the output?
cout << price - price * (discount / 100);
a) 25
b) 15
c) 22.5
d) 20.0
6. Which of the following options is valid with reference to the code snippet?
double d = 45.326;
double r = d % 9.0;
cout << r;
a) The value inside the variable r will be 0.326
b) The value inside the variable r will be 5.036
c) Variable r has to be defined as an integer as the % operator always returns an integer
d) The assignment statement for variable r is wrong, as the % operator expects integer values as
operands
2
7. What is the output of the following code snippet?
int value = 25;
value--;
value = value * 2;
cout << value << endl;
a) 50
b) 49
c) 48
d) No output due to syntax error
8. Assuming that the user provides 100 as input, what is the output of the following code snippet?
int a, b;
a = 0;
cout << "Please enter b: ";
cin >> b;
if (b >= 100);
{
a = b;
}
cout << "a= " << a << endl;
a) a= 0
b) a= 99
c) a= 100
d) There is no output due to compilation errors.
9. Assuming that the user provides 300 as input, what is the output of the following code snippet?
int x;
int y;
x = 0;
cout << "Please enter y: ";
cin >> y;
if (y > 303)
{
x = y;
}
else
{
x = 0;
}
cout << "x= " << x << endl;
a) x= 0
b) x= 300
c) x= 303
d) There is no output due to compilation errors.
3
10. What is the output of the following code snippet?
int main()
{
int num = 100;
if (num != 100)
{
cout << "100" << endl;
}
else
{
cout << "Not 100" << endl;
}
return 0;
}
a) There is no output due to compilation errors.
b) 100
c) Not 100
d) 100
11. Which of the following code snippets would you use to test for equality of variables a and b?
a) if (a = b) { ...... }
b) if (a == b) { ...... }
c) if (a != b) { ...... }
d) if (a ! b) { ...... }
12. Assuming that a user enters 64 as his marks obtained, what is the output of the following code
snippet?
int main()
{
int score = 0;
cout << "Enter your score: ";
cin >> score;
if (score < 40) { cout << "F" << endl; }
else if (score < 50) { cout << "D" << endl; }
else if (score < 60) { cout << "C" << endl; }
else if (score < 70) { cout << "B" << endl; }
else if (score < 80) { cout << "B+" << endl; }
else { cout << "A" << endl; }
return 0;
}
a) D
b) C
c) B
d) A
4
13. How many times will the following loop run?
int i = 0;
while (i < 9)
{
cout << i << endl;
i++;
}
a) 0
b) 8
c) 9
d) 10
14. What is the output of the code snippet given below?
int i = 0;
while (i != 9)
{
cout << i << " ";
i = i + 2;
}
a) No output
b) 0 2 4 6 8
c) 10 12 14 16 18 …. (infinite loop)
d) 0 2 4 6 8 10 12 14 …. (infinite loop)
15. How many times is the text "Let us C" printed if the code snippet given below is run?
int i = 0;
do
{
cout << "Let us C" << endl;
i++;
if (i % 2 == 0)
{
i = 11;
}
}while (i <= 10);
a) 1
b) 2
c) 10
d) 11
5
Part-B
1. Write notes on break statement in C++ and how it differs from the continue statement? (2
Points)
2. Write a C++ program to find the area of a shape whose area is given by the formula Area =
2+4r + πr
6
(3 Points)
Trending now
This is a popular solution!
Step by step
Solved in 10 steps