You are on page 1of 7

BSC/BCA-2ND

Object Oriented Programming (SCT-155/CAT-153)


Assignment-2
Date of allocation of Assignments 2 MAR 2019

Date of Submission of Assignments 14TH MAR 2019

Instructions:

1. You are required to do assignment according to your grouping A/B/C/D/E/F/G only.


2. You are required to use A4 size sheets and staple those sheets with University’s official
assignment front page.
3. The submitted programs code has to be compiled without errors by GNU C/C++ compiler or turbo C++
compiler.
4. Use comments and brief explanation of code.

Assignment Group

Assignment 1 18BCA1085 - 18BCA1102

Assignment 2 18BCA1103 - 18BCA1112

Assignment 3 18BCA1113 - 18BCA1125

Assignment 4 18BCA1126 - 18BCA1128

Assignment 5 18BCA1129 - 18BCA1154

Assignment 6 18BCA1156 - 18BCA 1195

Assignment 7 18BCA1201 - 18BCA3021 and


17BCA1489,1510,1571

S No. Group Assignment


1 Group A 1. An electricity board charges the following rates to domestic users to discourage large
consumption of energy :
For the first 100 units − 50 P per unit, Beyond 300 units − 60 P per unit If the total
cost is more than Rs.250.00 then an additional surcharge of 15% is added on the
difference. Create a class Electricity in which the function Bill computes the cost.
Define a derived class More_Electricity and override Bill to add the surcharge.
2. A class Person has name (char*) and age (int). Define the following constructors
a. default
b. with name as argument (assume age is 18)
c. with name and age as argument Also define the copy constructor.
3. Create a database of the following items of the derived class.
Name of the patient, sex, age, ward number, bed number, nature of illness, date of
admission. Design a base class consisting of data members : name of the patient, sex
and age ; and another base class consisting of the data members : bed number and
nature of the illness. The derived class consists of the data member ,date of
admission. Program should carry out the following methods
(i) Add a new entry. List the complete record.
4. A class Teacher has following specifications :
Private members : Name, Subject, Basic, DA, HRA,salary.
float Calculate( ) function computes the salary and returns it. Salary is sum of Basic,
DA and HRA.
Public members : Readdata ( ) function accepts the data values and invokes the
calculate function. Displaydata ( ) function prints the data on the screen.
5. Create a class Time that has separate int member data for hours, minutes and seconds.
One constructor should initialize this data to zero and another constructor initialize it
to fixed values. Write member function to display time in 12 hour as well as 24 hour
format. The final member function should add two objects of class Time. A main()
program should create three objects of class time, of which two are initialized to
specific values and third object initialized to zero. Then it should add the two
initialized values together, leaving the result in the third. Finally it should display the
value of all three objects with appropriate headings.
2 Group B 1. Consider a publishing company that markets both book and audio cassette version to
its works. Create a class Publication that stores the title (a string) and price (type
float) of a publication. Derive the following two classes from the above Publication
class: Book which adds a page count (int) and Tape which adds a playing time in
minutes (float). Each class should have get_data() function to get its data from the
user at the keyboard.
Write the main() function to test the Book and Tape classes by creating instances of
them asking the user to fill in data with get_data() and then displaying it using
put_data().
2. Student and Professor are two subclasses in which Student subclass displays the
name and CGPA (grade points in float) and Professor subclass displays the name and
number of publications (int). Write a main program using polymorphism to display
the data of one student and one professor.
3. Create a class Distance with feet and inch and with a print function to print the
distance. Write a non-member function max which returns the larger of two distance
objects, which are arguments. Write a main program that accepts two distance objects
from the user, compare them and display the larger.
4. A class worker with the following specifications :
Private members of class worker are wno , wname , hrwk, wgrate float (worker no,
worker name hour worked and wage rate per hour) totwage float (hrwk_ wgrate )
calcwg ( ) A function to find hrwk_ wgrate.
Public members of class worker: In_data ( ) a function to accept values for wno,
wname, hrwk, wgrate and invoke calcwg ( ) to calculate netpay. Out_data ( ) a
function to display all the data members on the screen.
5. A class Student has name (char name[20]) and age(int). Define the default
constructor, member functions get_data() for taking the name and age of the Student,
print() for displaying the data of Student.
3 Group C 1. A class Patient that stores the patient name (a string) and the disease (a string) of the
patient. From this class derive two classes : In_patient which has a data member
roomrent (type float) and Out_patient which has a data member OPD_charges (float).
Each of these three classes should have a nondefault constructor and a putdata()
function to display its data. Write a main() program to test In_ patient and Out_patient
classes by creating instances of them and then displaying the data with putdata().
2. A derived class having following items: name, age, rollno, marks, empcode and
designation. Design a base class student having data members as rollno, marks and
the another base class is employee having data members as empcode and designation.
These both base classes are inherited from a single base class person with data
members name and age. The program should carry out the required input( ) and
output( ) member functions for all.
3. Create a class Employee with a name and salary. Create a class Manager inherit from
Employee. Add an instance variable, named department, of type string. Supply a
method to toString that prints the manager’s name, department and salary. Make a
class Executive inherit from Manager. Supply a method to String that prints the string
“Executive” followed by the information stored in the Manager superclass object.
Supply a test program that tests these classes and methods

4. A hospital wants to create a database regarding its indoor patients. The information
to store include
a) Name of the patient
b) Date of admission
c) Disease
d) Date of discharge
Create a structure to store the date (year, month and date as its members). Create a
base class to store the above information. The member function should include
functions to enter information and display a list of all the patients in the database.
Create a derived class to store the age of the patients. List the information about all
the to store the age of the patients. List the information about all the pediatric patients
(less than twelve years in age).
5. Consider the following class hierarchy.create a base class employee (empcode emp
name). Derive the class manager (designation clubdues), scientist (department name
,publication) and labourer from employee class. Write C++ menu driven program
a) To accept the detail of ‘n’ employee.
b) To display the information.
c) To display all the scientist from “chemical department”.
4. Group D 1. A supermarket chain has asked you to develop an automatic checkout system. All
products are identifiable by means of a barcode and the product name. Groceries are
either sold in packages or by weight. Packed goods have fixed prices. The price of
groceries sold by weight is calculated by multiplying the weight by the current price
per kilo. Develop the classes needed to represent the products first and organize them
hierarchically. The Product class, which contains generic information on all products
(barcode, name, etc.), can be used as a base class.
a) The Product class contains two data members of type long used for storing barcodes
and the product name. Define a constructor with parameters for both data members.
Add default values for the parameters to provide a default constructor for the class.
In addition to the access methods setCode() and getCode(), also define the methods
scanner() and printer(). For test purposes, these methods will simply output product
data on screen or read the data of a product from the keyboard.
2. Create a class Time which contains:
– hours
– minutes
– second
Write a C++ program using operator overloading for the following:
i. .= = to check whether two Times are same or not.
ii. >> to accept the time.
iii. << to display the time .
3. A class has three data members: name, roll no, marks of 5 subjects and a member
function Assign() to assign the streams on the basis of table given below:
Avg. Marks Stream
90% or more Computers
80% - 89% Electronics
75% - 79% Mechanical
70% - 74% Electrical
4. Develop a program to convert the polar co-ordinates into rectangular coordinates.
(hint: polar co-ordinates(radius, angle) and rectangular co-ordinates(x,y) where x =
r*cos(angle) and y = r*sin(angle)).
5. Create the mark sheet of an university examination with the following items from the
keyboard : Name of the student Roll no. Subject name Subject code Internal marks
External marks Design a base class consisting of data members Name of the student
and Roll no. The derived class consists of the data members Subject name, Subject
code, Internal marks and External marks.
5 Group E 1. A function area() to compute the area of objects of different classes – triangle,
rectangle, square. Invoke these in the main program. Comment on the binding (static
or dynamic) that takes place in your program.
2. A class Deposit has data members such as principal, a rate of interest which is fixed
for all deposits and a period in terms of years. Write member functions to (i)
alter(float) which can change the rate of interest. (ii) interest() which computes the
interest and returns it. (iii) print() which prints data as shown below. Note that the
width of each column is 20.
Principal Year Interest
1100.00 1 100.00
3. A class Publication which has a title. Derive two classes from it – a class Book which
has an accession number and a class Magazine which has volume number. With these
two as bases, derive the class Journal. Define a function print() in each of these
classes. Ensure that the derived class function always invokes the base(s) class
function. In main() create a Journal called IEEEOOP with an accession number 681.3
and a volume number 1. Invoke the print() function for this object.

4. Create a program that calculates the cost of construction for building a house for
this,derive a class publicly from three base classes cement,steel and wood. The
requirements for building a house will be 500 bags of cement where each bags costs
rs150, three tons of steel costing rs 28000 per ton and so on cubic feet of wood costing
rs 1500 per cubic foot.
5. Assume that the cell users are two kinds – those with a post paid option and those
with a prepaid option. Post paid gives a fixed free talk time and the rest is computed
at the rate of Rs.1.90 per pulse. Prepaid cards have a fixed talk time. Define a class
Cell_user as a base class and derive the hierarchy of classes. Define member
functions and override them wherever necessary to retrieve the talk time left for each
user print the bill in a proper format containing all the information for the post paid
user.
6. Group F 1. Operators such as >>, which read input from the keyboard, must be able to convert a
series of digits into a number. Write a program that does the same thing. It should
allow the user to type up to six digits, and then display the resulting number as a type
long integer. The digits should be read individually, as characters, using getche().
2. Write a function called reversit() that reverses a C-string (an array of char). Use a for
loop that swaps the first and last characters, then the second and next-to-last
characters, and so on. The string should be passed to reversit() as an argument. Write
a program to exercise reversit(). The program should get a string from the user, call
reversit(), and print out the result. Use an input method that allows embedded blanks.
Test the program with Napoleon’s famous phrase, “Able was I ere I saw Elba.” Create
a class called employee that contains a name (an object of class string) and an
employee number (type long). Include a member function called getdata() to get data
from the user for insertion into the object, and another function called putdata() to
display the data. Assume the name has no embedded blanks. Write a main() program
to exercise this class. It should create an array of type employee, and then invite the
user to input data for up to 100 employees. Finally, it should print out the data for all
the employees.
3. Start with a program that allows the user to input a number of integers, and then
stores them in an int array. Write a function called maxint() that goes through the
array, element by element, looking for the largest one. The function should take as
arguments the address of the array and the number of elements in it, and return the
index number of the largest element. The program should call this function and then
display the largest element and its index number.
4. A matrix is a two-dimensional array. Create a class matrix that provides the same
safety feature as the array class that is, it checks to be sure no array index is out of
bounds. Make the member data in the matrix class a 10-by-10 array. A constructor
should allow the programmer to specify the actual dimensions of the matrix
(provided they’re less than 10 by 10). The member functions that access data in the
matrix will now need two index numbers: one for each dimension of the array.
5. Create a class called bMoney. It should store money amounts as long doubles. Use
the function mstold() to convert a money string entered as input into a long double,
and the function ldtoms() to convert the long double to a money string for display.
You can call the input and output member functions getmoney() and putmoney().
Write another member function that adds two bMoney. Just add the long double
member data amounts in two bMoney objects. Write a main() program that
repeatedly asks the user to enter two money strings, and then displays the sum as a
money string.
7 Group G 1. Model this tollbooth with a class called tollBooth. The two data items are a type
unsigned int to hold the total number of cars, and a type double to hold the total
amount of money collected. A constructor initializes both of these to 0. A member
function called payingCar() increments the car total and adds 0.50 to the cash total.
Another function, called nopayCar(), increments the car total but adds nothing to the
cash total. Finally, a member function called display() displays the two totals. Make
appropriate member functions const. Include a program to test this class. This
program should allow the user to push one key to count a paying car, and another to
count a nonpaying car. Pushing the Esc key should cause the program to print out the
total cars and total cash and then exit.
2. Create a class called time that has separate int member data for hours, minutes, and
seconds. One constructor should initialize this data to 0, and another should initialize
it to fixed values. Another member function should display it, in 11:59:59 format.
The final member function should add two objects of type time passed as arguments.
A main() program should create two initialized time objects and one that isn’t
initialized. Then it should add the two initialized values together, leaving the result
in the third time variable. Finally it should display the value of this third variable.
Make appropriate member functions const.
3. Create a class that includes a data member that holds a “serial number” for each
object created from the class. That is, the first object created will be numbered 1, the
second 2, and so on. To do this, you’ll need another data member that records a count
of how many objects have been created so far. Then, as each object is created, its
constructor can examine this count member variable to determine the appropriate
serial number for the new object. Add a member function that permits an object to
report its own serial number. Then write a main() program that creates three objects
and queries each one about its serial number. They should respond I am object
number 2, and so on.
4. Create a class Polar that represents the points on the plain as polar coordinates (radius
and angle). Create an overloaded +operator for addition of two Polar quantities.
“Adding” two points on the plain can be accomplished by adding their X coordinates
and then adding their Y coordinates. This gives the X and Y coordinates of the
“answer.” Thus you’ll need to convert two sets of polar coordinates to rectangular
coordinates, add them, then convert the resulting rectangular representation back to
polar.
5. Imagine a tollbooth at a bridge. A Car passing by the booth is expected to pay a toll.
The tollbooth keeps the track of the number of cars that gone by and the total amount
of cash collected. Create a class tollbooth with the data members as:- -total number
of cars passed. -total toll collected. Write necessary member functions:
a) a constructors that initializes both data members to zero.
b) paying car(): when any car passes through the tollbooth, that much toll gets added
into total toll collected and total number of cars passed is incremented by one.
c) nonpaying car(): increments the car total but adds nothing to cash total.
d) display (): displays total no. of cars passed and the total amount collected.

You might also like