You are on page 1of 5

Questions

1) Given that

for( k=10;k<15;k++)
{
if (k<=12)
cout<<twice k=<<2*k<<endl<<endl;
else
cout<<k=<<k<<endl;
}
What is the output produced from this code fragments?

2) Find the output for the following program


#include<iostream.h>
#include<conio.h>
void main()
{
for (i=0;i<=10;i++);
{
if (i==5)
break;
cout<<i<<endl:
}
cout<<i<<endl:
}
3) Rewrite the following code after removing syntax errors underline each correction

#include<iostream.h>;
Void main()
{
int j=99, a;
float u=10.0;
cin(a);
int b=sqrt(a)
while a<=j
{
a+=10
u*=b
b=sqrt(a)
}
}
4) Find the output of following program code:
Void main ( ) {
int x = 7, y = 5;
cout << x ++;
cout << ++ x;
cout << x;
cout << y ++ <<, << ++ y; }

5) Find the output :


void result(int &x, int y=10)
{
int temp = x + y;
x + = temp;
if(y <=10)
y + = temp;
}
void main( )
{
int A1=10, B2=5;
result(A1, B2);
cout<<A1<<B2<<endl;
result(A1);
cout<<A1<<B2<<endl;
result(B2);
cout<<A1<<B2<<endl;
}
6) Find the output
#include <iostream.h>
void main( )
{
int i = 0, x = 0;
do
{
if(i % 5 = = 0)
{ cout<<x;
x++;
}
++ i;
}while(i<10);
cout<<\n<<x;
}
7) Rewrite the following program after removing the syntactical error(s) if any.
Underline each correction.
#include<iostream.h>
int main
{
struct movie
{
char movie_name[20];
char movie_type;
int ticket_cost=100;
}movie;
gets(movie_name);
gets(movie_type);
}
8) What will be the output of the following segment?
struct number

{
int no1, no2;
};
void display(number n)
{
cout<<Number1=<<n.no1++<<Number2=<<- -n.no2<<endl;
}
void main( )
{
number n1={10,100}, n2, n3;
n3 = n1;
n1.no1 + = 5;
n2 = n3;
n2.no1 - = 5;
n2.no2 * = 2;
n3.no1 + = 1;
display(n1);
display(n2);
display(n3);
}
9) Find the output of the following program.
#include<iostream.h>
void Withdef(int HisNum=30)
{
for(int I=20;I<=HisNum;I+=5)
cout<<I<<,;
cout<<endl;
}
void Control(int &MyNum)
{
MyNum+=10;
Withdef(MyNum);
}
void main()
{
int YourNum=20;
Control(YourNum);
Withdef();
cout<<Number=<<YourNum<<endl;
}
10)
void main()
{
char *NAME=a ProFiLe!;
for(int x=0;x<strlen(NAME);x++)
if(islower(NAME[x]))
NAME[x]=toupper(NAME[x]);
else
if(isupper(NAME[x]))
if(x%2!=0)
NAME[x]=tolower(NAME[x-1]);
else
NAME[x]--;
cout<<NAME<<endl;

}
11) How Many time the following code will be executed
int i = 1 ;
i= i - 1 ;
while(i)
{
cout<<its a while loop;
i++ ;
}
12) identify the error(s) in the following code fragment
char ch; int v=0,o=0;
cout<<enter character;
while ((ch>=A && ch<=Z)||( ch>=a && ch<=z))
{
switch(ch) {
case a:
case e:
case i:
case o:
case u:
case U: ++v; break; default : ++o;
}cout<<v;<< <<o;
}
13) Find the output of the following program; 3
#include<iostream.h>
#include<ctype.h>
void main( )
{
char Text[ ] = Comp@uter!;
for(int I=0; Text[I]!=\0;I++)
{ if(!isalpha(Text[I]))
Text[I]=*;
else if(isupper(Text[I]))
Text[I]=Text[I]+1;
else
Text[I] = Text[I+1]; }
cout<<Text;
}
14) What will be the output of the following program segment?
If input is as: (a) g (b) b (c) e (d) p
cin >>ch;
switch (ch)
{ case g: cout<<Good;
case b: cout<<Bad;
break;
case e: cout<< excellent ;
break;
default: cout<< wrong choice;

}
15) Find the error from the following code segment and rewrite the corrected code underlining the
correction made.
# include(iostream.h)
void main ( )
int X,Y;
cin>>>X;
for(Y=0,Y<10, Y++)
if X= =Y
cout<<Y+X;
else
cout>>Y; }
16) Convert the following code segment into switch case construct.
int ch;
cin>>ch;
If(ch = = 1)
{ cout<< Laptop;
}
else If(ch = = 2)
{
cout<<Desktop ;
} else if(ch= = 3)
{
cout<<Notebook;
} else
{
cout<<Invalid Choice;
}
}
}

You might also like