C++ Programs


  1. Write a C++ program to create a class Worker with data members as Worker_Name, No_of_Hours_worked, Pay_Rate. Write necessary member functions to calculate and display the salary of worker. (Use default value for Pay_Rate)
  2. Create a class ComplexNumber containing members as: - real - imaginary Write a C++ program to calculate and display the sum of two complex numbers.
  3. 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-mon-yyyy format. (Input: 19-12-2014 Output: 19-Dec-2014) Perform validation for month.
  4. Create a base class Student(Roll_No, Name) which derives two classes Academic_Marks(Mark1, Mark2, Mark3) and Extra_Activities_Marks(Marks). Class Result(Total_Marks, Grade) inherits both Academic_Marks and Extra_Activities_Marks classes. (Use Virtual Base Class) Write a C++ menu driven program to perform the following functions:
    i. Build a master table
    ii. Calculate Total_marks and grade
  5. Create a base class Account (Acc_Holder_Name, Acc_Holder_Contact_No). Derive a two classes as Saving_Account(S_Acc_No., Balance) and Current_Account( C_Acc_No., Balance) from Account. Write a C++ menu driven program to perform following functions :
    i. Accept the details for ‘n’ account holders.
    ii. Display the details of ‘n’ account holders by adding interest amount where interest rate for Saving account is 5% of balance and interest rate for Current account is 1.5% of balance.
  6. Write C++ program to Create two classes Array1 and Array2 which contains data members as Integer array of a specified size. Write necessary member functions to accept and display array elements of both the classes. Find and display smallest number from both the array.(use friend function,manipulators)
  7. Write a C++ program to create a class which contains two dimensional integer array of size mXn. Write a member function to display sum of all elements of entered matrix. (Use Dynamic Constructor for allocating memory and Destructor to free memory of an object)
  8. Write a C++ program to create a class which contains single dimensional integer array of given size. Write a member function to display even and odd numbers from a given array. (Use Dynamic Constructor to allocate and Destructor to free memory of an object)
  9. 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 :
    i. Enter details of ‘n’ reservations
    ii. Display details of all reservations
    iii. Display reservation details of a specified Train class
  10. Write a C++ program to create a class Employee which contains data members as Emp_Id, Emp_Name, Basic_Salary, HRA, DA, Gross_Salary. Write member functions to accept Employee information. Calculate and display Gross salary of an employee. (DA=12% of Basic salary and HRA = 30% of Basic salary) (Use appropriate manipulators to display employee information in given format :- Emp_Id and Emp_Name should be left justified and Basic_Salary, HRA, DA, Gross salary Right justified with a precision of two digits)
  11. Create a class Date containing members as: - dd - mm - yyyy Write a C++ program for overloading operators >> and << to accept and display a Date also write a member function to validate a date.
  12. Create two base classes Learning_Info( Roll_No, Stud_Name, Class, Percentage) and Earning_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)
  13. Write a C++ program to create a class Person which contains data members as P_Name, P_City, P_Contact_Number. Write member functions to accept and display five Persons information. Design User defined Manipulator to print P_Contact_Number. (For Contact Number set right justification, maximum width to 10 and fill remaining spaces with ‘*’)
  14. Write a C++ program to read two float numbers. Perform arithmetic binary operations like +, - , *, / on these numbers using Inline Function. Display resultant value with a precision of two digits.
  15. Create a Vector class to represent a series of integer values. Allocate memory for Vector object using new operator. Write a C++ menu driven program with following member functions:
    i. To accept a vector
    ii. To display a vector in the form (10,20,30,…)
    iii. To multiply by a scalar value iv. To modify the value of a given position from vector
  16. Create a class College containing data members as College_Id, College_Name, Establishment_year, University_Name. Write a C++ program with following member functions:
    i. To accept ‘n’ College details
    ii. To display College details of a specified University
    iii. To display College details according to a specified establishment year (Use Array of Object and Function overloading)
  17. Write a C++ program to find area and volume of cylinder using Inline function.
  18. Write a C++ program to create a class which contains two data members. Write member functions to accept display and swap two entered numbers using call by reference.
  19. Create a class Distance which contains data members as: kilometer, meter. Write C++ program to perform following functions:
    i. To accept a distance
    ii. To display a distance
    iii. To overload += operator to add two distances.
    iv. To overload > operator to compare two distances.
  20. Write a C++ program to create a class Integer. Write necessary member functions to overload the operator unary pre and post increment ‘++’ for an integer number.
  21. Write a C++ program to create a class Integer. Write necessary member functions to overload the operator unary pre and post decrement ‘--’ for an integer number.
  22. Write the definition for a class called ‘point’ that has x & y as integer data members. Overload the assignment operator (=) to copy one object to another. (Use Default and parameterized constructor to initialize the appropriate objects) Write a C++ program to illustrate the use of above class.
  23. Imagine a ticket Selling booth at a fair. People passing by are requested to purchase a ticket. A ticket is priced as Rs. 5/- . The ticketbooth keeps the track of the number of peoples that have visited the booth and of the total amount of cash collected. Create a class ticketbooth that contains No_of_people_visited, Total_Amount_collected. Write C++ program to perform following functions:
    i. To assign initial values.
    ii. To increment the No_of_people_visited if visitors have just visited the booth.
    iii. To increment the No_of_people_visited and Total_amount_collected if tickets have been purchased.
    iv. To display both totals
  24. Create a class Person that contains data members as Person_Name, City, Mob_No. Write a C++ program to perform following functions:
    i. To accept and display Person information
    ii. To search the mobile number of a given person
    iii. To search the Person details of a given mobile number (Use Function Overloading)
  25. Create a C++ class Mindata to perform following functions: int min( int, int) – returns the minimum of two integer arguments. float min(float, float, float) – returns the minimum of three float arguments. int min( int [ ] ,int) – returns the minimum of all elements in an array of size ‘n’.
  26. Write a class sales (Salesmam_Name, Product_name, Sales_Quantity, Target). Each salesman deals with a separate product and is assigned a target for a month. At the end of the month his monthly sales is compared with target and commission is calculated as follows: • If Sales_Quantity > target then commission is 25% of extra sales made + 10% of target
    • If Sales_Quantity ==target then commission is 10% of target.
    • Otherwise commission is zero Display the salesman information along with commission obtained. (Use array of objects).
  27. 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 C++ program to accept and display information of both Book and CD. (Use pure virtual function).
  28. Create a base class Conversion. Derive three different classes Weight (Gram, Kilogram), Volume(Milliliter, Liter), Currency(Rupees, Paise) from Conversion class. Write a C++ program to perform read, convert and display operations. (Use Pure virtual function).
  29. Write a C++ program which will accept ‘n’ integers from user through command line argument. Store Prime numbers in file “Prime.txt” and remaining numbers in “Others.txt”.
  30. Create a class for inventory of Mobile containing Model_Number, Company_Name, Price, Stock as data members. Mobile can be sold, if stock is available, otherwise purchase will be made. Write a C++ program to perform following functions :
    i. To accept and display mobile details
    ii. To sale a Mobile (Sale contains Model_Number & Quantity of mobile)
    iii. To Purchase a Mobile (Purchase contains Model_Numbet & Quantity of mobile).
  31. Write a C++ program to create two classes Class1 and Class2. Each class contains one float data member. Write following functions: i. To accept float numbers ii. To display float numbers in right justified format with precision of two digits iii. To Exchange the private values of both these classes by using Friend function.
  32. Write a C++ program to sort integer and float array elements in ascending order by using function overloading.
  33. Create a class MyString which contains a character pointer (Use new and delete operator). Write a C++ program to overload following operators: ! To change the case of each alphabet from given string [ ] To print a character present at specified index.
  34. Create a C++ class Sumdata to perform following functions: int sum( int, int) - returns the addition of two integer arguments. float sum(flaot, float, float) - returns the addition of three float arguments. int sum( int [ ] ,int) - returns the sum of all elements in an array of size 'n'.
  35. Write a C++ program to find maximum of two integer numbers and two float numbers by using function template.
  36. Create a class Clock that contains integer data members as hours, minutes and seconds. Write a C++ program to perform following member functions: void setclock(int, int, int ) to set the initial time of clock object. void showclock() to display the time in hh:min:sec format. Write a function tick( ) which by default increment the value of second by 1 or according to user specified second. The clock uses 24 hours format.
  37. Create a base class Shape. Derive three different classes Circle, Rectangle and Triangle from Shape class. Write a C++ program to calculate area of Circle, Rectangle and Triangle. (Use pure virtual function).
  38. 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 i. Accept details from user for ‘n’ departments and write it in a file “Dept.txt”. ii. Display details of department from a file. iii. Count the number of objects stored in a file.
  39. Write c++ program to create a class temperature which converts temperature fahrenheit to celcious
  40. Write c++ program to find given number is palindrome or not.
  41. Write c++ program to create a menu driven program contains addition,subtraction,division, multiplication, remainder functions
  42. Write c++ program to create class factorial and find factorial of given number
  43. Write c++ program to find Fibonacci series up to given number.
  44. Write C++ menu driven program for following function:
    1)To accept matrix
    2)Display matrix
    3)Sum of rows in matrix
    4)Sum of columns in matrix
    5)Transpose of matrix
  45. Write c++ program to display diagonal of given Matrix.
  46. Write C++ program to create class matrix which contains 3 functions
    1) Accept 2 Matrix
    2) Display 2 Matrix
    3) Sum of 2 Matrix
  47. Write C++ program to divide odd and even elements from array and store it in 2 different arrays.
  48. Write C++ program to create class power which contains function to find power of given number.
  49. Write a C++ program to find area and perimeter of rectangle using Inline function.
  50. Create a C++ class overload to perform following functions: float area(float,float,float) – returns the area of cone. float area(float, float) – returns the area of sphere. float area( int) – returns the area of circle.