Final Exam Practice
Final Exam Practice
1. Which of the following Symbol Denotes the direction of logic flow in the program:
A.
B.
C.
D.
2. C++ is one of the following type of language.
A. Middle-level language
B. High-level Language
C. Low-level language
D. None of the above
3. One of the following is used for inserting a new line in C++ Program.
A. \n
B. <<endl;
C. /n
D. Both A and B
4. Which one of the following would be used to print the value of a variable named Result?
A. cout << Result << endl;
B. cin >> "Result" >> endl;
C. cin >> Result >> endl;
D. cout << "Result" << endl;
5. Which one of the following correctly declares an array holding 10 integers in C++?
A. int array{10};
B. array array[10];
C. int array;
D. int array[10];
6. In C++ the (double) data type occupies the following memory size:
A. 1 byte
B. 2 byte
C. Byte
D. 8 Bytes
7. What is the memory size of Boolean data type in C++?
A. 1 byte
B. 2 byte
C. Byte
D. 4 Bytes
8. In C++ the signs +, -, *, /, % are known as:
A. Integers
B. arithmetic operators
C. variables
D. constants
9. What is the output of the shown code segment?
A. 33 int x = 2;
B. 42 float y=3.0;
C. 41 x++;
D. 31 --y;
cout<<x++<<--y;
10.if int x[4]={1,2,3,4}, the value of x [1] is equal
A. 1
B. 2
C. 4
D. 3
11. what will be the result of the following code segment:
#include <iostream>
using namespace std;
int main() {
int a[]={1,2,3,4};
cout <<"a"<< endl;
return 0;
}
A. 1234
B. 1
C. 2
D. a
12.How many lines of output, will this code produce? for(int i=2; i<=7;i++)
A. 2 lines {
B. 3 lines cout<<i<<endl;
C. 4 lines i++;
D. 5 lines }
13.A variable can store multiple values of the same type.
A. Functions
B. Keywords
C. Array
D. None of these
14.In C++, what is the result of the expression 10 - (5+4*2) / 4 - 2 =
A. 3
B. 4
C. 5
D. 6
15. What will be the output of the following code segment:
#include <iostream>
using namespace std;
int main() {
int a;
a = 10 + 2 * 5;
cout << a;
return 0;
}
A. 18
B. 20
C. 15
D. 19
1) What will the following code fragment print?
int a = 8 , b = 6 ,c = 2 ,A;
Output
a = ++a - c;
11
b = --b + c;
A=b + ++a /2;
cout <<A;
a = 3, b = 2, and c = 5
a.
((b--) * (--c) + b - ++a) > = 7
b. 9
a * (++c) / b <=2
int A[5] = { 1, 2, 3 };
int K = 0;
A. K = A[0] - A[2] + A[4] * 10; -2
cout << K;
int n = 9;
n++;
if (n < 9 )
B. cout << "This is final Exam!"; This is Final Exam
else
cout << “This is Final Exam!";
int b = 1;
int c=2;
do 21
C. { 31
cout << c << b <<endl;
++c; 41
} while (c<=4);
int x,y;
for (int i=0; i < 5; i++ )
{ 0
if(i==3)
{
1
D.
continue; 2
} 4
cout<<i<<endl;
}
1) Find errors in the following program and rewrite the corrected one.
#include <iostream>
int mein() using namespace std;
{ int main()
{
int sum = 0, avg = 0;
int b[5] = {9;3,11,7,1 }; int num [10] = {9,3,11,7,1} ;
sum = 0; for (int i = 0; i < 5; i++ )
for(int i=0 ; X<5 ; i++); {
sum = sum + num [i];
sum=sum +b[i];
}
cout<<"Sum is" << sum <<endl; cout << "Sum is: " << sum;
cout<<"Average is"<<Avg/5.0; avg = sum / 10 ;
cout << "\n Average is: " <<
} avg;
}
1) Write an algorithm and draw a flowchart to determine whether student is pass or Not.
Steps:
GRADE =
(M1+M2+M3+M4+M5+M6)/6
else
Print “Fail”
Endif
Stop
1) Write a C++ program to calculate sum of 5 numbers 12, 13, 14, 15, 16 using one-
dimensional array.
OR
2) Write C++ Program to print numbers from 1 to 6 and then stop counting at 4 using break
statement and for loop.
OR
3) Write C++ program to check whether a number is even or odd using if else statements.
OR
4) Write C++ program to display Numbers from 1 to 10 and skip number 3 using continue
and While loop.
OR
5) Write a C++ Program to Find Square root of Any Number: By using an inbuilt Library
Function.
OR
6) Write a C++ Program to find the value of Pi (π).
Question number:1)
#include <iostream>
using namespace std;
int main()
{
int numbers[5],
sum = 0;
cout << "Enter 5 numbers: ";
for (int i = 0; i < 5; ++i)
{
cin >> numbers[i];
sum += numbers[i];
}
cout << "Sum = " << sum << endl;
return 0;
}
Output
Enter 5 numbers: 12 13 14 15 16
Sum = 70
Question number:2)
#include <iostream>
using namespace std;
int main()
{
for (int i = 1; i <= 6; i++)
{
if (i == 5)
{
break;
}
cout << i << endl;
}
return 0;
}
Output
1
2
3
4
Question number:3)
#include <iostream>
using namespace std;
int main()
{
int a;
cout << "Enter the number: ";
cin >> a;
if (a % 2 == 0)
{
cout << "The given number is EVEN" << endl;
}
else
{
cout << "The given number is ODD" << endl;
}
return 0;
}
Output
Enter the number: 3
The given number is ODD
Question number:4)
#include <iostream>
using namespace std;
int main()
{
cout << "Displaying Numbers from 1 to 10 (Excluding 3):"<<endl;
for (int i = 1; i <= 10; ++i)
{
if (i == 3)
{
continue;
}
cout << i << " ";
}
return 0;
}
Output
Displaying Numbers from 1 to 10 (Excluding 3):
124567891
Question number:5)
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double number, squareroot;
cout<<"Enter A Number:";
cin>> number;
squareroot = sqrt(number);
cout<< "Squareroot of " <<number<<"="<<squareroot;
return 0;
}
Out Put
Enter A Number:40
Squareroot of 40=6.32456
Question number:6)
#include <iostream>
#include <cmath>
void printValueOfPi()
{
double pi = 2 * acos(0.0);
printf("%f\n", pi);
}
int main()
{
printValueOfPi();
return 0;
}
Out Put
3.141593