oocp
TRANSCRIPT
-
8/3/2019 OOCP
1/3
LAB-3
1. Create a class 'Triangle' with a char member variable, a constructor with one charargument which initializes the character argument. If no argument is specified, it should
by default initialize the char member to *. Write a member function print_tri whichprints triangle of given char. Take the no of lines as argument to print_tri function.
2. Write a class 'Complex' that has two member data real and imaginary. Do theappropriate operations given below. Use data given by the user. Write necessary member
function.
(a) write overloaded constructors for three different kind of object creation.
Object1 (), /* set real=0.0 and imaginary=0.0*/Object2 (2.3), /* set imaginary=0.0*/
Object3 (2.3, 6.7)
(b) Write a friend function addition, which adds two objects of the class complex and
returns the object.
(c) Write a copy constructor for the class COMPLEX.
3. Create a class 'countMember' with required data member and member function. Write
a program to print total number of object created for class count. Use static data member
and static member function.
4. Create a class 'countTime' that has separate int member data for hours, minutes and
seconds. One constructor should initialize this data to 0 and another should initialize it tofixed values. A member function should display it as hh:mm:ss format. The final member
function should add two objects of type time passed as argument. A main() programshould create two initialized time objects, and one that isn't initialized. Then it should add
the two initialized values together, leaving the result in third time variable. Finally it
should display the value of its third variable.
5. Create two classes DM and DB which store the value of distances. DM stores distancein meters and centimeters and DB in feet and inches. Write a program that can read
values for the class objects and add one object of DM with another object of DB. Use a
friend function to carry out the additon operation. The object that stores the result may be
a DM object or DB object, depending on the units in which the results are required. Thedisplay should be in the format of feet and inches or meters and centimeters depending on
the object on display. [1 meter = 100 cm = 39.37 inch = 3.28 feet ]
LAB-4
-
8/3/2019 OOCP
2/3
1. Create a class Distance with data as Inch and Feet and develop member function to
insert values, display distance and overload and + operator to perform following
operation.(a) d3 = d1 + d2.
(b) d4 = d1 - d2
(c) d5 = d1 + 10.5(d) d6 = 10.5 + d1
2. Define a class string with string as a data member. Write a program to overload , =
= operator to compare the two object of string class. [do not use any built in function for
string comparison]
3. Create a class FLOAT that contains one float data member. Overload all the fourarithmetic operators using friend function, so that they operate on the objects of FLOAT.
LAB-5
1. Define a class Ton having data member ton and another class KG having kilogram and
gram as data members. Write a program to convert object of ton class to KG class andvice versa.
2. Write a program that consists of two classes TIME12 and TIME24. The first one
maintains time on as 12 hour basis, whereas the other one maintaining time on a 24 hour
basis. Provide conversion function to carry out the conversion from object of one type to
another.
LAB-6
1) Define a class 'Employee' which has first name and last name as the data members.Derive a class 'Hourly-Workers' with wage and hours as data members and function
get_pay () which calculates and returns total_pay. Write a program to input data of a
particular employee and print it with total pay.
2. Create a class Institute (name, address, city). Derive a class Branch (name, total no of
students, no of faculties) from Institute.From Branch derive a class Student (name, regno, aggregate, address, city). Write appropriate member functions to display data of a
particular student.
3. Create a class student as a virtual base class with no. and name as Data member.
Derive test and sports classes from students with marks of three subjects and score
respectively. Derive a result class from test and sports with total no. of marks and score insports. Print output.
-
8/3/2019 OOCP
3/3
4. Define a base class called Shape. Use this class to store two double type values that
could be defined to compute the area of figures. Derive two specific classes called
Triangle and Rectangle from the base class Shape. Add to the base class, a memberfunction get_data () to initialize base class data members and another member function
display_area () to compute and display the area of figures. Make display_area () as a
virtual function and redefine this function in the derived classes. Using these three classesdesign a program that will accept dimensions of atriangle or rectangle and display the
area.