Class and Object Assignment: Private Members
Class and Object Assignment: Private Members
Assignment
1.Define a class student with the following specification:
Private members
admno integer type
sname 20 character
eng, math,sci, total float
ctotal( ) A function to calculate the total marks with float return type.
Public members:
takedata ( ) function to reed admno, sname,eng,math, sci and invoke ctotal( ) to calculate total.
showdata ( ) to display all the data members on the screen.
6. struct date
{
int dd, mm, yy ;
};
struct doner
{
char name[20];
date dob;
};
void main( )
{
doner person;
------------------
------------------
}
How will you access the fields : name and yy of the above structure? (2)
8. Define a class Bank to represent the bank account of a customer with the following
specification 4
Private Members:
- Name of type character array(string)
- Account_no of type long
- Type_of_account ( S for Saving Account, C for current Account) of type char
- Balance of type float
Public Members:
A constructor to initialize data members as follows
- Name NULL
- Account_no 100001
- Type_of_account ‘S’
- Balance 1000
A function NewAccount() to input the values of the data members Name, Account_no,
Type_of_account and Balance with following two conditions
Minimum Balance for Current account is Rs.3000
Minimum Balance for Saving account is Rs.1000
A function Deposit() to deposit money and update the Balance amount.
A function Withdrawal() to withdraw money. Money can be withdrawn if minimum
balance is as >=1000 for Saving account and >=3000 for Current account.
A function Display() which displays the contents of all the data members for a account.
10. Define a class named Football in C++ with the following descriptions:
Private members:
Team_A, Team_B– Strings of 20 characters
Goal_A, Goal_B – integer numbers
Winner – String of 20 character
Public members :
A constructor to initialize the values of data members.
Function Get_Team( ) to read the values for all the data members.
Function Show_Team( ) to show Team_A, Goal_A, Team_B, Goal_B and Winner.
Function Champion( ) to assign the value of Winner based on high scoring team. If both
team scored same number of goals assign “Draw”.
Public Members:
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.
Position Points
I 7
II 5
III 3
If number of participants is more than 7, then points for each position will be doubled.
Show_Data() to show the values of Game, Standard and Points.
15. Define a class Tour in C++ with the description given below: 4
Private Members:
TCode of type string NoofAdults of type integer NoofKids of type integer
Kilometres of type integer TotalFare of type float
Public Members:
• A constructor to assign initial values as follows:
TCode with the word “NULL” NoofAdults as 0 NoofKids as 0
Kilometres 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(Rs) For Kilometres
500 >=1000
300 <1000 &>=500
200 <500
For each Kid the above Fare will be 30% of the Fare mentioned in the above table For example:
If Kilometres is 850, NoofAdults = 2 and NoofKids = 3
Then TotalFare should be calculated as
NumofAdults * 300 + NoofKids * 90 i.e. 2*300 + 3*90=870
• A function EnterTour( ) to input the values of the data members TCode, NoofAdults, NoofKids and
kilometres and invoke the Assign Fare( ) function.
• A function ShowTour( ) which displays the content of all the data members for a Tour.
16. Define a class Student for the following specification.
Private members of the Student are:
roll integer
name array of character of size 20
class integer
mark1, mark2, mark3 integer
average float
calculate() that calculates overall average marks and returns the average.
Public members of the Student are:
Readmarks() reads marks and invokes the calculate function.
Displaymarks() prints the data.
20. Define a class Travel in C++ with the description given below:
Private members:
plancode of type long
place of type characters array
number_of_travellers of type integer
number_of_buses of type integer
Public members:
A constructor to assign initial values of plancode as 1001, place as “Kolkata”,
number_of_travellers as 5 and number_of_buses as 1
A function newplan( ) which allows user to enter plancode , place and number_of_travellers and
also assign the number_of_buses as per the following conditions:
number_of_travellers number_of_buses
less than 20 2
equal to and more than 20 and less than 40 3
equal to and more than 40 4
A function show( ) to display the contents of all the data members on the screen.
Public Members
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
23. Define a class named ADMISSION in C++ with the following descriptions:
Private Members:
AD_NO integer (Ranges 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.
25. Design a class Composite to fill an array of order [m x n] with the first [m x n] composite numbers
column wise. The details of the members of the class are given below:
Class name: Composite
Data members/ instance variables:
arr[ ] [ ] : Two dimensional array.
m : integer to store the number of rows.
n : integer to store the number of columns.
Member functions:
Composite( ) : to accept the size of the array.
int isComposite( int p) : return 1 if number is composite and 0 if not composite.
void fill( ) : to fill the elements of the array with the first (m x n) composite numbers.
void display( ) : displays the array in a matrix form.
Specify the class Composite giving details of the constructor and member functions int
isComposite(int), void fill( ) and void display( ) with main( ) function to create an object and call
the function accordingly.
26. 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.
27. Define a class named HOUSING in C++ with the following descriptions:
Private members
REG_NO integer(Ranges 10 — 1000)
NAME Array of characters(String)
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
Function Draw Nos( ) 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.
28. Define a class in C++ with following description:
Private Members
a. A data member Flight number of type integer
b. A data member Destination of type string
c. A data member Distance of type float
d. A data member Fuel of type float
e. 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 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
30. Define a class bank to represent the bank account of a customer with the
following specifications:
private members:
- name of the depositor char (20)
- account no int
- type of account ( s for saving, c for current account) char(1)
- balance amount (float)
member functions:-
- ini( ) to initialize data members
- deposit( ) to deposit money
- withdraw( )for withdraw of money. Mony can be
withdraw if minimum balance > = 1000
- display( ) to display data members
36. Declare a class bank to represent bank account of 10 customers with the following data members: name of
depositor, account number, type of account(s for savings and c for current account), balance amount. The
class also contains the following member functions:
(a) To initialize data members.
(b) To deposit money
(c) To withdraw money after checking minimum balance (say 1000)
(d) To display the data members on screen.
37. Define a class named MOVIE in C++ with the following description:
Private members
HALL_NO integer
MOVIE_NAME Array of characters (String)
WEEK integer (Total number of weeks the same movie is shown)
WEEK_COLLECTION Float
TOTAL_COLLECTION Float
Public Members
Function Read_Data( ) to read an object of ADMISSION type
Function Display( ) to display the details of an object
Function Update( ) to update the total collection and Weekly collection once in a
week changes. Total collection will be incremented by Weekly collection and
Weekly collection is made Zero
38. Define a class Tour in C++ with the description given below :
Private Members :
TCode of type string
NoofAdults of type integer
NoofKids of type integer
Kilometres of type integer
TotalFare of type float
Public Members :
A constructor to assign initial values as follows :
TCode with the word “NULL”
NoofAdults as 0
NoofKids as 0
Kilometres as 0
TotalFare as 0
A function AssignFare ( ) which calculates and assigns the value of the data
member TotalFare as follows
For each For
Adult Kilometres
Fare(Rs)
500 >=1000
300 <1000
&>=500
200 <500
For each Kid the above Fare will be 50% of the Fare mentioned in the above table
For example :
If Kilometres is 850, NoofAdults = 2 and NoofKids = 3
Then TotalFare should be calculated as
NumofAdults * 300 + NoofKids * 150
i.e. 2*300 + 3*150=1050
A function EnterTour( ) to input the values of the data members TCode, NoofAdults, NoofKids and
Kilometres; and invoke the Assign Fare( ) function.
A function ShowTour( ) which displays the content of all the data members for a Tour.
Contributed : Mohan