0% found this document useful (0 votes)
146 views

Classes and Objects Worksheet2

The document defines 13 classes with attributes and methods to model different real world entities like societies, movies, cricketers, travel etc. Each class definition includes data members to store relevant attributes and member functions to initialize, calculate derived values, accept user input and display object details.

Uploaded by

Sooraj Rajmohan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
146 views

Classes and Objects Worksheet2

The document defines 13 classes with attributes and methods to model different real world entities like societies, movies, cricketers, travel etc. Each class definition includes data members to store relevant attributes and member functions to initialize, calculate derived values, accept user input and display object details.

Uploaded by

Sooraj Rajmohan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Class and Objects Worksheet 2

1.) Define a class having the following:


Attributes:
Name of the society
House number
Number of members
Flat type
Income
Methods:
1) To read data member
2) To allocate the flat according to the income
Income>=10000 flat type=HIG
Income>=5000 and <10,000 flat type=MIG
Income<5000 flat type=LIG
3) To display all the data.

2) Define a class Travel in C++ with the following descriptions :


Attributes :
TravelCode of type long
Place of type string
No_of_travellers of type integer
No_of_buses of type integer
Methods:
a) A constructor function to assign initial values of TravelCode as 201, Place
as Nainital, No_of_travellers as 10, No_of_buses as 1
b) A function NewTravel() which allows user to enter TravelCode, Place and
No_of_travellers. Also, assign the value of No_of_buses as per the
following conditions :
No_of_travellers No_of_buses
Less than 20 1
Equal to or more than 20 and less than 40 2
Equal to 40 or more than 40 3
c) A function ShowTravel( ) to display the content from all the data
members on screen.
3) Define a Movie with the following specifications:
Attributes Methods
Name of the movie - to initialize data members
Date of releasing - to display the movie details
Name of the director - to update the total collection at the end
Total collection of every week.
Write the complete program to call the member functions according the user choice
4) Define a class batsman with the following specifications:
Attributes:
bcode ( 4 digit code number)
bname ( 20 characters)
innings, notout,runs (integer type)
batavg calculated according to the formula
batavg = runs/(innings notout)
calavg() function to compute batavg.
Methods:
Readdata( ) function to accept values for bcode, bname, innings,
notout, runs and invoke the function calavg()
Display( ) function to display data members on screen.
Write the function definitions.
5) Define a class Serial with the following specifications:
Attributes
Serialcode integer
Title 25 characters
Duration float
Noofepisodes integer
Methods.
A function to initialise Duration as 30 and Noofepisodes as 10.
Newserial() function to accept values of Serialcode and Title.
Otherentries() function to assign the values of Duration and Noofepisodes
passed as parameters to this function.
Displaydata() function to display all the data members on the screen

6) Define a class TEST in C++ with following description:


Attributes
a. TestCode of type integer
b. Description of type string
c. NoCandidate of type integer
d. CenterReqd (number of centers required) of type integer
Methods
a. A member function CALCNTR() to calculate and return the number of
centers as (NoCandidates/100+1)
b. A function SCHEDULE() to allow user to enter values for TestCode,
Description, NoCandidate & call function CALCNTR() to calculate the number of
Centres
A function DISPTEST() to allow user to view the content of all the data
members.
7) Define a class Flight in Python with following description:
Attributes :- Flight number, Destination, Distance, Fuel
Methods
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
A function FEEDINFO() to allow user to enter values for Flight Number,
Destination, Distance & call function CALFUEL() to calculate the quantity of
Fuel
A function SHOWINFO() to allow user to view the content of all the data
Members

8) Define a class Hotel in with the following specification:


Attributes
rno // datamember to store the room no
Name//datamember to customer name
Tariff//datamember to store per day charges
NOD//datamember to store no of days of stay
Calc() // a function to calculate and return amt as NOD*tariff and if the
value of nod*tariff is more than 10000 then as 1.05*nod*tariff

Methods:
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 calcu())

9) Define a class Applicant in with following description:


Attributes
A data member Ano (Admission number )
A data member Name
A data member Agg( Aggregate Marks )
A member function GradeMe() to find the Grade as per the aggregate
marks obtained by a student.
Equivalent aggregate marks and 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 D
Methods
A function enter() to allow user to enter values for Ano, Name ,Agg and
call function GradeMe() to find the Grade.
A function result() to allow user to view the content of all the data
members
10) Define a class Clothing in C++ with the following descriptions:
Attributes:
Code, Type, Size, Material, Price
Methods
A function Calc_Price() which calculates and assigns the value of Price as follows:
For the value of Material as COTTON

Type Price (Rs.)


TROUSER 1500
SHIRT 1200
For Material other than COTTON the above mentioned Price gets reduced by 25%.
A constructor to assign initial values of Code, Type and Material with the word NOT
ASSIGNED and Size and Price with 0.
A function Enter () to input the values of the data members Code, Type, Size and
Material and invoke the CalcPrice() function.
A function Show () which displays the content of all the data members for a Clothing.

11)Define a class named HOUSING in C++ with the following descriptions:


attributes
REG_NO integer(Ranges 10 1000)
NAME Array of characters (String)
TYPE Character
COST Float
Public Members
Read_Data( ) to read an object of HOUSING type.
Function Display( ) to display the details of an object.
Function DrawNos( ) to choose and display the details of 2 houses selected
randomly from an array of 10 objects of type HOUSING. Use random
function to generate the registration nos. to match with REGNO from the
array.
12)Define a class named Tour in C++ with following description?
attributes:
tcode integer (Ranges 6 - 10)
adults, children, distance integer
totalfare float
AssignFare( )A function which calculates and assign the value to data member
totalfare as follows:-
- For adults Fare Distance
Rs. 500 >=1500
And fare get reduced by 25% if distance is < 1500.
- For Children
For every child a fixed Rs. 50 is charged as fare.
Methods:
A constructor which initialized initialize all data members with 0
Function EnterTour() to input the values of the data members tcode, adults,
children and call to AssignFare function.
Function ShowTour() to print all the details of object of Travel type.

13)Define a class Travel in C++ with the description given below :


Private Members :
T.Code of type string ,No_of_Adults of type integer ,No_of_Children of type integer
Distance of type integer
TotalFare of type float
Public Members
-A constructor to assign initial values as follows:
T_Code with the word NULL ,No_of_Adults as 0 ,No_of_Children as 0 ,Distance as
0 ,Totalfare as 0
-A function AssignFare( ) which calculates and assigns the value of the data member
TotalFare as follows
For each Adult
Fare
For Distance (Km)
(Rs)

500 >=1000

300 <1000 & >=500

200 <500

For each Child the above Fare will be 50% of the Fare mentioned in the
above table.
For example: If Distance is 750, No_of_Adults = 3 and No_of_Children = 2
Then TotalFare should be calculated as No_of_Adults * 300 + No_of_Children * 150
i.e. 3 * 300 + 2 * 150 = 1200
-A funtion EnterTravel( ) to input the values of the data members T_Code,
No_of_Adults, No_of_Children and Distance; and invoke the AssignFare() function.
-A function ShowTravel() which displays the content of all the data members for a
Travel.

You might also like