0% found this document useful (0 votes)
276 views2 pages

Questions Based On Classes and Constructor: Q1. Define A Class Flight in C++ With The Following Specification

The first document describes two C++ classes - Flight and TEST. The Flight class has private data members for flight number, destination, distance, and fuel. It contains public member functions to input data and calculate fuel usage. The TEST class has private data members for test code, description, and number of candidates. It contains public member functions to input data and calculate the number of exam centers. The second document describes an Exam class with multiple constructor functions that demonstrate constructor overloading. It asks how to call each constructor and which OOP feature is shown. The third document describes a readbook class with constructor and destructor functions. It asks about the purpose and invocation of each

Uploaded by

Niti Arora
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
276 views2 pages

Questions Based On Classes and Constructor: Q1. Define A Class Flight in C++ With The Following Specification

The first document describes two C++ classes - Flight and TEST. The Flight class has private data members for flight number, destination, distance, and fuel. It contains public member functions to input data and calculate fuel usage. The TEST class has private data members for test code, description, and number of candidates. It contains public member functions to input data and calculate the number of exam centers. The second document describes an Exam class with multiple constructor functions that demonstrate constructor overloading. It asks how to call each constructor and which OOP feature is shown. The third document describes a readbook class with constructor and destructor functions. It asks about the purpose and invocation of each

Uploaded by

Niti Arora
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Questions based on classes and constructor

Q1. Define a class Flight in C++ with the following specification:


Private Members:
• A Data Member Flight Number of type integer
• A Data Member Destination of type String
• A Data Member Distance of Float Type
• A Data Member Fuel of type float
A Member Function CalFuel( ) 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 Feed_Info( ) to allow user to enter values for Flight Number, Destination,
Distance & Call Function CalFuel( ) to calculate the quantity of fuel.
A Function Show_Fuel( ) to allow user to view the content of all the data members.

Q2. Define a class TEST with the following specification:


Private members
Testcode of type integer
Description of type string
NoCandidate of type integer
A member function CALCNTR( ) to calculate and return the number of centers as (
NoCandidate / 100 + 1)
Public members
A constructor function to initialize Testcode as 12.
A function IN_DATA( ) to accept values for Testcode, Description, NoCandidate
And call function CALCNTR( )
A function OUT_DATA( ) to display all the data members

Q3. Answer the questions after going through the following class.
class Exam
{
char Subject[20] ;
int Marks ;
public :
Exam() // Function 1
{
strcpy(Subject, “Computer” ) ;
Marks = 0 ;
}
Exam(char P[ ]) // Function 2
{
strcpy(Subject, P) ;
Marks=0 ;
}
Exam(int M) // Function 3
{
strcpy(Subject, “Computer”) ;
Marks = M ;
}
Exam(char P[ ], int M) // Function 4
{
strcpy(Subject, P) ;
Marks = M ;
}
};
a) Which feature of the Object Oriented Programming is demonstrated using Function 1,
Function2, Function 3 and Function 4 in the above class Exam?
b) Write statements in C++ that would execute Function1, function2, Function 3 and Function 4
of class Exam.

Q4. Answer the questions(i) and (ii) after going through the following class :
class Exam
{
int year;
public :
Exam(){year=0;} //function1
Exam(int y) { year=y; } //function2
Exam(Exam &t); //function3
~Exam()” cout<<””object is relaease………….”;} //function4
};
(i) When Exam E1; command is issued which function will be invoked and what is it called.
(ii) Write complete definition for function 3.
(iii) When Exam E1(E2); command is issued which function will be invoked.
(iv) When function4 will be executed.

Q5. Given the following C++ code, answer the questions i and ii:
class readbook
{
public:
readbook( ) //Function1
{
cout<<”Open the Book”<<endl;
}
void readchapter( ) //Function 2
{
cout<<”Reading chapter one”<<endl;
}
~readbook( ) //Function 3
{
cout<<”Close the book”<<endl;
}
};
1. In OOP, what is Function 1 referred as and when does it get invoked/called?
2. In OOP, what is Function 3 referred as and when does it get invoked/called?

Q6. Distinguish between the following two statements:


time T1(13, 10, 25); //statement 1
time T1 = time(13,10,25); //statement 2

You might also like