Oop CGL Practical Questions
Oop CGL Practical Questions
A1. Implement a class Complex which represents the Complex Number data type. Implement the
following operations:
1. Constructor (including a default constructor which creates the complex number 0+0i).
2. Overloaded operator+ to add two complex numbers.
3. Overloaded operator* to multiply two complex numbers.
4. Overloaded << and >> to print and read Complex Numbers.
A2. Imagine a publishing company that markets both book and audiocassette versions of its works.
Create a class publication that stores the title (a string) and price (type float) of a publication. From
this class derive two classes: book, which adds a page count (type int), and tape, which adds a playing
time in minutes (type float). Each of these three classes should have a getdata() function to get its data
from the user at the keyboard, and a putdata() function to display its data. Write a main() program to
test the book and tape classes by creating instances of them, asking the user to fill in data with
getdata(), and then displaying the data with putdata().
A3 Write a function in C++ to count and display the number of lines not starting with alphabet 'A'
present in a text file "STORY.TXT".
Example:
If the file "STORY.TXT" contains the following lines,
The roses are red.
A girl is playing there.
There is a playground.
An aeroplane is in the sky.
Numbers are not allowed in the password.
The function should display the output as 3.
A4. Write a C++ program create a calculator for an arithmetic operator (+, -, *, /). The program
should take two operands from user and performs the operation on those two operands depending
upon the operator entered by user. Use a switch statement to select the operation. Finally, display the
result. Some sample interaction with the program might look like this: Enter first number, operator,
second number: 10 / 3 Answer = 3.333333 Do another (y/n)? y Enter first number, operator, second
number: 12 + 100 Answer = 112 Do another (y/n)? n
A5.Write C++ Program with base class convert declares two variables, val1 and val2, which hold the
initial and converted values, respectively. It also defines the functions getinit( ) and getconv( ), which
return the initial value and the converted value. These elements of convert are fixed and applicable to
all derived classes that will inherit convert. However, the function that will actually perform the
conversion, compute( ), is a pure virtual function that must be defined by the classes derived from
convert. The specific nature of compute( ) will be determined by what type of conversion is taking
place.
A6. Create employee bio-data using following classes i) Personal record ii))Professional record iii)
Academic record Assume appropriate data members and member function to accept required data &
print bio-data. Create bio-data using multiple inheritance using C++
A7. Create User defined exception to check the following conditions and throw the exception if the
criterion does not met.
a. User has age between 18 and 55
b. User stays has income between Rs. 50,000 – Rs. 1,00,000 per month
c. User stays in Pune/ Mumbai/ Bangalore / Chennai
d. User has 4-wheeler
Accept age, Income, City, Vehicle from the user and check for the conditions mentioned
above. If any of the condition not met then throw the exception.
1
OOP & CGL
A8. Write a C++ program that creates an output file, writes information to it, closes the file and
open it again as an input file and read the information from the file.
A9. Using standard template library (STL) list container implement following member functions of
list class: empty, insert, merge, reverse, sort, Unique, using iterator
A10. Write a function template selectionSort. Write a program that inputs, sorts and outputs an int
array and a float array.
A11. Write a C++ program using command line arguments to search for a word in a file and replace it
with the specified word. The usage of the program is shown below.
A12. Create student database with appropriate data members that should use the following features of
object oriented programming in C++. Class, Object, array of objects, new, delete, default constructor
to initialize student class fields, parameterized constructor to set the values into the objects, access
specifiers, this pointer.