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

CPP Final Programs

The document contains descriptions of multiple C++ programming problems organized into different sections: Simple Program, Class, Inline Function, Constructor and Destructor, Static data member and Static member function, Operator Overloading, Function Overloading, and Virtual Function. The problems involve writing C++ code to define classes with various data members and member functions, overloading operators and functions, using constructors and destructors, and demonstrating polymorphism with virtual functions.

Uploaded by

aditya borude
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
170 views

CPP Final Programs

The document contains descriptions of multiple C++ programming problems organized into different sections: Simple Program, Class, Inline Function, Constructor and Destructor, Static data member and Static member function, Operator Overloading, Function Overloading, and Virtual Function. The problems involve writing C++ code to define classes with various data members and member functions, overloading operators and functions, using constructors and destructors, and demonstrating polymorphism with virtual functions.

Uploaded by

aditya borude
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Simple Program

1. Write a C++ program to check if number is prime or not.


2. Write a C++ program to calculate following series: (1) + (1+2) + (1+2+3) +
(1+2+3+4) + ... +(1+2+3+4+...+n)
3. Write a C++ program to display factors of a number

Class
1. Write the definition for a class Cylinder that contains data members radius
and height. The class has the following member functions:
a. void setradius(float) to set the radius of data member.
b. void setheight(float) to set the height of data member.
c. float volume( ) to calculate and return the volume of the cylinder.
Write a C++ program to create cylinder object and display its volume.
2. Create a class Time which contains data members as: Hours, Minutes and
Seconds. Write a C++ program to perform following necessary member
functions:
a. To read time
b. To display time in format like: hh:mm:ss
c. To add two different times (Use Objects as argument)
3. Write a C++ program to interchange values of two integer numbers (use call
by reference).
4. Write a C++ program to define a class Bus with the following specifications:
Bus No, Bus Name, No of Seats, Starting point, Destination .Write a menu
driven program by using appropriate manipulators to
a. Accept details of n buses.
b. Display all bus details.
c. Display details of bus from specified starting point to destination

Inline Function
1. Write a C++ program to print area of circle, square and rectangle using inline
function.
2. Write a C++ program to read two float numbers. Perform arithmetic binary
operations +,-,*,/ on these numbers using inline function. Display the resultant
value.
3. Write a C++ program to accept length and width of a rectangle. Calculate and
display perimeter as well as area of a rectangle by using inline function.
4. Write a C++ program to check minimum and maximum of two integer number
(use inline function and conditional operator).

Constructor and Destructor


1. Write a C++ program to create a class which contains two dimensional integer
array of size m*n Write a member function to display transpose of entered
matrix.(Use Dynamic Constructor for allocating memory and Destructor to
free memory of an object).
2. Write a C++ program to create a class Mobile which contains data members
as Mobile_Id, Mobile_Name, Mobile_Price. Create and Initialize all values
of Mobile object by using parameterized constructor. Display the values of
Mobile object.
3. .Write a C++ program using class which contains two data members as type
integer. Create and initialize the objects using default constructor,
parameterized constructor with default value. Write a member function to
display maximum from given two numbers for all objects.
4. Write a C++ program to create a class Date which contains three data
members as dd,mm,yyyy. Create and initialize the object by using
parameterized constructor and display date in dd-month-yyyy format. (Input:
19-12-2014 Output: 19-Dec-2014) Perform validation for month.
5. Write C++ program to create a class Employee containing data members
Emp_no, Emp_Name, Designation and Salary. Create and initialize the
objects using default, parameterized and Copy Constructor. Also write
member function to calculate Income tax of the employee which is 20% of
salary
6. Write a C++ program to create a class Number which contains two integer
data members. Create and initialize the object by using default constructor,
parameterized constructor. Write a member function to display maximum
from given two numbers for all objects.
Static data member and Static member function
1. Write a C++ program to create a class Item with data members Item_code,
Item_name, Item_Price. Write member functions to accept and display item
information and also display number of objects created for a class. (Use Static
data member and Static member function).
2. Create a Base class Train containing protected data members as Train_no,
Train_Name. Derive a class Route(Route_id, Source, Destination) from Train
class. Also derive a class Reservation (Number_of_Seats, Train_Class, Fare,
Travel_Date) from Route. Write a C++ program to perform following
necessary functions: a. Enter details of n reservations b. Display details of all
reservations c. Display reservation details of a specified Train class
3. Write a C++ program to create a class which contains single dimensional
integer array of given size. Define member function to display median of a
given array. (Use Dynamic Constructor to allocate and Destructor to free
memory of an object).

Operator Overloading
1. Write a C++ program to create a class Array that contains one float array as
member. Overload the Unary ++ and -- operators to increase or decrease the
value of each element of an array. Use friend function for operator function.
2. Create a class String which contains a character pointer (Use new and delete
operator) Write a C++ program to overload following operators
a. ! To reverse the case of each alphabet from given string.
b. [ ] To print a character present at specified index
3. Create a class String which contains a character pointer (Use new and delete
operator). Write a C++ program to overload following operators:
a. ! To reverse the case of each alphabet from given string
b. == To check equality of two strings
4. Create a class Matrix and Write a C++ program to perform following
functions:
a. To accept a Matrix
b. To display a Matrix
c. Overload unary minus ‘–‘ operator to calculate transpose of a Matrix
d. Overload binary multiplication '*’ operator to calculate multiplication
of two matrices
5. Create a class String which contains a character pointer (Use new and delete
operator). Write a C++ program to overload following operators:
a. < To compare length of two strings
b. == To check equality of two strings
c. + To concatenate two strings
6. Write a C++ programto create a class Distance which contains data members
as kilometer, meter. Write a program to perform the following functions a.To
accept distance b.To display distance c.To overload > operator to compare
two distance
7. Create a class Fraction that contains two data members as numerator and
denominator. Write a C++ program to overload following operators a. ++
Unary (pre and post both) b. << and >> Overload as friend functions
8. Create a class Time containing members as: - hours - minutes - seconds Write
a C++ program for overloading operators >> and << to accept and display a
Time also write a member function to display time in total seconds.
9. Create a class Fraction containing data members as Numerator and
Denominator. Write a program to overload operators ++ , -- and * to
increment, decrement a Fraction and multiply two Fraction respectively. (Use
constructor to initialize values of an object)

Function Overloading
1. Write a C++ program to overload function Volume and find Volume of Cube,
Cylinder and Sphere
2. Create a class Book containing Book_name, author and Price as a data
member and write necessary member functions for the following (use function
overloading).
a. To Accept and display the Book Information.
b. Display book details of a given author c. Display book details of
specific price
3. Write a C++ program to create a class employee containing salary as a data
member. Write necessary member functions to overload the operator unary
pre and post decrement "--" for decrementing salary.
4. Write a C++ program to implement a class printdata to overload print function
as follows: void print(int) - outputs value followed by the value of the integer.
5. Eg. print(10) outputs - value 10
6. void print(char *) – outputs value followed by the string in double quotes.
7. Eg. print(“hi”) outputs value “hi”
8. Create a class College containing data members as College_Id,
College_Name, Establishment_year, University_Name. Write a C++ program
with following functions
a. Accept n College details b. Display College details of specified
University
b. Display College details according to Establishment year (Use Array of
Objects and Function Overloading).
9. Write a C++ program to create a class Person that contains data members as
Person_Name, City, Mob_No. Write a C++ program to perform following
functions:
a. To accept and display Person information
b. To search the Person details of a given mobile number
c. To search the Person details of a given city. (Use Function
Overloading)
10. Write a C++ program to implement a class ‘student’ to overload following
functions as follows: a. int maximum(int, int) – returns the maximum score of
two students b. int maximum(int *a, int arraylength) – returns the maximum
score from an array ‘a’.
11. Write a C++ program to sort integer and float array elements in ascending
order by using function overloading.

Virtual Function
1. Write a C++ program to create a class Shape with functions to find area of the
shape and display the name of the shape and other essential components of
the class. Create derived classes circle, rectangle and trapezoid each having
overridden function area and display. Write a suitable program to illustrate
Virtual Function.
2. A book (ISBN) and CD (data capacity) are both types of media (id, title)
objects. A person buys 10 media items each of which can be either book or
CD. Display the list of all books and CD’s bought. Define the classes and
appropriate member functions to accept and display data. Use pointers and
concept of polymorphism (Virtual Function)
3. Create a base class Conversion. Derive three different classes Weight (Gram,
Kilogram), Volume (Milliliter, Liter), Currency (Rupees, Paise) from
Conversion class. Write a program to perform read, convert and display
operations. (Use Pure virtual function)
4. Create a base class Media. Derive two different classes Book (Book_id,
Book_name, Publication, Author, Book_price) and CD (CD_title, CD_price)
from Media. Write a program to accept and display information of both Book
and CD. (Use pure virtual function)
5. Create a class called LIST with two pure virtual function store() and retrieve().
To store a value call store and to retrieve call retrieves function. Derive two
classes stack and queue from it and override store and retrieve.
Friend Function
1. Write a C++ program to create two classes Rectangle1 and Rectangle2.
Compare area of both the rectangles using friend function.
2. Write a C++ program to design a class complex to represent complex number.
The complex class uses an external function (as a friend function) to add two
complex number. The function should return an object of type complex
representing the sum of two complex Numbers.
3. Write a C++ program to subtract two integer numbers of two different classes
using friend function.
Inheritance
1. Write a C++ program with Student as abstract class and create derive classes
Engineering, Medicine and Science having data member rollno and name
from base class Student. Create objects of the derived classes and access them
using array of pointer of base class Student.
2. Create a base class Flight containing protected data members as Flight_no,
Flight_Name. Derive a class Route(Source, Destination) from class Flight.
Also derive a class Reservation (no_seats, class, fare, travel_date) from Route.
Write a C++ program to perform the following necessary functions.
a. Enter details of n reservations.
b. Display reservation details of Business class.
3. Create a base class Student (Roll_No, Name) which derives two classes
Theory and Practical. Theory class contains marks of five Subjects and
Practical class contains marks of two practical subjects. Class Result
(Total_Marks, Class) inherits both Theory and Practical classes. (Use concept
of Virtual Base Class) Write a menu driven program to perform the following
functions:
a. Build a master table.
b. Display master table.
4. Design two base classes Employee (Name, Designation) and Project
(Project_Id, title). Derive a class Emp_Proj(Duration) from Employee and
Project. Write a menu driven program to
a. Build a master table. Display a master table
b. Display Project details in the ascending order of duration
5. Create a Base class Train containing protected data members as Train_no,
Train_Name. Derive a class Route(Route_id, Source, Destination) from Train
class. Also derive a class Reservation (Number_of_Seats, Train_Class, Fare,
Travel_Date) from Route. Write a C++ program to perform following
necessary functions:
a. Enter details of n reservations
b. Display details of all reservations
c. Display reservation details of a specified Train class
6. Design a base class Product(Product _Id, Product _Name, Price). Derive a
class Discount (Discount_In_Percentage) from Product. A customer buys n
Products. Calculate total price, total discount and display bill using
appropriate manipulators.
7. Implement the following class hierarchy: Employee: code, ename, desg
Manager (derived from Employee): year_of_experience, salary Define
appropriate functions to accept and display details. Create n objects of the
manager class and display the records. Write main function that uses the above
class and its member functions.
8. Create two base classes Learn_Info(Roll_No, Stud_Name, Class, Percentage)
and Earn_Info(No_of_hours_worked, Charges_per_hour). Derive a class
Earn_Learn_info from above two classes. Write necessary member functions
to accept and display Student information. Calculate total money earned by
the student. (Use constructor in derived class)
9. Design a two base classes Employee (Name, Designation) and
Project(Project_Id, title). Derive a class Emp_Proj(Duration) from Employee
and Project. Write a menu driven program to a. Build a master table. b.
Display a master table c. Display Project details in the ascending order of
duration.
File Handling
1. Write a C++ program to copy the contents of one file to another.
2. Write a C++ program to read the contents of a text file. Count and display
number of characters, words and lines from a file. Find the number of
occurrences of a given word present in a file.
3. Write a C++ program to read student information such as rollno, name and
percentage of n students. Write the student information using file handling.
4. Write a C++ program to create a text file which stores employee information
as emp_id, emp_name, emp_sal). Write a menu driven program with the
options
5. Append b. Modify c. Display d. Exit
6. Write a C++ program to create a class Department which contains data
members as Dept_Id, Dept_Name, H.O.D., Number_Of_staff. Write
necessary member functions to a. Accept details from user for ‘n’ departments
and write it in a file “Dept.txt”. b. Display details of department from a file.
7. Write a C++ program to read the contents of a “Sample.txt” file. Store all the
uppercase characters in ”Upper.txt”, lowercase characters in ”Lower.txt” and
digits in “Digit.txt” files. Change the case of each character from “Sample.txt”
and store it in “Convert.txt” file

You might also like