Professional Documents
Culture Documents
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?
#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; }
{
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;
}
}
}