Questions Based on Class

Q. Define a class book with following specification. Private members à book no, book title, price per copy, total cost. Function to calculate total cost for 'n' no of copies. Where 'n' is passed as function argument input(), purchase().
Q. Define a class batsman, name, code, inn, not out, runs, batting average. Cal avg() to compute the batting average. Public read(), invokes cal avg(), display data().
Q. Construct following declaration class employee, int code, char name, and float salary. Public void inp(), void show(), float salary(). (i) Write the objects of employee to binary. (ii) Read the objects of employee from binary file and display all objects on screen whose salary between 10,000 to 20,000

 

Questions Based on Inheritance

Q. Specify a class 'Cricket' having the following class specification:
Class name : Cricket
Data members : Name of the players and name of the country
Member functions : getinput() to get information display() to output the information

Derive class 'Bowler' public from cricket with following data members and functions:
Data members : no. of matches played, no. of over bowled and no. of wicket taken.
Member functions : getinput() to get information display() to output the information.

Derive another class 'Batsman' public from cricket with following data members and functions:
Data members : No. of matches played, no. of runs scored and average.
Member functions : inputdata() to input all the information and display() to display the information.
Write a program that will allow the user to input the information as per user choice (want to input for 'bowler' or 'batsman') for 100 players and display all the information in two separate list of 'batsman' and 'bowler'.

Q. Specify a class 'Library_Account' having following class specification:
Class name : Library_Account
Data members : student name and class
Member functions : inputdata() and display() for input and output operations.
Derive a class 'Book_Issue' public library_account with following data members and functions:
Data members : name of the book and date of issue (day, month, year)
Member functions : inputdata() and display() for input and output operations.
Derive another class 'Fine_Account' derived public from class 'Book_issue' containing following data members and functions:
Data members : fine rate and fine amount
Member functions : inputdata() to input the rate, int calculate_fine(int,int,int) with three arguments to get the values of day, month, and year and return the fine amount.

Q10. Create a class 'school' having the following specifications :
Class Name School
Data members:
Char school_name[20] : To store the name of the school
Char school_address[50] : To store the address of the school
Member functions :
Getinfo() : function get school name and address.
Putinfo() : function to display school name and address.
Derive a class "faculty" public from the class 'school', containing the information related to faculty such as: faculty name, subject (specification) and years of services etc.
Write a program id C++ to create 50 objects and print all the information in descending order of the years of experience. Include all required member functions in the class faculty.

Q. Write a program to input the students name, class, name of the book, date issue (day, month, year), fine rate and date of return (day, month, year) and print name of the student, class, name of the book, no of days for which the fine has to be calculated and the fine amount. (you may use instant variables and include member function if necessary. Students are not allowed to retain any book more then 30 days. Leap year also should be taken into account)

Q. A financial Institution has only two kinds of Accounts, Simple and Compound.
The class Account has two protected attributes Account Number (a positive integer) and Principle (a double precision real number to store the money deposited initially).
The interest for a Simple Account is calculated by using the Simple Interest formula: SI=PRT/100, where SI=Simple Interest, P=Principle, R=Rate of Interest per annum, T=Time in year.
The interest for a Compound Account is calculated by using the Compound Interest formula. CI=P[1+R/100]T - P, where CI=Compound Interest, P=Principle, R=Rate of Interest per annum, T=Time in year.

Rate and Time for two types of account may vary. Model the above situation by defining classes Account, Simple and Compound, where Simple and Compound are derived classes from class Account.
Write appropriate constructors for passing various attributes for the three classes. Write the function double interest() that calculates the appropriate interest and return the interest for the classes Simple and Compound. Also write the function display() for the three classes which print out all the attributes values as.
Account Number:
Principle:
Rate:
Time:
Interest:
with each attribute on a single line. Make sure that each display() function is correctly placed in the appropriate class. You do not need to write the main function.

Q. A class D2Point defines the coordinates of a point in a plane while another class D3Point defines the coordinates of a point in space. The details of both the classes are given below:
Class name D2Point
Data members double x, y To store the x and y coordinates.
Functions/methods:
D2Point() constructor to assign 0 to x,y
D2Point(double nx, double ny) constructor to assign nx to x and ny to y.
double distance2d(D2Point b) to return the distance between the point b and the current point in a plane.
Class name D3Point.
Data members double z. To store the z coordinate.
Functions/methods:
D3Point() constructor to assign 0 to z.
D3Point(double nz) constructor to assign nz to z.
double distance3d(D3point b) to return the distance between the point b and the current point in space.

if x1,y1,z1 x2 y2 z2 be the coordinates of the two points then the distance between the points in a plane is given by the formula: '/(x2-x1)2 + (y2-y1)2

and the distance between the points in space is given by the formula. '/(x2-x1)2 + (y2-y1)2 + (z2-z1)2

Specify the class D2point giving the details of the two constructors and function double distance2d(D2Point b). Using the concept of inheritance specify the class D3Point giving the details of the two constructors and function double distance3d(D3Point b). You do not need to write the main function.

Question 13. [2005]
A class iscscores defines the scores of a candidates in six subjects and another class bestfour defines the best four subjects.
The details of both the classes are given below.

Class Name iscscores
Data Member/Instance variable
int number[6][2] to contain marks for six subjects and subject code[numeric]
Member Functions/Methods
iscscores() constructor to accept the marks.
int point() to return the point in each subjects according to the following: Marks>=90 1 point80-89 2 points70-79 3 points60-69 4 points50-59 5 points40-49 6 points------------- accordingly
Class Name bestfour
Member Functions/Methods
void bestsubjects() to display the total points and best four subjects codes using the concept of inheritance.

Specify the details of both the classes using the concept of inheritance. Specify the details of the constructor iscscores(), and functions int point(), void bestsubjects(). Other functions are written for you and you need not write the main function.