C++ Practical File (3sem)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 50

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

Session (2020-2023)
A practical file on
C++ Lab
(Paper Code: - BCA 253)

Submitted to: - Submitted by: -


Ms. Sangita Vishwakarma Name: Bhavishya
Assistant Professor Enroll. No.: 00142402020
(CS & IT Dept.) Class: - BCA 3(2S)
INDEX
S No. Programs Page No. Signature
1 Define a class to represent the bank account. 1-3
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

2 Write a program for creating a class 4-5


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.

3 Write a program to show the concept of 6


returning object to the function.

4 Write a program to dynamically allocate & 7


deallocate memory using new & delete
operator.

5 Write a program using inline function to 8


find minimum of two values.

6 Write a program to calculate the area of 9


rectangle, square, triangle & circle using the
concept of function overloading.

7 Write a program to perform addition of 10-11


time in the hours and minutes format using
the
concept of classes & objects.

8 Write a program to demonstrate the concept 12-15


of default constructor, parameterized
constructor, copy constructor & destructor.

9 Write a program to create class distance 16-17


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.

10 Create a class polar having data members - 18-19


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.

11 Write a program to design a class complex 20-21


to represent complex numbers. Perform
addition & multiplication of complex
numbers by overloading + & * operators
(use
friend function).

12 Create a class circle with data member 22-23


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.

13 Design three classes: student, exam & result. 24-25


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.

14 Define an abstract class shape which has a 26-27


pure virtual function area(). Derive two
classes – rectangle & triangle that will
implement the area().

15 Write a program to demonstrate the concept 28-29


of virtual function.

16 Write a program to copy the contents of one 30-31


file to another.

17 Write a program to count the number of 32-33


lines and words in a file and display on the
screen.

18 Write a program to enter a string, then 34


write it to the file character by character
and read
from file character by character.

19 Write a program to show the concept of 35


exception handling which throws a division
by
zero exception and catches it in the catch
block.

20 Write a program that uses function template 36


to find the largest and smallest value.

21 Write a program that uses function template 37-38


to swap two values.
C++ Programs
Q1. 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

Program
2
Output
Q2. 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.
Program
Output
Q3. Write a program to show the concept of returning object to the function.
Program

Output
Q4. Write a program to dynamically allocate & deallocate memory using new
& delete operator.
Program

Output
Q5. Write a program using inline function to find minimum of two values.
Program

Output
Q6. Write a program to calculate the area of rectangle, square, triangle &
circle using the concept of function overloading.

Program
Output

Q7. Write a program to perform addition of time in the hours and minutes
format using the concept of classes & objects.
Program
Output
Q8. Write a program to demonstrate the concept of default constructor,
parameterized constructor, copy constructor & destructor.
#1 Default Constructor: -
Program

Output
#2 Parameterized Constructor: -
Program
Output
#3 Copy Constructor

Program
Output
#4 Destructor
Program

Output
Q9. 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.

Program
Output
Q10. 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.

Program
Output
Q11. Write a program to design a class complex to represent complex
numbers. Perform addition & multiplication of complex numbers by
overloading + & * operators (use friend function).

Program
Output
Q12. 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.
Program
Output
Q13. 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.

Program
Output
Q14. Define an abstract class shape which has a pure virtual function area().
Derive two classes – rectangle & triangle that will implement the area().
Program
Output
Q15. Write a program to demonstrate the concept of virtual function.
Program
Output
Q16. Write a program to copy the contents of one file to another.
Program
Output

Q17. Write a program to count the number of lines and words in a file and
display on the screen.
Program

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

Program
Output
Q19. Write a program to show the concept of exception handling which
throws a division by zero exception and catches it in the catch block.
Program
Output

Q20. Write a program that uses function template to find the largest and
smallest value.
Program
Output

Q21. Write a program that uses function template to swap two values.
Program

Output

You might also like