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

C++Practical File

The document contains the output of 21 programs written in C++ to demonstrate various OOP concepts like classes, objects, inheritance, polymorphism, function overloading, templates, file handling, and exception handling. The programs create classes to represent bank accounts, employees, distances, complex numbers, circles, spheres, cylinders, students' results, shapes, and more. They perform operations like calculating salaries, adding objects, finding areas and volumes, reading/writing to files, and handling exceptions. Member functions, constructors, destructors, friend functions, virtual functions, and templates are also used.

Uploaded by

Sherodhi Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

C++Practical File

The document contains the output of 21 programs written in C++ to demonstrate various OOP concepts like classes, objects, inheritance, polymorphism, function overloading, templates, file handling, and exception handling. The programs create classes to represent bank accounts, employees, distances, complex numbers, circles, spheres, cylinders, students' results, shapes, and more. They perform operations like calculating salaries, adding objects, finding areas and volumes, reading/writing to files, and handling exceptions. Member functions, constructors, destructors, friend functions, virtual functions, and templates are also used.

Uploaded by

Sherodhi Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 31

Trinity Institute of Professional

Studies
(Affiliated to Guru Gobind Singh Indraprastha University, Delhi)
Ranked “A+” Institution by SFRC, Govt. of NCT of India
Recognized under section 2(f) of the UGC Act, 1956
NAAC Accredited “B++” Grade Institution

Practical File of
C++ Lab

Submitted to: - Submitted by:-


Ms. Sangita Vishwakarma Name: Sherodhi Sharma
Assistant Professor Enroll. No: 03724002020
(CS & IT Dept.) Class: BCA 3 rd Semester (2S)
Q 1. Define a class to represent the bank account. Include the following
details:-
DATA MEMBERS
- name of depositor
- account number
- type of account
- balance amount
MEMBER FUNCTIONS
- to assign initial values
- to deposit amount
- to withdraw amount after checking the balance
- to display name and balance
OUTPUT
Q 2. Write a program for creating a class employee that holds information
like empid, name, designation, HRA, basic salary & age. The class should
perform operations like entering the details of the employee, calculating
its total salary and printing all the employee details.
OUTPUT

Q 3. Write a program to show the concept of returning object to the


function.
OUTPUT

Q 4. Write a program to dynamically allocate & deallocate memory using


new & delete operator.

OUTPUT
Q 5. Write a program using inline function to find minimum of two values.

OUTPUT

Q 6. Write a program to calculate the area of rectangle, square, triangle &


circle using the concept of function overloading.
OUTPUT
Q 7. Write a program to perform addition of time in the hours and
minutes format using the concept of classes & objects.

OUTPUT
Q 8. Write a program to demonstrate the concept of default constructor,
parameterized constructor, copy constructor & destructor.
A) Default Constructor

OUTPUT

B) Parameterised Constructor
OUTPUT

C) Copy Constructor
OUTPUT

D) Destructor
OUTPUT

Q 9. Write a program to create class distance having data members - feet


and inch (a single object will store distance in form such as 5 feet 3 inch).
It contains a member function for taking input the data members and
another member function for displaying value of data members. Class
distance contains declaration of friend function add which accepts two
objects of class distance and returns object of class distance after
addition. Test the class using main function and objects of class distance.

OUTPUT
Q 10. Create a class polar having data members - radius and angle. It
contains member function for taking input data member & for displaying
value of data members. Class polar contains declaration of friend function
add which accepts two objects of class polar and returns object of class
polar after addition.
OUTPUT
Q 11. Write a program to design a class complex to represent complex
numbers. Perform addition & multiplication of complex numbers by
overloading + & * operators (use friend function).
OUTPUT

Q 12. Create a class circle with data member radius. Provide member
function to calculate area. Derive a class sphere from a class circle.
Provide member function to calculate volume. Derive class cylinder from
class sphere with additional data member for height and member
function to calculate volume.
OUTPUT
Q 13. Design three classes: student, exam & result. The student class has
data members - roll no, name of student. Create a class exam, which
contains data members - name of subject, minimum marks, maximum
marks, obtained marks for three subjects. Derive class result from both
the students and exam classes.
OUTPUT

Q 14. Define an abstract class shape which has a pure virtual function
area(). Derive two classes – rectangle & triangle that will implement the
area().
OUTPUT
Q 15. Write a program to demonstrate the concept of virtual function.

OUTPUT
Q 16. Write a program to copy the contents of one file to another.
OUTPUT

Q 17. Write a program to count the number of lines and words in a file
and display on the screen.
OUTPUT

Q 18. Write a program to enter a string, then write it to the file character
by character and read from file character by character.

OUTPUT
Q 19. Write a program to show the concept of exception handling which
throws a division by zero exception and catches it in the catch block.

OUTPUT
Q 20. Write a program that uses function template to find the largest and
smallest value.

OUTPUT
Q 21. Write a program that uses function template to swap two values.

OUTPUT

You might also like