Professional Documents
Culture Documents
Instructions:
Assignment Group
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.