COMPUTER SCIENCE C++

2009 Outside Delhi:

1.a) What is the difference between Actual Parameter and Formal Parameter? Give an example in C++ to illustrate both types of parameters.

2

Ans) The parameters in the function call statement (or calling function) are called as Actual Parameters.

The parameters in the function definition (or called function) are called as Formal Parameters.

Eg:
void manip(int x, int y)
{ ---
---
}
void main( )
{
int a,b;
----
Manip(a,b);
}
Here a,b are Actual Parameters and x,y are Formal Parameters.

1.b) Write the names of the header files to which the following belong:

(i) setw( )
(ii) sqrt( )

1

Ans: (i) setw( ) – iomanip.h (ii)sqrt( ) - math.h

1.c) Rewrite the following program after removing the syntactical errors (if any). Underline each correction.

include <iostream.h>
include <stdio.h>

class MyStudent
{ int StudentId=1001;
char Name[20];
public
MyStudent( ) { }
void Register( )
{ cin>>StudentId;
gets(Name);
}
void Display( )
{ cout<<StudentId<<”:”<<Name<<endl;
}
};
void main( )
{ MyStudent MS;
Register.MS( );
MS.Display( );

2

Ans:

#include <iostream.h>
#include <stdio.h>
class MyStudent
{ int StudentId;
char Name[20];
public:
MyStudent( ) { }
void Register( ) { cin>>StudentId;
gets(Name);
}
void Display( )
{ cout<<StudentId<<":"<<Name<<endl;
}
};
void main( )
{ MyStudent MS;
MS.Register( );
MS.Display( );

 

CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( [email protected] )