Object Oriented Methodology & Programming (Using C++) : Laboratory Assignments of
Object Oriented Methodology & Programming (Using C++) : Laboratory Assignments of
Object Oriented Methodology & Programming (Using C++) : Laboratory Assignments of
Books:
Text Book:
1. Bjarne Stroustrup, The C++ Programming Language, Addison Wesley
2. Robert Lafore, Object-Oriented Programming in C++, Fourth Edition, SAMS
3. Dale and Weems , Programming and Problem solving with C++, Jones and Bartlett,
2010
Reference Book
1. E . Balaguruswami, Object Oriented Programming C++, TMH
2. Steve Oualline, Practical C++ Programming O'Reilly & Associates, Inc.
Assignment I
Class, object, Function
1. Write an inline function to obtain largest of three numbers.
2. Write a function called hms_to_secs() that takes three int valuesfor hours, minutes, and
secondsas arguments, and returns the equivalent time in seconds (type long). Create a
program that exercises this function by repeatedly obtaining a time value in hours,
minutes, and seconds from the user (format 12:59:59), calling the function, and
displaying the value of seconds it returns.
3. 3. Define a class to represent a bank account. It contains
Data Members:
Name of the depositor
Account Number
Type of account
Balance
Member Functions:
To assign initial values
To deposit an amount
To withdraw an amount < amount available
Display the name and balance.
4. Create a bank account by supplying a user id and password.
Login using their id and password.
Quit the program.
Now if login was successful the user will be able to do the following:
Withdraw money.
Deposit money.
Request balance.
For simplicity take the matrix as 3X3 and the vector as 1X3.
1,2,3,6, and 9 are basic category and 4,5,7 and 8 are intellectual category
Assignment II
Constructor
1. Write a C++ program to add two complex numbers.
i) The class Complex contains three constructors.
a) One with no parameter. (Used for the object for storing result.)
b) With one parameter(Same value for real and imaginary part)
c) With two parameters.
and
ii) Two friend functions
a) One to add two complex number by taking two reference variables of class
complex and returning another reference.
b) To display the result.
2. A Bank gives 4% interest on current account and 6% interest on savings account. An
additional 3% interest is provided for savings duration of 5 years and above. Using dynamic
initialization of constructor write banking program using C++.
Assignment III
Operator Overloading and Type Conversion
1. Check whether a number is even or odd by overloading ! operator.
2. ii) Check whether a number is prime or not by overloading -- operator
[Hints Use the concept of overloading ! operator].
3. Add two complex number by overloading + operator
a) Using Member function.
b) Using Friend Function.
4. Class Distance consists of length in feet and inches. Class Distance contains
i) one default constructor
ii)
iii)
iv)
Assignment IV
Inheritance
1. Class student contains roll number, name and course as data member and Input_student
and display_student as member function. A derived class exam is created from the class
student with publicly inherited. The derived class contains mark1, mark2, mark3 as
marks of three subjects and input_marks and display_result as member function. Create
an array of object of the exam class and display the result of 5 students.
2. Try the same program with privately inheritance.
3. Write a program where derived class is a friend of base class.
4. Test whether the Base class be a friend of Derived class.
5. Class user contains data member name and age. A constructor with two arguments is
used to assign name and age.
User are of two types a) Student and b) Teacher.
class Student contains data member i)course ii) Roll Number and iii)Marks and method
display() to display data related to student.
class Teacher contains data member i) subject_assigned (May take this as an array) ii)
contact_hour and method display() to display data related to teacher.
Implement this program using base class constructor in derived class.
6. Base class count contains a variable c. It contains a no argument constructor, one
argument constructor, a method to return c and a operator overloading function for
++.
Derived class counter access the value of c from base class constructor through its
constructor and a operator overloading function for --.
7. Class Student contains data member Name, roll as protected.
Method get() to name & roll and display() to display name and roll.
Class Mark is publicly inherited from Student.
It contains protected data member mark1,mark2 i.e. marks of two subjects & get_marks()
and display_marks() as public.
Class Result is publicly inherited from Mark.
It contains private data member total and two public method cal_result( ) to calculate
total and display_result() with comment whether the student has passed or not.
8. Rewrite the program in 7 with method overriding. Take the methods in all classes are
get() and display().
9. . Write a C++ program to implement the following level of inheritance.
class Examination and Extracurricular are inherited from Student and Result is multiply
inherited from Examination and Extracurricular.
13. Test whether the diamond problem exist is Friend Class.
Assignment V
Pointer, Virtual Function and Polymorphism
1. Write a program using this pointer to find out the least number obtained among three
subjects. Use ternary operator.
2. Class polygon contains data member width and height and public method set_value() to
assign values to width and height.
class Rectangle and Triangle are inherited from polygon class. Both the classes
contain public method calculate_area() to calculate the area of Rectangle and Triangle.
Use base class pointer to access the derived class object and show the area calculated.
3. Write a program to create a class shape with functions to find area of and display the
name of the shape and other essential component of the class. Create derived classes
circle, rectangle and trapezoid each having overridden functions area and display. Write a
suitable program to illustrate virtual functions.
4. Write a program with Student as abstract class and create derive classes Engineering,
Medicine and Science from base class Student. Create the objects of the derived classes
and process them and access them using array of pointer of type base class Student.
Assignment VI
Exception Handling
1. Two integers are taken from keyboard. Then perform division operation.
a) A try block to throw an exception when a wrong type of data is keyed.
b) When division by zero occurs.
write appropriate catch block to handle the exception thrown.
2. Design stack and queue classes with necessary exception handling.
Assignment VII
Template
1. Design a class Template to find the largest among three numbers using ternary
operator.
2. Design a class Template to implement stack.
3. Write a template to sort an array by ascending order.
4. Design a template to find the largest among three numbers of different data types.
5. Design a template for calculating xy where x may be integer or float (not char or
string) and y must be integer. Put appropriate alert for wrong data type.
6. Design a template to show that integer/integer is integer by if any one of them is
float it returns float.