Está en la página 1de 5

SCHOOL OF ENGINEERING SIR PADAMPAT SINGHANIA UNIVERSITY, UDAIPUR B.

Tech II Semester PROGRAMMING WITH C++ (CS102) Credits: 3 (L) + 0 (T) + 2 (P) = 5 Faculty: Deepak Gour

Programming Exercises based on C++


1. Define a class employee. Include the following members: Data Members: 1. Name of the employee 2. Age of the employee Member Functions: 1. To get the name and age of the employee 2. To display the name and age of the employee. 2. Define a class BankAccount to represent a bank account. Include the following members: Data Members: 1. 2. 3. 4. Name of the depositor Account Number Type of account Balance amount in the account

Member Functions: 1. 2. 3. 4. To assign initial value To deposit an amount To withdraw an amount after checking the balance To display name and balance

3. Modify the program 1 for handling 5 employees. 4. Modify the program 2 for handling 10 customers. 5. Imagine a tollbooth at a bridge. Cars passing by the booth are expected to pay Rupees 25.75 toll. Mostly they do, but sometimes a car goes by without paying. The tollbooth keeps track of the number of cars

that have gone by, and of the total amount of money collected. Include the following members: Data Members: 1. Total Number of Cars 2. Total amount of money Member Functions: 1. PayingCar() increments the car total and adds Rupees 25.75 to the cash total 2. NoPayCar() increments the car total but adds nothing to the cash total 3. Display() which displays the two totals 6. Define a class Shop by considering a shopping list of items for which we place an order with a dealer every month. Include the following members: Data Members: 1. 2. 3. 4. Item Code (Array) Item Name (Array) Item price (Array) Count (which keep track of number of items)

Member Functions: 1. 2. 3. 4. To enter individual items and their costs To calculate the sum of the all item costs To remove any item from the list To display all the items from the list

7. Modify the Program 5 using constructor and destructor. 8. Modify the Program 6 using constructor and destructor. 9. Write a Program which explains the significance of the scope Resolution Operator with respect to referencing Global version of variable. 10. Create a class example which has one static data member count and one member function display (). Create a constructor in which increment the value of count. Create five objects as e1, e2, e3, e4, and e5 and call

display () function with respect to each object. 11. Create a class called time that has separate integer data member for hours, minutes, and seconds. One constructor should initialize this data to zero, and another should initialize it to some fixed values. Another member function should display it, in 11:59:59 format. The final member function should add two objects of type time passed as arguments. A main() program should create two initialized time object and one that isnt initialized. Then it should add the two initialized values together, leaving the result in third time variable. Finally it should display the value of this third variable. 12. Write a program showing the use of call by reference and return by reference. 13. Create a class calculator which supports all the basic operations of the calculator as addition, subtraction, multiplication, division etc. Program should be Menu driven and user friendly (i.e. interactive). 14. Create a class Temperature which converts the temperature from Centigrade to Fahrenheit and vice versa. Program should be Menu driven and user friendly (i.e. interactive). 15. Create a class Distance which supports the distances conversions as meter to centimeter, fetes, inches, etc. Program should be Menu driven and user friendly (i.e. interactive). 16. /* Illustration of Function Overloading. */ 17. /* Illustration of Ambiguity in Function Overloading. */ 18. /* Illustration of Static Member Function. */ 19. /* Write a program to convert temperture from Centigrade to Farenheit using functions. For Reference : c=(f-32)/1.8 */ 20. /* Define a class employee having data members as emp_code, dept_code, age, basic, DA, HRA and three member functions as getdata(), putdata(), calculatesalary() to get, display all the values of data members and calculate the total salary by adding basic, DA, HRA. Write this program for 10(ten) employees using an array of objects. */ 21. /* Illustration of Friend Function. */ 22. /* Write a program to show error message using const member function.*/

23. /* Write a base class employee which should contain common features of employee and create four derived classes to the employee base class as Employee1, Employee2, Employee3, Employee4. Calculate the income tax taking into following considerations: Employee1 ==> 30% Employee2 ==> 20% Employee3 ==> 10% Employee4 ==> NIL */ 24. /* Illustration of Inheritance. */ 25. (a) /* Write any example program which shows the concept of inheritance making the data members of base class protected. Modify the same program by converting the data members of base class to private. Show error code in output. */ 25. (b) Modify the program 25 (a) by converting the data members of base class to private. Show error code in output. */ 26. /* Draw a base class college which has data members as follows: univ_code, univ_name, coll_code, coll_name, address, city, state, picode. Draw a derived class with respect to following 6 departments: CSE, BT, IT, ECE, ME, CE. Include essential data members in derived class. */ 27. /* Write program to show the concept of SINGLE INHERITANCE. */ 28. /* Write a program to illustrate the use of MULTIPLE INHERITANCE. */ 29. /* To Illustrate the concept of Multiple Inheritance. Values are to be entered by the user. */ 30. /* Illustration of Multi-Level inheritance. This program is already provided with roll number and marks of any student, whose total is to be calculated. */ 31. /* In this program roll number and marks of a student are entered, following conditions are to be kept in mind: (01) Inputs must be given by the user. (02) All marks have maximum value of 100. (03) Extend the subject list from 2 to 5. (04) Calculate the total percentage and division. greater than or equal to 60 : 1st division greater than or equal to 48 : 2nd division greater than or equal to 33 : 3rd division

less than 33 : 4th division. */ 32. /* Modify the previous program according to following conditions: (01) introduce class sports as base class of results. (02) introduce class cultural as base class of results. (03) Calculate total marksin test, sports and cultural. (04) Calculate percentage and division based on acadamic record. (05) Calculate grade in sports and cultural as follows: if total marks >= 90 : A total marks >= 75 : B total marks >= 60 : C total marks < 60 : D. */ 33. /* Draw a virtual base class student which inherits 2 derived classes test and sports, which act as a base class to class result. */ 34. /*Write a program by using hybrid inheritance and create corresponding constructor in every class. Show the mechanism of calling the constructor in program coding. */

También podría gustarte