You are on page 1of 5

Assignment: Classes, Objects & Constructor

1. Define a class named Housing in C++ with the following descriptions :


private members
reg_no integers (Ranges 10-1000)
name char array
type character
cost float
public members
function Read_data() to read an object of housing type.
function display() to display the details of an object.
Define a function draw_nos() which takes an array of Housing as parameter, chooses and
displays the details of 2 houses selected randomly from the array. Use random function
to generate the registration no.
2. Define a class named Cricket in C++ with the following descriptions :
private members
Target_scope int
Overs_bowled int
Extra_time int
Penalty int
cal_panalty() a member function to calculate penalty as follows :
if Extra_time <=10 , penalty =1
if Extra_time >10 but <=20, penalty =2
otherwise, penalty =5
public members
a function extradata() to allow user to enter values for
target_score,overs_bowled,extra_time.
a function dispdata() to follow user to view the contents of all data members.
3. Define a class named Directory in C++ with the following descriptions :
private members
docunames string (documents name in directory)
freespace long (total number of bytes available in directory )
occupied long (total number of bytes available in directory)
public members
newdocuentry() a function to accept values of docunames,freespace &
occupied from user
retfreespace() a function that return the value of total kilobytes available.
(1 KB=1024 b)
showfiles() a function that displays the names of all the documents in

directory.
4. Define a class named Publisher in C++ with the following descriptions :
private members
Id long
title 40 char
author 40 char
price , stockqty double
stockvalue double
valcal() A function to find price*stockqty with double as return
type
Public members
a constructor function to initialize price , stockqty and stockvalue as 0
Enter() function to input the idnumber , title and author
Takestock() function to increment stockqty by N(where N is passed as
argument to this function) and call the function valcal() to update the
stockvalue().
sale() function to decrease the stockqty by N (where N is sale quantity passed
to this function as argument) and also call the function valcal() to update the
stockvalue
outdata() function to display all the data members on the screen.
5. Define a class named Serial in C++ with the following descriptions :
private members
serialcode int
title 20 char
duration float
noofepisodes integer
Public members
a constructor function to initialize duration as 30 and noofepisodes as 10.
Newserial() function to accept values for serialcode and title.
otherentries() function to assign the values of duration and noofepisodes with
the help of corresponding values passed as parameters to this function.
dispdata() function to display all the data members on the screen.
6. Considering the following specifications :
Structure name
data type
size
Name_first
char array
40
mid
char array
40
last
char array
60
Structure Phone

area
char array
4

Exch
char array
4

numb
char array
6
Class name P_rec
Data Type

name
Name

phone
Phone
Member functions:
Define constructor (outside the class P_rec) that accepts the values of data
members from the user.
Define the display_rec (outside the class P_rec) that shows the current values .
Declare structures in C++ for Name and Phone . Declare the class P_rec.
7. Define a class Competition in C++ with the following descriptions:
Data Members
Event_no integer
Description char(30)
Score integer
qualified char
Member functions
A constructor to assign initial values Event_No number as 101,Description as
State level Score is 50 , qualified N.
Input() To take the input for event_no,description and score.
Award(int) To award qualified as Y, if score is more than the cutoffscore passed
as argument to the function else N.
Show() To display all the details.
8. 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 charges
NOD
// data member to store number of days to stay
Calc() // a function to calculate and return Amount as NOD*Tariff and if the value of
NOD* Tariff is more than 10000 than 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( )
9. Define a class TAXPAYER in C++ with following description :
Private members :
a. Name of type string
b. PanNo of type string
c. Taxabincm (Taxable income) of type float

d. TotTax of type double


e. A function CompTax( ) to calculate tax according to the following slab:
Taxable Income
Tax%
Up to 160000
0
>160000 and <=300000
5
>300000 and <=500000
10
>500000
15
Public members :
A parameterized constructor to initialize all the members
A function INTAX( ) to enter data for the tax payer and call function
CompTax( ) to assign TotTax.
A function OUTAX( ) to allow user to view the content of all the data
members.
10.
Define a class Student in C++ with following description:
4
Private Members
A data member RNo (Registration Number) of type long
A data member Name of type string
A data member Marks of type float
A data member Remarks of type string
A member function AssignRemarks( ) to assign Remarks as per the Marks
obtained by a Student. Marks range and the respective Remarks are shown as
follows:
Marks
Remarks
>=75
Selected
>=50
Waiting list
less than 50 Not selected
Public Members
A function ENTER ( ) to allow user to enter values for RNo, Name, Marks & call
the function AssignRemarks( ) to assign the remarks.
A function DISPLAY ( ) to allow user to view the content of all the data
members.
11. Define a class Society with the following specifications.
Data members :
Private Members :
society_name char (30)
house_no integer
no_of_members integer

flat char(10)
income float
Member Functions:
Public members:
A constructer to assign initial values of society_name as Mahavir Nagar,
flat as A
Type, house_no as 56, no_of_members as 6, income as
50000.
input( ) to read data members.
alloc_flat( ) To allocate flat according to income
income >=500000 - Flat A Type
income >=250000 and income <500000 - Flat B Type
income <250000 - Flat C Type
show( ) to display all details.
12. Define a class Restra in C++ with following description:
4
Private Members
FoodCode of type int
Food of type string
Ftype of type string
Sticker of type string
A member function Getsticker to assign the following values for Sticker as per
the given Ftype:
Ftype
Sticker
Vegetarian green
Contains egg yellow
Nonvegetarian
red
Public members
A function GetFood() to allow the user to enter the values for Foodcode,
food,ftype and call
Function GetSticker() to assign Sticker.
A function ShowFood() to allow the users to view the contents of all the data
members.