InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 51. |
Given the following code fragment:i=2;start:cout<<i;i+=2;if(i<51) goto start;cout<<"\nThank You";Rewrite the above code using a while loop. |
|
Answer» int i=2; while(i<51) { cout<<i; i+=2; } cout<<"\nThank You"; |
|
| 52. |
Name the header files that shall be needed for the following code:void main() {char Text[]="Computer";cout<<setw(15)<<Text;} |
|
Answer» (i) iomanip.h for setw() (ii) iostream.h for cout |
|
| 53. |
Go through C++ code show below, and find out the possible output or outputs from the suggested Output Options(i) to (iv0. Also, write the least value and highest value, which can be assigned to the variable MyNum.#include<iostream.h>#include<stdlib.h>void main() {randomize();int MyNum,Max=5;MyNum=20+random(Max);for(int N=Mynum;N<=25;N++)cout<<C<<"*";}(i) 20*21*22*23*24*25(ii) 22*23*24*25(iii) 23*24* (iv) 21*22*23*24*25 |
|
Answer» (ii) 22*23*24*25 Minimum possible value = 20, Maximum possible value = 24 |
|
| 54. |
Find the syntax error(s), if any, in the following program:(i) #include<iostream.h>main() {int x[5],*y,z[5]for(i=0;i<=5;i++){x[i]=i;z[i]=i+3;y=z;x=y;}}(ii) #include<iostream.h>void main(){int x,y;cin>>x;for(x=0;x<5;++x)cout y else cout<<x<<y;}(iii) #include<iostream.h>void main(){int R;W=90;while W>60{ R=W-50;switch(W){20:cout<<"Lower Range"<<endl;30:cout<<"Middel Range"<<endl;20:cout<<"Higher Range"<<endl;}}}(iv) Rewrite the following program after removing all the syntax error(s), if any#include <iostream.h>void main() {int X[]={60, 50, 30, 40},Y;Count=4;cin>>Y;for(I=Count-1;I>=0,I--)switch(I){ case 0:case 2:cout<<Y*X[I]<<endl;breakcase1:case 3:cout>>Y+X[I];}}(v) Rewrite the following program after removing all the syntax error(s), if any.#include<iostream.h>void main(){int P[]={90, 10, 24, 15},Q;Number=4;Q=9;for(int I=Number-1;I>=0,I--)switch(I){ case 0:case 2:cout>>P[I]*Q<<endl;break;case1:case 3:cout<<P[I]+Q;}} |
|
Answer» (i) Will encounter a following syntax error(s):
(ii) There is a syntax error in cout statement. (iii) Will encounter a following syntax error(s):
(iv) #include<iostream.h> void main(){ int X[]={60, 50, 30, 40},Y,Count=4; cin>>Y; for(int I=Count-1;I>=0;I--) switch(I) { case 0: case 1: case 2:cout<<Y*X[I]<<endl;break; case 3:cout<<Y+X[I];break; } } (v) #include<iostream.h> void main() { int P[]={90, 10, 24, 15},Q,Number=4; Q=9; for(int I=Number-1;I>=0;I--) switch(I) { case 0: case 1: case 2:cout<<P[I]*Q<<endl; break; case 3:cout<<P[I]+Q; break; } } |
|
| 55. |
Given the following code fragment: if(a==0)cout<<"Zero";if(a==1)cout<<"One";if(a==2)cout<<"Two";if(a==3)cout<<"Three";Write an alternative code (using if) that saves on number on compressions. |
|
Answer» #include<iostream.h> void main() { int a; cout<<"enter a:"; cin>>a; if(a==0) cout<<"Zero"; else if(a==1) cout<<"One"; else if(a==2) cout<<"Two"; else if(a==3) cout<<"Three"; else cout<<"other than 0,1,2,3"; |
|
| 56. |
Rewrite the following program after removing all the syntactical error(s), if any. Underline each correction.#include <iostream.h>void main() {Present=25,Past=35;Assign(Present;Past);Assign(Past);} void Assign(int Default1,Default2=30){Default1=Default1+Default2;cout<<Default1>>Default2;} |
|
Answer» #include <iostream.h> void Assign(int Default1,int Default2=30); void main() { clrscr(); int Present=25,Past=35; Assign(Present,Past); Assign(Present); getch(); } void Assign(int Default1,int Default2) { Default1=Default1+Default2; cout<<Default1<<Default2; } |
|
| 57. |
Find the output of the following program:#include<iostream.h>void main() {int A = 5,B = 10;for(int I=1;I<=2;I++){cout<<"Line1"<<A++<<"&"<<B-2<<endl;cout<<"Line2"<<++B<<"&"<<A+3<<endl;}} |
|
Answer» Output: Line 15&8 Line 211&9 Line 1679 Line 212&10 |
|
| 58. |
Rewrite the following program after removing all the syntactical error(s), if any. Underline each correction.#include <iostream.h>void main() {One=10,Two=20;Callme(One;Two);Callme(Two);}void Callme(int Arg1,int Arg2=20){ Arg1=Arg1+Arg2cout<<Arg1<<Arg2;} |
|
Answer» #include <iostream.h> void Callme(int Arg1,int Arg2=20); void main() { int One=10,Two=20; Callme(One;Two); Callme(Two); } void Callme(int Arg1,int Arg2=20) { Arg1=Arg1+Arg2 cout<<Arg1<<Arg2; |
|