0% found this document useful (0 votes)
29 views

Oop Lop New It

Uploaded by

Suresh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Oop Lop New It

Uploaded by

Suresh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

GURU TEGH BAHADUR INSTITUTE OF TECHNOLOGY

OBJECT ORIENTED PROGRAMMING LAB (CIC -211)


LIST OF PRACTICALS

CLASSES AND OBJECTS


1. A class student has three data members: name, roll, marks of 5 subjects and member functions to assign streams
on the basis of the table given below:
Average marks Stream
96% and more computer science
91% - 95% electronics
86% - 90% mechanical
81% - 85% electrical
76% - 80% chemical
71% - 75% civil
Declare the class student and define the member functions.

2. Declare a class to represent bank account of 10 customers with the following data members:
Name of depositor
Account number
Type of account (s for savings, c for current)
Balance amount
The class also contains the following member functions:
A. To initialize
B. To deposit money
C. For withdrawal (if the deposit after withdrawal is greater than 10000)
D. To display the data members

3. Define a class employee with the following specifications:

Private members of class employee:


Empno
Ename
Basic
Hra = 10% of basic
Da = 20% of basic
Page 1 of 6
Netpay
Calculate()
Public members of class employee:
Havedata()
Dispdata()

4. Develop a Program to enter traveling details and tell number of buses required using classes and objects.
5. Demonstrate use of scope resolution operator using multiple initializations of the variable.
6. Write a program for multiplication of two matrices using OOP.
7. Use inline functions and macros to obtain the largest of three numbers.
8. Register the entrance of people in the auditorium using static class data
9. Write a program to find the greatest of two given numbers in two different classes using friend function.
10. Create a class called Date, with integer data members for day, month and year. The class comprises of member
functions
(1) To display date in DD/MM/YYYY format.
(2) To subtract an integer from date object
(3) To subtract one date from another.

11. A hospital wants to create a database regarding its indoor patients. The information to store includes
(a) Name of patient
(b)Date of admission
(c)Disease
(d)Date of discharge
Use the Date class created in previous program to store the date. The patient class comprises of The member
functions to enter the information and display the list of all patients in database

CONSTRUCTORS AND DESTRUCTORS


12. Define a class Serial with following specifications:
Private members:
serialCode integer
title 20 characters
duration float
noOfEpisodes integer
Public member function of class Serial:

Page 2 of 6
1. A constructor to initialize duration as 30 and noOfEpisodes as 10
2. newSerial () to accept values of serial code and title
3. otherEntries () to assign value to duration and noOfEpisodes with the help of values passed to the function
4. dispData () to display the data members on the screen

13. Considering the following specifications:

Structure name
Name
First char [40]
Mid char [40]
Last char [60]
Structure name
Phone
Area char [4]
Exch char [4]
Numb char[6]
Class name, p_rec with data mambers as objects of structure name and phone with member functions and
constructor.
14.Define a class student with the following specifications:

Private members:
Roll_no
Name
Class_st
Marks
Percentage
Calculate()
Public members:
Readmarks() which reads the marks and invokes the calculate function
Displaydata() which prints the data.

15. Declare a class String. It must have constructors which allow definition of object in the following form (the class
string has data members str of type char *):
String name1;//str point to NULL
String name2=”ABC”;//one argument constructor is invoked

Page 3 of 6
String name3=name2;//one argument constructor taking string object
Writ a program to model string class and to manipulate its objects.The destructor must release memory allocated to
str data members by its counter part.

16. Write a program to perform addition of two complex numbers using constructor overloading. The first
constructor which takes no argument is used to create objects which are not initialized, second which
takes one argument is used to initialize real and imag parts to equal values and third which takes two
argument is used to initialized real and imag to two different values.

INHERITANCE
17. Create 2 classes namely student and exam. Make the derived class result to inherit the details of total- marks and
students through multilevel inheritance.
18. Implement the above program using multiple inheritance.
19. Define a class to store coordinates of a point with member function to read the coordinates and display the
coordinates. Define a derived class with the additional capability to store the distance of the point from the origin.
Write the additional member functions for the same. Write a program, using the classes defined above to read
coordinates of a point and find its distance from the origin.
20. Imagine a publishing company that markets both book and audio cassette versions of its works. Create a class
publication that stores the title (a string) and price (type float) of a publication from this class derived two classes :
book, which adds a page count (type int) ; and tape , which adds a playing time in minutes (type float ). Each of these
classes should have getdata() and a putdata(). Write a main program to test the book and tape classes by creating
instances of them and asking a user to fill in their data with getdata () and displaying the data with putdata().
21. Use Patient class created above and create a derived class to store the age of patients. Display the list of all
pediatric patients less than 12 yrs. of age by using member function in the derived class.

COMPILE TIME AND RUN TIME POLYMORPHISM


22. Design a program for calculating the area of a triangle, rectangle and circle by taking shape as the base class using
virtual functions.
23. Create a class called List with two pure virtual function store() and retrieve().To store a value call store and to
retrieve call retrieve function. Derive two classes stack and queue from it and override store and retrieve.
24. Write a program to overload function area() to find area of triangle using heroes formula, area of rectangle , area
of square and area of circle.

Page 4 of 6
OPERATOR OVERLOADING
25. Write a program overloading unary operator to increment date.
26. Write a program overloading arithmetic operators to add two complex numbers.
27. Implement a class string containing the following functions:
- Overload + operator to carry out the concatenation of strings.
- Overload = operator to carry out string copy.
- Overload <= operator to carry out the comparison of strings.
- Function to display the length of a string.
- Function tolower( ) to convert upper case letters to lower case.
- Function toupper( ) to convert lower case letters to upper case.
28. Write a program overloading new and delete operator.

FILE HANDLING
29. Program to read and write data in a text file using fstream only.
30. Program to display word by word data from file.
31. Program to count total number of words and spaces in a file.
32. Write a program to perform the deletion of white spaces such as horizontal tab, vertical tab, space ,line feed
,new line and carriage return from a text file and store the contents of the file without the white spaces on
another file.
33. Write a program to read the class object of student info such as name , age ,sex ,height and weight from the
keyboard and to store them on a specified file using read() and write() functions. Again the same file is opened for
reading and displaying the contents of the file on the screen.
34. Program to enter data into Hotel file using class, and count the total number of customers.
35. Program on merging of records from 2 files.

TEMPLATES
36. Write a program for creating doubly linked list. The doubly linked list class must be of template type.
37. Write a program to define the function template for calculating the square of given numbers with different data
types.
38. Write a program to demonstrate the use of special functions, constructor and destructor in the class template.
The program is used to find the bigger of two entered numbers.

Page 5 of 6
EXCEPTION HANDLING
39. Write a program to raise an exception if any attempt is made to refer to an element whose index is beyond the
array size.
40. Write a program to develop a User Defined Exception.

Page 6 of 6

You might also like