Computer Science - XII
Define a Class
Note : Solve each question in proper Manner as you are doing in Final Exam. Don’t use Shortcuts.
PRACTICE IN WRITING BEFORE GO FOR THE SOLUTION:
In this type of question, a class is to be defined.
Start solving answer with class and class-name. Do not start with void main( ).
No header files to be included.
City of string type should be solved as char City[25]
A function like inputvalue( ) to enter values to be defined (e.g. cin or gets).
Another function like showvalues( ) to display values to be defined (e.g. cout or puts).
To assign a string, don’t use city = “Bhopal” but use strcpy(city, “Bhopal”)
Q1. Question to define a class and its member function
a. Define a class TAXCALC in C++ with following description :
Private members :
Name of type string
PanNo of type string
Taxabincm (Taxable income) of type float
TotTax of type double
A function CalcTax( ) to calculate tax according to the following slab:
Taxable Income Tax%
Up to 150000 0
>150000 and <=200000 10
>200000 and <=500000 20
>500000 30
Public members :
A parameterized constructor to initialize all the members
A function INTAX( ) to enter data for the tax payer and call function CalcTax( ) to assign
TotTax.
A function OUTAX( ) to allow user to view the content of all the data members
A function ReturnPanno( ) to return the PanNo to the called function.
b. Define a class Applicant in C++ with following description:
Private Members
A data member ANo ( Admission Number) of type long
A data member ApplName of type string
A data member Agg(Aggregate Marks) of type float
A data member Grade of type char
A member function GradeMe( ) to find the Grade as per the Aggregate Marks obtained by a
student. Equivalent Aggregate marks range and the respective Grades are shown as follows
Aggregate Marks Grade
> = 80 A
Less than 80 and > = 65 B
Less than 65 and > = 50 C
Less than 50 and >=33 D
Less than 33 E
Public Members
A function Enter( ) to allow user to enter values for ANo, Name, Agg & call function
GradeMe( ) to find the Grade
A function Result ( ) to allow user to view the content of all the data members.
A Function ReturnAno( ) to return the Admission number of applicant.
c. Define a class DONOR with the following specifications :
private :
Donor number integer
Name 20 characters
Blood group 2 characters
public :
Input( ) A function to accept all the information
Output( ) A function to display all the information
Checkgroup( ) A function with char * return to return Blood Group
Define both the number functions with their given description.
d. Define a class HOTEL in C++ with the following description:
Private Members
Rno //Data Member to store Room No
Name //Data Member to store customer Name
Tariff //Data Member to store per day charge
NOD //Data Member to store Number of days
CALC //A function to calculate and return amount as NOD*Tariff
and if the value of NOD*Tariff is more than 10000 then as
1.05*NOD*Tariff
Public Members:
Checkin( ) //A function to enter the content RNo,Name, Tariff and
NOD
Checkout() //A function to display Rno, Name, Tariff, NOD
and Amount (Amount to be displayed by calling function
CALC( )
e. Declare a class myfolder with the following specification :
Private members of the class
Filenames an array of strings of size[10][25]
(to represent all the names of files inside myfolder)
Availspace long (to represent total number of bytes available in myfolder)
Usedspace long ( to represent total number of bytes used in myfolder)
public members of the class
Newfileentry( ) A function to accept values of Filenames, Availspace and
Usedspace from user
Retavailspace( ) A Fucntion that returns the value of total Kilobytes available
( 1 Kilobytes = 1024 bytes)
Showfiles( ) a function that displays the names of all the files in myfolder
f. Declare a class books with the following specification :
Private members of the class
Bookno integer
Bookname String
Price decimal
Quantity integer
Amt float
Calc( ) to calculate the amount by multiplying Price with Quantity.
public members of the class
A Constructor that initialized the book with some default values.
ReadBook( ) A function to accept values of Book Number, Book Name, Price,
Quantity from the user and call function Calc to calculate the Amount.
PrintBook( ) A Function that print the details of book in the out put screen.
ReturnBno A Function that returns the value of book Number
**********