Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
126 views

Class and Object Assignment: Private Members

1. The student class has private data members for admission number, name, marks in 3 subjects and total marks. It contains public member functions to take input data, calculate total marks and display all data. 2. The Garments class models clothing items with private data like code, type, size, fabric and calculated price. Public member functions allow inputting data, calculating price based on fabric, and displaying garment details. 3. The DVD class contains private data like code, title, duration, actors, price and public member functions to input data, define a copy constructor and display DVD details.

Uploaded by

CHIRAG MARWAH
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views

Class and Object Assignment: Private Members

1. The student class has private data members for admission number, name, marks in 3 subjects and total marks. It contains public member functions to take input data, calculate total marks and display all data. 2. The Garments class models clothing items with private data like code, type, size, fabric and calculated price. Public member functions allow inputting data, calculating price based on fabric, and displaying garment details. 3. The DVD class contains private data like code, title, duration, actors, price and public member functions to input data, define a copy constructor and display DVD details.

Uploaded by

CHIRAG MARWAH
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 12

Class and object

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.

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


Private Members:
GCode of type string
GType of type string
GSize of type integer
GFabric of type string
GPrice of type float
A function Assign( ) which calculates and assigns the value of GPrice as follows:
For the value of GFabric "COTTON",
GType GPrice(Rs)
TROUSER 1300
SHIRT 1100
For GFabric other than "COTTON" the above mentioned GPrice gets reduced by 10%
Public Members :
A constructor to assign initial values of GCode, GType and GFabric with the
word "NOT ALLOTTED" and GSize and GPrice with o.
A function Input( ) to input the values of the data members GCode, GType,
GSize and GFabricl and invoke the Assign( ) function.
GAafrumnecntito. n Display( ) which displays the content of all the data members for a Garment

3. Defne a class DVD in C++ with following description :


Private members :
dcode integer
Title string
Duration integer
Actor string
Actress string
Price real number
Public members :
Parameterized constructor to get initial values for all members.
Define copy constructor for the class.
Function INCOMP( ) to input values
Function DISPCOMP( ) to view the contents of all the data members

4 Define and declare a class MYFOLDER with the following specifications:


Private Members:
Filename: An array of string of size [10][25]
Availspace: long
Usedspace: long
Public members:
newfileEntry( ): Function to read value
Retavailspace( ): Function that returns the value of total kilobytes available
Showfile(): Function to display details.
5 Define a class teacher with the following specifications:
( No need to define the functions)
Private members:
name: 20 characters
sub: 10 characters
basic,da,hra: integers
salary: float
calculate(): that returns salary
public members:
readdata(): read data values
showdata(): display details

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)

7. 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.

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.

9. Define a class named result in C++ with the following descriptions: 4


Private members:
Rollno – integer number
Name – String of 20 characters
Subjects – an integer array to store 6 subject marks
Total – integer number
Average – float number
Public members :
 A constructor to initialize the values of data members.
 Function Get_Value ( ) to read the values for all the data members.
 Function Show_Value ( )to show Rollno, Name, Total and Average.
 Function Best_Five ( )to find the average and total marks of top 5 subject marks.

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”.

11. Define a class Clothing in C++ with the following descriptions: 4


Private Members:
Code of type string
Type of type string
Size of type integer
Material of type string
Price of type float

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%.

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.

12. Define a class Rural_Games in C++ with the following descriptions: 4


Private Members:
Game for name of the game
No_of_Participants for number of participants
Participants for name of the participants
Standard for storing the participant class
Position for recording the position
Points for assigning the points based on position
Public Members:
A constructor to assign appropriate values for the members.
Get_Data () to read the values for Name of the game, number of participants
and all their names, class of study and position.
Assign_Points () to assign values based on the following condition

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.

13. Defne a class WEAR in C++ with following description : 4


Private members :
code string
Type string
Size integer
material string
Price real number
A function calprice( ) that calculates and assign the value of price as follows :
For the value of material as “WOOLEN”
Type Price(Rs.)
------- -------------
Coat 2400
Sweater 1600
For material other than “WOOLEN” the above mentioned price gets reduced by 30%.
Public members :
A constructor to get initial values for code, Type & material as “EMPTY” & size and price with 0.
A function INWEAR( ) to input the values for all the data members except price which will be initialized
by function calprice( ).
Function DISPWEAR( ) that shows all the contents of data members

14. Define a class Book with the following specification: [4]


Private members
Book_No integer type
Book_title 20 character
Price float(price per copy)
Total_cost( ) A function to calculate the total cost for N number of copies ,
where N is passed to the function as argument.
Public members:
INPUT ( ) function to reed Book_no, Book_title, price.
PURCHASE ( ) function to ask the user to input the number of copies to be purchased .
It invokes total_cost and prints the total cost to be paid by the user.

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.

17.. Define a class RESORT with the following specifications.


Private members:
Data members : roomno- int, name- string, charges- float, days- int, amount- float.
Member function: compute( ) - To calculate and return amount as days * charges
and if the value of days * charges is more than 2100 then as 1.5 * days * charges.
Public members:
Constructor: To assign roomno as 786, name as DON, charges as 420 and days as 7.
Member Functions: enterdetails ( )– to input data and invoke compute( ) function.
display ( ) – to display the details of the customer

18. Define a class Serial in C++ with the following description:


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.

19. Define a class named Admission in C++ with following description?


Private members:
admno integer (Ranges 10-1500)
name string of 20 characters
cls integer
fees float
Public members:
A constructor which initialized admno with 10, name with “NULL”, cls with 0 & fees with 0
Function getdata() to read the object of Admission type.
Function putdata() to print the details of object of admission type.
Function draw_nos() to generate the admission no. randomly to match with admno and display
the detail of object.

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.

21. Define a class REGFLAT in C++ with following description :


Private members :
a. registration number of type integer (range 200-500)
b. Name of type string
c. Flat type string
d. Cost of type float
Public members :
 A function INFLAT( ) to read an object of REGFLAT type
 A function OUTFLAT( ) to allow user to view the content of all the data members.
A function DRAW( ) to choose & display the details of 5 houses selected randomly from an array of 10
objects of type REGFLAT passed as arguments to the function. Use random function to generate the
registration numbers to match with registration number from the array.

22. Define a class TEST in C++ with following description:


Private Members
a. TestCode of type integer
b. Description of type string
c. NoCandidate of type integer
d. CenterReqd (number of centers required) of type integer
e. A member function CALCNTR() to calculate and return the number of centers as
(NoCandidates/100+1)

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.

24. Define a class SalesCounter with folloeing specifications:


Data members:
Net_amt, Amount – Real values
ClothType - string( 30), Pay_mode string (30)
Member functions
o Constructor – to initialize the Amount as 0, ClothType as “Cotton”, Pay_mode as “Cash”,
Net_amt as 0
o Calc_net () – to calculate discount and net_amt . The Company offers discount scheme on
each purchase to the customer. The scheme is as follows
 For Cotton
Purchase above 5000 and avail discount of 10%
Purchase above 7500 and avail discount of 15%
 For Silk
Purchase above 5000 and avail discount of 5%
Purchase above 7500 and avail discount of 10%
 For Synthetic
Purchase above 5000 and avail discount of 15%
Purchase above 7500 and avail discount of 25%
Now if the customer is paying by Cash an additional 2% discount will be given to them. If
by Cheque no discount will be given, if payment mode is credit card 2.5% tax has to be
paid by the customer on the total purchase.
o Purchase () – The Salesman will enter the detail of the purchasing made by the customer and
will also enter the payment mode(CASH/CHEQUE/CREDIT CARD ) , and will invoke the
Calc_net() to calculate the net amount
o Show() – The function will generate the bill to the customer along with the purchase details and
the amount to be paid

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

29 Define a class PhoneBill in C++ with the following descriptions.


Private members:
CustomerName of type character array
PhoneNumber of type long
No_of_units of type int
Rent of type int
Amount of type float.
calculate( ) This member function should calculate the value of amount as Rent+ cost for the
units.Where cost for the units can be calculated according to the following conditions.
No_of_units Cost
First 50 calls Free
Next 100 calls 0.80 @ unit
Next 200 calls 1.00 @ unit
Remaining calls 1.20 @ unit
Public members:
* A constructor to assign initial values of CustomerName as “Raju”, PhoneNumber as
259461, No_of_units as 50, Rent as 100, Amount as 100.
* A function accept ( ) which allows user to enter CustomerName, PhoneNumber, No_of_units
And Rent and should call function calculate ( ).
* A function Display ( ) to display the values of all the data members on the screen.

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

31 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.

32 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.

33.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.

34.Considering the following specifications :


Structure name data type size
Name first char array 40
mid char array 40
last char array 60
Phone area char array 4
exch char array 4
numb char array 6
Class name Data Type
P_rec 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.

35.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.

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

You might also like