C++Q
C++Q
C++Q
#include <iostream>
using namespace std;
int main()
{
int x, y;
x = 5;
x++ * ++x;
cout <<x << " " <<y;
return 0;
}
Select one:
o 30
o6 0
o7 0
o 36
11. Which of the following access specifies is used in a class definition by default?
Select one:
o Protected
o Friend
o Public
o Private
12. Which of the following statements is correct, when a class is inherited publicly?
Select one:
o Public members of the base class become protected members of derived class.
o Public members of the base class become public members of derived class.
o Private members of the base class become protected members of derived class.
o Public members of the base class become private members of derived class.
13. Which of the following accesses the 7th element stored in array?
Select one:
o array[6];
o array[7];
o array=7;
o array[8];
17. Which of the following is used to display a single character from a specified file on the screen?
[email protected]
Select one:
o putchar
o None of these
o getchar
o cin>>
18. Which of the following operator is used to get value stored at an address that is pointed by a pointer.
Select one:
o &(ampersand)
o .(dot)
o ~(tilde)
o *(asterisk)
24. To increase the value of c by one, which of the following statement should not be used?
Select one or more:
o c--;
o c-=1;
o c=c+1
o c+1 => c;
27. Select the missing code lines from the dropdown provided.
The C++ code given below should find the smallest number out of the five numbers entered by the user.
But, line numbers 7 and 16 are missing.
1. #include<iostream>
2. using namespace std;
3. int main()
4. {
5. int num[5];
6. cout << "Enter five integers\n";
7. ---------------Missing code -------------------
8. {
9. cin >> num[i];
10. }
11. int smallest = num[0];
12. for(int i=1; i<=5; i++)
13. {
14. if(num[i]<smallest)
15. {
16. ---------------Missing code -------------------
17. }
18. }
19. cout << "Smallest number is " << smallest << "\n";
20. return 0;
21. }
Line 7
Line 16
28. Select the missing code lines from the dropdown provided.
The C++ code given below should find the area of circle. Radius of the circle is entered by user.
But, line numbers 7 and 10 are missing.
1 #include <iostream>
2 using namespace std;
3 int main()
4 {
5 int r;
6 float pi = 3.14;
7 ---------------Missing code -------------------
8 cout <<"Enter the radius of the circle\n";
9 cin >>r;
10 ---------------Missing code -------------------
11 cout <<"Area of the circle is " <<area << "\n";
12 return 0;
13 }
Line 7
Line 11
29. Select the missing code lines from the dropdown provided.
The C++ code given below should find sum of two numbers entered by user.
But, line numbers 3 and 10 are missing.
1 #include <iostream>
2 using namespace std;
3 ---------------Missing code -------------------
4 {
5 int c = a + b;
6 cout<<"Sum of a and b is "<<c<<"\n";
7 }
8 int main()
9 {
10 ---------------Missing code -------------------
11 sum = add(5,4);
12 return 0;
13 }
Line 3 - Answer
Line 10 - Answer
30. What will be the output of the following program? Write the answer in digits not alphabet.
#include<iostream>
using namespace std;
void MyFunction(int a, int b = 40)
{
Answer:
32. Which is the condition where no more data can be read from a data source?
Select one:
o switch condition
o for condition
o EOF(end of file)
o if condition
35. Which of the following two entities (reading from left to right) can be connected by the dot operator?
Select one:
o A class and a member of that class.
o A class member and a class object.
o A class object and a class.
o A class object and a member of that class.
37. What will be the output of the following program? Write the answer in digits not alphabet.
#include<iostream>
using namespace std;
long FactFinder(long = 5);
int main()
{
for(int i = 0; i<= 0; i++)
cout<< FactFinder() << endl;
return 0;
}
long FactFinder(long x)
{
if(x < 2)
return 1;
long fact = 1;
for(long i = 1; i <= x-1; i++)
fact = fact * i;
return fact;
}
Answer:
{
double a = 21.09399;
float b = 10.20;
int c ,d;
c = (int) a;
d = (int) b;
cout << c <<" " << d;
return 0;
}
Select one:
o Compilation error
o 21.09399 10.20
o 21 10
o 0
Select one:
o None of these
o 5010
o 4990
o 6533
42. Which of the following functions is used to read data from the console?
Select one:
o scanf();
o main()
o cout <<
o cin>>;
44. Which format specifier will be used to provide precision of 4 digits after decimal point?
Select one:
o %.4f
o .%4f
o %f4
o %4f
45. The region of code within which a variable can be accessed is known as _______________.
Select one:
o Arguments
o Scope of variable
o Functions
o Token
46. Which of the following is used to display a single character from a specified file on the screen?
[email protected]
Select one:
o getchar
o None of these
o cin>>
o putchar
47. Which format specifier will be used to provide precision of 4 digits after decimal point?
Select one:
o %4f
o %f4
o .%4f
o %.4f
48. Which format specifier will be used to provide precision of 4 digits after decimal point?
Select one:
o %4f
o %f4
o .%4f
o %.4f
4 int c = a + b;
5 cout<<"Sum of a and b is "<<c<<"\n";
6 }
7 int main()
8 {
9 int sum;
10 sum = add(5);
11 return 0;
12 }
Select one:
Line number 5
o No error
o Line number 1
o Line number 2
o Line number 10
52. Based on the below definition statements, which of the following is/are not correct options?
int x;
float f;
int *pi;
float *pf;
Select one or more:
pi=x;
pi=*x;
x=a;
pi=&x;
54. Select the missing code lines from the dropdown provided.
The C++ code given below should find the cube of a number entered by the user.
But, line numbers 2 and 8 are missing.
1. #include<iostream>
2. ---------------Missing code -------------------
3. int main()
4. {
5. int num;
6. cout << "Enter an integers\n";
7. cin >> num;
8. ---------------Missing code -------------------
9. cout << "Cube of " << num << " is "<< cube << "\n";
10. return 0;
11. }
o Line 2
o Line 8
55. Select the missing code lines from the dropdown provided.
The C++ code given below has class that should give dimensions and volume of the Box.
But, line numbers 20 and 26 are missing.
#include<iostream>
using namespace std;
class Box
{
public:
double length;
double breadth;
double height;
void dimension(double l, double b, double h)
{
length = l;
breadth = b;
height = h;
cout << "Length is " << length << "\n";
cout << "Breadth is " << breadth << "\n";
cout << "height is " << height << "\n";
}
double volume()
{
---------------Missing code -------------------
}
};
int main()
{
Box b;
---------------Missing code -------------------
cout << "Volume is "<< b.volume() << "\n";
return 0;
}
o Line 20
o Line 26
56. Select the missing code lines from the dropdown provided.
The C++ code given below should find the sum of the ten numbers entered by the user.
1. #include<iostream>
2. using namespace std;
3. int main()
4. {
5. int num[10];
6. cout << "Enter ten integers\n";
7. for(int i=0; i<10; i++)
8. {
9. ---------------Missing code -------------------
10. }
11. int sum=0;
12. ---------------Missing code -------------------
13. {
14. sum = sum + num[i];
15. }
16. cout << "Sum is " << sum << "\n";
17. return 0;
18. }
o Line 9
o Line 12
57. What will be the output of the following program? Write the answer in digits not alphabet.
#include<iostream>
using namespace std;
int main(){
int i;
for(i=0;i<=5;i++);
cout<<i;
return 0;
}
Answer:
58. What will be the output of the following program? Write the answer in digits not alphabet.
#include<iostream>
using namespace std;
class Base
{
public:
int S, A, M;
Base(int x, int y)
{
S = y - y;
A = x + x;
M = x * x;
}
Base(int, int y = 'A', int z = 'B')
{
S = y;
A = y + 1 - 1;
M = z - 1;
}
void Display(void)
{
cout<< S << " " << A << " " << M << endl;
}
};
class Derived : public Base
{
int x, y, z;
public:
Derived (int xx = 65, int yy = 66, int zz = 67): Base(x)
{
x = xx;
y = yy;
z = zz;
}
void Display(int n)
{
if(n)
Base::Display ();
else
cout<< x << " " << y << " " << z << endl;
}
};
int main()
{
Derived objDev;
objDev.Display (-1);
Return 0;
}
Answer: