cpp lab manual
cpp lab manual
Lab Assignment
Object Oriented Programming with C++
Prepare a lab copy with the corresponding answer. You can use any binding copy. A4 loose sheet
(stapled together) is NOT allowed. If your paper is found to be plagiarized from some other students,
it will be recorded for necessary action and reflects on your internal marks.
Note: Hand written only, no typing is accepted. Submit the hard copy to my cabin (Cabin No-221,
near the classroom 219) on or before 23 April, 2025. Attempt all.
1. What kinds of things can become objects in OOP?
2. How does a main() function in C++ differ from main() in C?
3. What will happen when you run the following code?
#include<iostream.h>
void main()
{ int i=10,j=5;
int modResult=0;
int divResult=0;
modResult=i%j;
cout<<modResult<<” “;
divResult=i/modResult;
cout<<divResult;
}
4. Write a program to display the following output using a single cout statement.
Maths=90
Physics=77
Chemistry=69
5. Write a C++ code that will ask for a temperature in Fahrenheit and display it in Celsius. Do
it using a class called temp and member functions.
6. In C++, a variable can be declared anywhere in the scope. What is the significance of this
feature?
7. What are the applications of the scope resolution operator (::) in C++?
8. What is a reference variable? Write a function using reference variables as arguments to
swap the values of a pair of integers.
9. Write a C++ code to compute the area of a triangle and a circle by overloading the area()
function.
10. Define a class to represent a bank account. Include the following members:
Data Members-
a)Name of the depositor
b)Account number
c)Type of account
d)Balance amount in the account
Member functions-
a)To assign initial values
b)To deposit an amount
c)To withdraw an amount after checking the balance
d)To display name and balance
Write a main() program to test the program.
11. 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 C++ code 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 may be a DM
object or DB object, depending on the units in which the results are required.
12. Describe the importance of destructor. Explain its use with the help of an example.
13. Write a C++ code to find a prime number using constructor.
14. When is a friend function compulsory? Give an example.
15. Describe the syntax of multiple inheritance. When do we use such an inheritance?
16. Class D is derived from class B. The class D does not contain any data members of its
own. Does the class D require constructors? Explain your answer.
17. When do we make a virtual function “pure”? What are the implications of making a function
a pure virtual function?
18. Using the concept of pointers write a function that swaps private data values of two objects
of the same class type.
19. Write a C++ code to calculate the factorial of an integer using pointer to function concept.
20. Two files named ‘Source1’ and ‘Source2’ contain sorted list of integers. Write a program
that reads the contents of both the files and stores the merged list in sorted form in a new
file named ‘Target’.
21. Write a class template that shows the working of a calculator.
22. Write a program containing a possible exception. Use a try block to throw it and a catch
block to handle it properly.
23. Write a program that demonstrates how certain exception types are NOT allowed to be
thrown.
24. Write a program to calculate the area of a rectangle using an inline function.
25. Write a program to overload multiply() function for three different output.
26. Write a program to find the sum of three integers using function template.
27. Write a program involving working with a single file. Show how a file can be opened and
closed.
28. Use an inline function that converts the temperature given in degree Celsius into degrees
Fahrenheit.
29. Explain the concept of iterators in STL and how they are used.
30. Design a UML diagram for the following code-
class vit
{ int age;
string name;
public:
void set(int a, string n)
{ age=a;
name=n;
}
string get_name()
{ return name;
}
};
31. Design a UML class diagram that for a bank management system (BMS). The diagram
should include the following classes: Customer, Bank, ATM, Account, and ATM Transaction.
Each class should have specific attributes and operations defined. For example the
Customer class should have attributes and methods for deposit, withdrawal, and checking
the balance. Similarly, define the attributes and functionalities for the other classes as well.
32. Write a program to explain the working of copy constructor.
33. Write a program to explain the working of hybrid inheritance.
34. Write a program to explain the working of pure virtual function.
_______________THE END___________