c++labcycle

3
OOPS LAB CYCLE 1 1. Write a C++ program to implement function overloading in order to compute power(m,n) where i) m is double and n is int ii) m and n are int. Use a default value of 2 for n to make the function to calculate squares when this argument is omitted. 2. Define a class to represent a bank account. Include the following members: Data Members 1 Name of the depositor 2 Account Number 3 Type of account 4 Balance amount in the account Member function 1 To assign initial values 2 To deposit an amount 3 To withdraw an amount after checking the balance 4 To display name and Balance write a main program to test the program. Test the program for 10 customers. 3. Create 2 classes with the names dm and db which stores the values of distances .dm stores the distances in meters and centimeters, the class db stores distances in feet and inches, ,,write a program in c++ i.e., they can read values of the class object using a friend function to carry the addition operation. The object that stores the result may be dm object or db depending on the units in which the result is required the display should be in the form of feet and inches or meters and centimeters depending on the object on display. 4. Create a class called 'TIME' that has - three integer data members for hours, minutes and seconds

description

list of c++ programs

Transcript of c++labcycle

Page 1: c++labcycle

OOPS LAB CYCLE 1

1. Write a C++ program to implement function overloading in order to computepower(m,n) where i) m is double and n is int ii) m and n are int. Use a default value of 2 for n to make the function to calculate squares when this argument is omitted.

2. Define a class to represent a bank account. Include the following members: 

Data Members 1 Name of the depositor 2 Account Number 3 Type of account 4 Balance amount in the account 

Member function 1 To assign initial values 2 To deposit an amount 3 To withdraw an amount after checking the balance 4 To display name and Balance 

write a main program to test the program. Test the program for 10 customers.3. Create 2 classes with the names dm and db which stores the values of distances .dm

stores the distances in meters and centimeters, the class db stores distances in feet and inches, ,,write a program in c++ i.e., they can read values of the class object using a friend function to carry the addition operation. The object that stores the result may be dm object or db depending on the units in which the result is required the display should be in the form of feet and inches or meters and centimeters depending on the object on display.

4. Create a class called 'TIME' that has

- three integer data members for hours, minutes and seconds- constructor to initialize the object to zero- constructor to initialize the object to some constant value- member function to add two TIME objects- member function to display time in HH:MM:SS formatWrite a main function to create two TIME objects, add them and display the result in

HH:MM:SS format.5. Create a class 'COMPLEX' to hold a complex number. Write a friend function to

add two complex numbers. Write a main function to add two COMPLEX objects.

6. Create a 'MATRIX' class of size m X n. Overload the ‘+’ operator to add twoMATRIX objects. Write a main function to implement it.

7. Create a 'STRING' class which overloads ‘ = = ' operator to compare two STRINGobjects. Use friend function.

Page 2: c++labcycle

OOPS LAB CYCLE 1

8. Write a C++ program to overload unary – operator using a) friend function b)without using friend function.

9. Write a C++ program to overload ‘++’ and ‘--‘operators to convert a string to uppercase and lowercase respectively.

10. A Book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author , title , price , publisher and stock position. Whenever a customer wants a book , the sales person inputs the title and author and the system searches the list and displays whether it is available or not. If it is not, an appropriate message is displayed. If it is, then the system displays the book details and requests for number of copies required. If the requested copies are available, the total cost of the requested copies is displayed ; otherwise the message " REQUIRED COPIES NOT IN STOCK " is displayed.Design a system using a class called         books       with suitable member functions and constructors. Use       new      operator in constructors to allocate memory space required.Improve the sytem design to incorporate the following features :a.                 The price of the books should be updated as and when required. Use a private member function to implement this.

b.                 The stock value of each book should be automatically updated as soon as a transaction is completed.

c.                  The number of successful and unsuccessful transactions should be recorded for the purpose of statistical analysis. Use         static          data members to keep         count            of transactions.

Modify the program to demonstrate the use of pointers to access the members.

11. Design a class polar which describes a point in the plane using polar coordinates radius and angle. Use the overloaded + operator add two objects of polar. (Hint: You need to use the following trigonometric formula: x = r*cos(a); y = r*sin(a); (arc tangent) a = atan(x/y) and r = sqrt(x*x + y*y)

12. Write a C++ program to illustrate friend classes.13. Write a C++ program to illustrate static member functions.