You are on page 1of 10

Assignment -II

S No. Group Assignment

1 Group A
(16BCE1002 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
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.
(ii)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. Create a class named Complex Number with the appropriate data
(16BCE1013 members and constructors. Include member functions (defined inside
the class) to perform the following operations:
Inputting a complex number
Outputting a complex number
Arithmetic operations on two complex numbers.
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
(worker no, worker name, hour worked and wage rate per hour)
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
(16BCE1025 (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 managers 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 (empcodeemp 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


4. Group D 1. A supermarket chain has asked you to develop an automatic

(16BCE1041 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:

Write a C++ program using operator overloading for the
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

Avg. Marks Stream

90% or more Computers

80% - 89% Electronics

75% - 79% Mechanical

70% - 74% Electrical

4. Create a class rational which represents a numerical value by two
double values- NUMERATOR & DENOMINATOR. overload
following operators for rational class:
Overload + operator to add two rational number.
Overload >> operator to enable input through cin.
Overload << operator to enable output through cout

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
(16BCE1056 1. A function area() to compute the area of objects of
-1067) 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

(i) retrieve the talk time left for each user.

(ii) 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
(16BCE1068 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,
callreversit(), and print out the result. Use an input method that
allows embedded blanks. Test the program with Napoleons 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
theyre 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. 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.

7 Group G 1. Create a class called bMoney. It should store money amounts as long
(16BCE1076 doubles. Use the function mstold()to convert a money string entered
-1471) 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 bMoneyobjects. Write a main()
program that repeatedly asks the user to enter two money strings,
and then displays the sum as a money string.

2. Create a class rational which represents a numerical value by two

double values- NUMERATOR & DENOMINATOR. Include the
following public member Functions:
Constructor with no arguments (default).
Constructor with two arguments.
Void reduce ( ) that reduces the rational number by eliminating the
highest common factor between the numerator and denominator.
Add two rational numbers by mean of member function.
Write a main ( ) to test all the functions in the class.

3. Define a class Rectangle which has a length and a breadth. Define

the constructors and the destructor and member functions to get the
length and the breadth. Write a global function which creates an
instance of the class Rectangle and computes the area using the
member functions.
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 youll 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.