Govt. of Karnataka, Department of Technical Education
Diploma in Computer Science & Engineering
Subject: OOP with C++ Lab
Contact Hrs / week: 6 Total hrs: 96
1. Write a C++ program to find the largest of three numbers using inline function.
2. Write a C++ program to sort an array of integer in ascending order using a function called exchange( ) which accepts two integer arguments by reference.
3. Write a C++ program to implement function overloading in order to compute power(m,n) where i) m is double and n is int ii) m and n are int.
4. Create a 'DISTANCE' class with :
- feet and inches as data members
- member function to input distance
- member function to output distance
- member function to add two distance objects
Write a main function to create objects of DISTANCE class. Input two distances and output the sum.
5. Create a class called 'EMPLOYEE' that has
- EMPCODE and EMPNAME as data members
- member function getdata( ) to input data
- member function display( ) to output data
Write a main function to create EMP, an array of EMPLOYEE objects. Accept and display the details of at least 6 employees.
6. Create a class called 'TIME' that has
- three integer data members for hours, minutes and seconds
- constructor to initialize the object to zero
- constructor to initialize the object to some constant value
- member function to add two TIME objects
- member function to display time in HH:MM:SS format
Write a main function to create two TIME objects, add them and display the result in HH:MM:SS format.
7. Create a class 'COMPLEX' to hold a complex number. Write a friend function to add two complex numbers. Write a main function to add two COMPLEX objects.
8. Create a 'MATRIX' class of size m X n. Overload the ‘+’ operator to add two MATRIX objects. Write a main function to implement it.
9. Derive a class ‘MAT’ from MATRIX class created in program No. 8. Add a member function to overload ‘*’ operator to multiply two objects. (Single Inheritance)
10. Write a c++ program :
a) to illustrate multilevel inheritance.
b) to illustrate multiple inheritance.
11. Create a 'STRING' class which overloads ‘ = = ' operator to compare two STRING objects.
12. Write a C++ program to illustrate ‘this’ pointer and pointers to derived classes.
13. Create a base class called 'SHAPE' having
- two data members of type double
- member function get-data( ) to initialize base class data members
- pure virtual member function display-area( ) to compute and display the area of the geometrical object.
Derive two specific classes 'TRIANGLE' and 'RECTANGLE' from the base class. Using these three classes design a program that will accept dimension of a triangle / rectangle interactively and display the area.
14. Write a C++ program to read a list containing item name, item code and cost interactively and display the data in a tabular format as shown below:
The Name and Code are left-justified and the Cost is right-justified with a precision of 2 digits. Trailing zeros are shown. Fill the unused spaces with Hyphen
15. Design your own manipulator to provide the following output specification for printing money value:
1) 10 columns width
2) The character '$' at the beginning
3) Showing '+' sign.
4) Two digits precision
5) Filling of unused spaces with ' * '
6) Trailing zeros shown
16. Write a C++ program that uses a single file for both reading and writing the data.
17. A file contains a list of names and telephone numbers in the following form:
Name Tel. No.
Write a C++ program to read the file and output the list in the tabular format. The name should be left-justified and numbers right-justified. Use a class object to store each set of data.
18. Write an interactive, menu-driven program that will access the file created in program No.17 and implement the following tasks:
i) To determine the telephone numbers of the specified person.
ii) To determine the name if a telephone number is given.
iii) To update the telephone number whenever there is a change.
19. Write a C++ program that displays the size (in bytes) of a given file. The name of the file is specified as command line argument.
20. Define a function template for finding the minimum value contained in an array. Write main( ) function to find the minimum value of integer array and minimum value of floating point numbers in an array.
21. Write a class template to represent a generic vector. Include member functions to perform the following tasks:
1) To create the vector.
2) To modify the value of a given element.
3) To multiply the vector by a scalar value.
4) To display the vector in the form (10, 20, 30,…..)
Note: Execute programs in LINUX/Windows platform
Scheme of Examination
Writing two programs
Entering one program
Execution with result
| || |