Você está na página 1de 2

CLASS PROGRAMS

1. Explain constructors and destructors in C++. Why they are usually declared in the public section. 2. Explain overloaded constructors with example. Why do we need to overload constructor? 3. Explain constructors with default arguments with example 4. Explain copy constructor and its need. Why argument of copy constructor must be reference argument 5. Explain static class members. 6. State whether the following statements are true or false a. b. c. d. e. f. g. Defining a class without any member is an error Data members of a class can be accessed only with the help of member function Constructor methods cannot return any value A constructor is always declared as public A class can implement any number of constructors A copy of static variable is created every time the class is instantiated A static method can access only other static members

7. Write a program to enter the information of 10 books. (book-id, title and price) Print the information. 8. Create a class player with date member as player name, team name, number of matches and highest score. Get the data for five students. Sort the data in ascending order based on team name and print the result in proper format. 9. Write a program to add two polar coordinates. Create a member class polar with radius and angle as data member. X = r cos theta angle = a tan(y/z) Y = r sin theta radius = sqrt (x^2 + y^2) 10. Create a class of addresses called address. Data item must include street_no, street_name city, state, pincode. A member function putaddr() should display the address and member function getaddr() should prompt the user to type in a new address. Write a main program that creates an array of address object, prompt the user to enter as many address as desired and display all the addresses.
11. Create a class named Integer to hold two integer values. Design a method Swap that could take two Integer objects as parameters and swap their contents. Write a main program to implement the class Integer and the method Swap. 12. Define a Time class containing the following members: a. Two integer data members minutes and hours b. Two overloaded constructors c. One method to display the class data members d. Increment method that increments the time by 1 minute e. Decrement method that decrements the time by 1 minute.

One the constructors take integer parameters to assign values to two data members and the other constructor takes one integer parameter representing the total number of minutes and converts it into hours and minutes. Write a complete program to verify the operations and test that they work correctly. 13. Write a program to represent a vector (a series of integer values). Include constructors and methods to perform the following tasks. a. To create the vector b. To modify the value of a given element c. To multiply by a scalar value d. To display the vector in the form (10,20) 14. A common use of static member variable is to keep track of object that currently exist for a class. Write a program to illustrate this feature 15. 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 detils and requests for the number of copies required. If the requested copies are available, the total cost is displayed; other wise the message Insufficient Stock is displayed. It should also have the following features. a. The price of the book should be updated as and when required 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 transaction. Design a system using a class called Books with suitable members.

Você também pode gostar