Assignment for Half Yearly Examination
Assignment for half yearly preparationClass XI
Q.1.a) What is the difference
between automatic type conversion and type casting ?Give example to explain
both.
b) Give any four differences between switch and if-else
without giving any example.
c) Give
differences between break ,continue and exit with example .
d)Give difference between while and do while loops.
e) What is the difference between if and switch
statements?
f) What is the difference between ‘x’ and “x”?
g) How can you give a single line and multiline comments
in C++ explain with suitable examples.
h) What will be the value of a=5/3 if a is (i) int
(ii)float ?
Q.2. Name the header files needed to
execute this program successfully:
void main()
{
int x, y, z;
x=10; y=9;
z=pow(x,2);
getch();
}
Q2. Consider the following erroneous code
fragments. Write the corrected code underlining all the corrections made:
void main()
{ int c;
switch( c );
case 1.5: { cout<<” India is great\n”;
} break;
‘case’ 2: { cout<<” hello\n”;
} break;
} }
Q. 3. Predict the output:
# include<iostream.h>
void main ( )
{int i=0;
for (i=1; i<=30;i++)
{
cout<<i<<endl;
i=i+2;
}
}
Q. 4. Do the following conversion:
Convert
following while loop to for loop and do while loop
int x=0;
while(x<=100)
{ cout<<” the value of x is \n”<<x;
cout<<”done \n”;
x+=2;
}
Q. 5. Give
output:-
i. int k=5,i=10;
while(i<=100)
{
cout<<k+i;
k=k*5;
i=i+10;
}
cout<<"bye";
ii. for(int j=2;j<10;j+=2)
{int k=j*3;
if(k%6==0)
cout<<k;
cout<<"loop continues\n";
}
ii. int a=3;
do
{
int k=a+5;
cout<<"k="<<k;
a=a+3;
}while(a<15);
i. int k=5,i=10;
while(i<=100)
{
cout<<k+i;
k=k*5;
i=i+10;
}
cout<<"bye";
ii. for(int j=2;j<10;j+=2)
{int k=j*3;
if(k%6==0)
cout<<k;
cout<<"loop continues\n";
}
ii. int a=3;
do
{
int k=a+5;
cout<<"k="<<k;
a=a+3;
}while(a<15);
Q6.
Convert the following for loop to while and do-while loop
int sum=1;
for(int
i=1;i<10;i++)
{
sum=sum*5;
}
cout<<sum;
}
Q7. Convert the following while loop to for and do-while
loop:
int fact=1;
int
i=1;
int num=8;
while
( i<num)
{
fact=fact*i;
i++;
}
cout<<fact;
}
Q8.Convert the following
switch case statement to if-else statement:
int
p,q,r,s,t;
p=q=r=s=t=2;
switch(p)
{ case
1:
case
2:q++;
case
3: r++; q++;
break;
case
4:
case
5: s++; q++;r++;
break;
default
: t++; q++; r++; s++;
}
p++;
cout<<q<<”
“<<r<<” “<<s<<” “<<t;
Q9 Convert the following
if-else statement to switch-case statement
int
num=10,sum=0;
if(num==1)
sum+=5;
else if (num==10||num==20)
sum+=10;
else if( num==100)
sum*=10;
else
sum-=5;
}
Plese uplaod the answers too ....
ReplyDelete