Important Questions

CBSE Guess > Papers > Important Questions > Class XII > 2010 > Computer Science > Computer Science By Ravi Kiran

CBSE CLASS XII

Q.1.f. Write the output of the following program.
#include<iostream.h>
void Execute(int &X,int Y=200)
{ int TEMP=X+Y;
X+=TEMP;
if(Y!=200)
cout<<TEMP<<X<<Y<<endl;
}
void main( )
{ int A=50,B=20;
Execute(B);
cout<<A<<B<<endl;
Execute(A,B);
cout<<A<<B<<endl;
}

1.f. Write a C++ function having two value parameters X and N with result type float to find the sum of series given below.
1 + x1/2! + x2/3! + x3/4! + x4/5! + - - - - - -xn/(n+1)!
#include<iostream.h>
#include<conio.h>
#include<math.h>
float sum_series(float X,int N) //function
being declared
{ float sum=0,term;
int fact,f;
sum+=1;
for(int i=1;i<=N;i++)
{ fact=1;
for(f=1;f<=(i+1);f++)
fact*=f;
term=pow(X,i)/fact;
sum+=term;
}
return(sum);
}
void main( )
{ clrscr( );
float x1;
int n1;
cout<<"\nEnter the value of X and N";
cin>>x1>>n1;
cout<<"\nThe Sum of the Series
..."<<sum_series(x1,n1);
getch(); }

Q1. .a. What is the difference between Global Variable and Local Variable?

Ans:

Global Variable Local Variable
· It is a variable, which is declared outside all the functions
· It is accessible throughout the program
· It is a variable, which is declared with in a function or with in a compound statement
· It is accessible only within a function/compound statement in which it is declared
#include <iostream.h>
float NUM=900; //NUM is a global variable
void LOCAL(int T)
{ int Total=0; //Total is a local variable
for (int I=0;I<T;I++)
Total+=I;
cout<<NUM+Total;
}
void main()
{ LOCAL(45);
}

1.b)Write the names of the header files to which the following belong.
(i) strcmp() (ii) fabs()

Ans:

(i)string.h (ii) math.h

Paper By Mr. Ravi Kiran
Email Id : [email protected]