1. What do you mean by static member function? Write an example.
2. What do you mean a class and an object?
3. Differentiate between private, protected and public visibility modes of a class with suitable example.
4. Find and write the output of the following C++ program code: Note: Assume all required header files are already being included in the program.
class Stock
{ long int ID;
float Rate;
int Date;
public:
void Initialize( )
{ID=1001; Rate = 200; Date = 1; }
void RegCode( long int I, float R)
{ ID = I; Rate = R; }
void Change( int New, int DT )
{ Rate+= New ; Date = DT; }
void Show( )
{ cout<< “Date:”<< Date << endl ;
cout<<< ID << “#”<< Rate << endl ;
} };
void main( )
{ Stock A,B,C,D;
A.Initialize( ) ; B.Initilalize( ) ; C.Initialize( ) ; D.Initialize( ) ;
A.RegCode(1024,150) ; B.RegCode(2015,300) ; B.Change(100,29) ;
C.Change(-20,20) ; D.Change(30,15) ; A.Show( ) ; B.Show( ); C.Show( ) ; D.Show( ) ;
}
5. Define a class BUS in C++ with following description:
Private Members
A data member Busnumber of type integer
A data member Destination of type string(25 characters)
A data member Distance of type float
A data member Fuel of type float
A member function CALCFUEL() to calculate the value of Fuel as per the following criteria
Distance Fuel
<=1000 500
more than 1000 and <=2000 1100
more than 2000 2200
Public Members
A function FEEDINFO( ) to allow user to enter values for Bus Number, Destination, Distance & call function CALCFUEL( ) to calculate the quantity of Fuel.
A function SHOWINFO( ) to allow user to view the content of all the data members.
6. Write the definition of a class CUBE in C++ with following description:
Private Members:
Cno - data member of integer type
Side - data member of float type
Volume - data member of float type
CalcVolume( ) - Member function to calculate and assign Volume as side*side*side
Public Members:
GetData( ) - A function to allow user to enter values of side. Also,this function should
call CalcVolume( ) to calculate volume.
ShowData( ) - A function to display Cno, Side and Volume.
7. Rewrite the following program after removing the syntactical error(s), if any. Underline each correction.
#include[iostream.h>
Class Admission
{ int Adno ;
char name[25] ;
public
void getdata( )
{ cout<< “ Enter the admission number:”;
cin>> Adno;
cout<< “\n Enter name:” ;
gets(name) ;
}
void display( )
{ cout << “Admission number :”<< Adno;
cout<< “\nName:” <
} } ;
void main( )
{ Admission AD ;
getdata( ).AD
display( );
}
Please click on below link to download CBSE Class 12 Computer Science Worksheet Set F Solved