CBSE Guess > Papers > Important Questions > Class XII > 2010 > Computer Science > Computer Science By MRK
CBSE CLASS XII
2000.
1.b. Name the header file, to which following built in function belong: 2
(i) isupper( ) ( ii)setw() (iii)exp( ) (iv)strcmp( )
Ans. (i) isupper( ) - ctype.h
(ii)setw( ) - iomanip.h
(iii)exp( ) - math.h
(iv)strcmp( ) - string.h
1.c. Will the following program execute successfully?If not, state the eason(s)2
#include<stdio.h>
void main( )
{ int s1,s2,num;
s1=s2=0;
for(x=0;x<11;x++)
{ cin<<num;
if(num>0)s1+=num;else s2=/num;
}
cout<<s1<<s2;
}
Ans. The program will not execute successfully.
Because some syntax errors are there in the program. They are
(i)cin and cout, stream objects used but iostream.h header file is not included in the program.
(ii)x is not declared, it should be declared as int.
(iii)With cin, we should use >> instead of <<.
(iv)The shorthand operator /=, is given wrongly as =/.
So the corrected program is as follows:
#include<iostream.h>
void main( )
{ int s1,s2,num;
s1=s2=0;
for(int x=0;x<11;x++)
{ cin>>num;
if(num>0)s1+=num;else s2/=num;
}
cout<<s1<<s2;
}
d)Give the output of the following program segment(Assuming all required header files are included in the program): 2
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;
Ans. Output: AOROoIiE
1.e. Write the output of the following program3
#include<iostream.h>
int func(int &x,int y=10)
{ if(x%y==0) return ++x;else return y- -;
}
void main( )
{ int p=20,q=23;
q=func(p,q);
cout<<p<<q<<endl;
p=func(q);
cout<<p<<q<<endl;
q=func(p);
cout<<p<<q<<endl;
}
Ans. Output: 2023
1023
1111
f. Write a function seqsum( ) in C++ with two arguments, double x and int n. The function should return a value of type double and it should find the sum of the following series. 4
1+ x/2! + x2/4! + x3/6! + x4/8! + x5/10! + ----+ xn/(2n)!
#include<iostream.h>
#include<math.h>
#include<conio.h>
double seqsum(int x1,int m1);
void main()
{ int x;
int m;
clrscr();
cout<<"Enter the vaue of X and M";
cin>>x>>m;
cout<<"\nThe sum of the series =
"<<seqsum(x,m);
getch();
}
double seqsum(int x1,int m1)
{ double sum=1;
for(int i=1;i<=m1;i++)
{ int f=1;
for(int j=1;j<=2*i;j++)
{ f=f*j;
}
sum=sum+pow(x1,i)/f;
}
return sum;
}
Paper By Mr. MRK
Email Id : [email protected]@yahoo.com |