Session 2017-18 Chapter 4: Classess & Object How does a class enforce data-hiding, abstraction, and encapsulation? What is the significance of access specifiers in a class? How are class and object different in terms of Object Oriented Programming Differentiate between public and private visibility modes in context of Object Oriented Programming using a suitable example illustrating each. What are the advantages and disadvantages of inline functions? What do you understand about a member function? How does a member function differ from an ordinary function? What is the relationship of a class and its objects? How is memory allocated to a class and its objects? What do you mean by static data member of a class? Explain the characteristics of a static data member. Define a class Candidate in C++ with the following description : (Delhi 2011) Private Members Public Members A data member RNo (Registration Number) of type long A data member Name of type string A data member Score of type float A data member Remarks of type string A member function AssignRem( ) to assign Remarks as per the Score obtained by a candidate. Score range and the respective Remarks are shown as follows Score Remarks >= 50 Selected A function ENTER( ) to allow user to enter values for RNo, Name, Score and call function AssignRem( ) to assign the remarks. A function DISPLAY( ) to allow user to view the content of all the data members.
Write a C + + program using classes and objects to simulate result preparation system for 20 students. The data available for each student includes rollno, name and marks in 3- subjects. The percentage marks and grade are to be calculated from the above information. The percentage marks are the average marks and the grade is calculated as follows percentage marks < 50 grade 'E' >=50 & <60 'D' >=60& <75 'C' >=75 & <90 'B' >=90& <100 'A' Define a class RESORT in C++ with the following description : Rno Name Charges Days COMPUTE( ) //Data member to store Room No //Data member to store customer name //Data member to store per day charges //Data member to store number of days of stay //A function to calculate and return Amount as Days*Charges and if the value of Days*Charges is more than 11000 then as 1.02*Days*Charges Public Members : Getinfo( ) Dispinfo( ) Define a class STOCK in C++ with the following description : Private Members : ICode of type integer (Item Code) Item of type string (Item Name) //A function to enter the content Rno, Name, Charges and Days //A function to display Rno, Name, Charges, Days and Amount (Amount to be displayed by calling function COMPUTE( )) Price of type float (Price of each item) Qty of type integer (Quantity in stock)
Discount of type float (Discount percentage on the item) A member function FindDisc( ) to calculate discount as per the following rule Public_Members : If Qty<=50 Discount is 0 If 50<Qty<=100 Discount is 5 IfQty>100 Discount is 10 A function Buy( ) to allow user to enter values for ICode, Item, Price, Qty and call function FindDisc( ) to calculate the Discount. A function ShowAll( ) to allow user to view the content of all the data members. What is wrong with the following code? 1 #include <iostream.h> 2 class Complex 3 { 4 doubler ; 5 double i ; 6 public: 7 void print (const char *p = 0, Complex& c) ; 8 }; 9 void print(const char *p, Complex& c) 10 { 11 if(!p) return ; 12 tout << p << c.r<< c.i; 13 } 14 int main( ) 15 { complex a ; a.print( ) ; 16 17 return 0 ;
18 } 1. Define a class Flight in C++ with the following specification : Private Members : E A Data Member FlightNumber of type integer A Data Member Destination of type String E A Data Member Distance of float type E 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 FlightNumber, 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. 2. Define a class in C++ with the following description : r A data member TrainNumber of type integer. A data member Destination of type string A data member Distance of type float A data member Fuel of type float A member.function CALFUEL( ) to calculate the value of Fuel as per the following criteria :
. Define a class TESTMATCH in C++ with the following description : Private Members : o TestCode of type integer o Description of type string o NoOfCandidates of type integer o CenterReqd (number of centers required) of type integer A member function CALCULATECNTR( ) to calculate and return the number of centers as (NoOfCandidates /100 + 1) Public Members : o A function GETDATA( ) to allow user to enter values for TestCode, Description, NoOfCandidates & call function CALCULATECNTR( ) to calculate the number of centers. A function PUTDATA( ) to allow user to view the content of all the data members in the following format : TEST MATCH INFORMATION Test Match Code Description Total Candidates Centers Required Define a class named ADMISSION in C++ with the following descriptions : Private Members : AD_NO integer (Range 10-2000) NAME Array of characters (String) CLASS character FEES float Public Members : Function Read_Data( ) to read an object of ADMISSION type Function Display( ) to display the details of an object Function Draw_Nos() to choose 2 students randomly and display the
details. Use random function to generate admission nos to match with AD_NO.