# Object Oriented Programming Lab Manual

Here is the Complete Lab Practical file of Object Oriented Programming Language(OOPS) in C++. All the Practicals were Compiled and run in DEV CPP. This file covers the whole Syllabus of the student’s subject of OOPs studying in B.tech (2nd year). The file contains proper comments and proper outputs with coding.

This Practical File Consist of the below Practicals-:

01.Write a program to find out the factorial of a given number.

02.Write a program to check whether a given number is an Armstrong number or not.

03.Write a program to create a Fibonacci series.

04.Write a program that displays the menu of Dominos, receives order & displays their bill with tax using Class and objects.

05.Write a program for Class implementation by passing arguments in a member function.

06.Write a program using classes to show different operator overloading (i.e. Unary, Binary & left & right shift).

07.Write a program to show the use of Containership in a class.

08.Write a program to implement object slicing in a class.

09.Write a program to implement dynamic binding.

10.Raising a number n to a power p is the same as multiplying n by itself p times. Write a function calledpower ( ) that takes a double value for n and an int value for p, and returns the result as the double value. Use a default argument of 2 for p, so that if this argument is omitted, the number will be squared. Write a main ( ) function that gets values from the user to test this function.

11.Create the equivalent of a four function calculator. The program should request the user to enter a number, an operator, and another number. It should then carry out the specified arithmetical operation: adding, subtracting, multiplying, or dividing the two numbers. (It should use a switch statement to select the operation).Finally, it should display the result.When it finishes the calculation, the program should ask if the user wants to do another calculation. The response can be ‘Y’ or ‘N’.

12.Write a program that uses a structure called point to model a point. Define three points, and have the user input values to two of them. Then set the third point equal to the sum of the other two, and display the value of the new point.

13.A phone number, such as (212) 767-8900, can be thought of as having three parts: the area code (212), the exchange (767) and the number (8900). Write a program that uses a structure to store these three parts of a phone number separately. Call the structure phone. Create two structure. Variables of type phone. Initialize one, and have the user input a number for the other one. Then display both numbers.

14.Write a function called reversit( ) that reverses a 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.

15.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.

16.Create two classes DM and DB which store the value of distances. DM stores distances in 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 addition operation. The object that stores the results maybe a DM object or DB object, depending on the units in which the results are required. The display should be in the format of feet and inches or meters and centimeters depending on the object on display.

17.Imagine a tollbooth with a class called toll Booth. 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 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 displays the two totals. 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 non-paying car. Pushing special key should cause the program to print out the total cars and total cash and then exit.

18.Make a class Employee with a name and salary. Make a class Manager inherits from Employee. Add an instance variable, named Department of type string. Supply a method to String that prints the manager’s name, department, and salary. Make a class Executive inherits from Manager. Supply a method to String that prints the string “Executive” followed by the information stored in the Manager super class object. Supply a test program that tests these classes and methods.

19.Consider the following class definition

class father {
protected : int age;
public: father (int x) {age = x;}
virtual void iam ( )
{ cout < < “I AM THE FATHER, my age is : ”<< age<< end1:}};

Derive the two classes son and daughter from the above class and for each, define iam( ) to write our similar but appropriate messages. You should also define suitable constructors for these classes. Now, write a main( ) that creates objects of the three classes and then calls iam( ) for them. Declare pointer to father. Successively, assign addresses of objects of the two derived classes to this pointer and in each case, call iam( ) through the pointer to demonstrate polymorphism in action.

20.A hospital wants to create a database regarding its indoor patients. The information to store include

a) Name of the patient
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 to store the age of the patients. List the information about all the pediatric patients (less than twelve years of age).

21.Write a program that creates a binary file by reading the data for the students from the terminal. The data of each student consist of roll no., name ( a string of 30 or lesser no. of characters) and marks.

22.Create a class account that stores customer name, account number, and type of account. From this derive the classes cur_acct and sav_acct to make them more specific to their requirements. Include necessary member functions in order to achieve the following tasks:

a) Accept deposit from a customer and update the balance.
b) Display the balance.
c) Compute and deposit interest.
d) Permit withdrawal and update the balance.
e) Check for the minimum balance, impose a penalty, necessary and update the balance.
f) Do not use any constructors.

23.Create a base class called shape. Use this class to store two double type values that could be used to compute the area of figures. Derive two specific classes called triangle and rectangle from the base shape. Add to the base class, a member function 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 to suit their requirements.Using these three classes, design a program that will accept dimensions of a triangle or a rectangle interactively and display the area.