Вы находитесь на странице: 1из 3

1.

An electricity board charges the following rates to domestic users to discourage large
consumption of energy:
FOR the first 100 units - 60P per unit
For next 200 units - 80P per unit
Beyond 300 units - 90P per unit
All users are charged a minimum of Rs.50.00. if the total amount is more than Rs.300.00 than an
additional surcharge of 15% is added .Write a C++ program to read the names of users and
number of units consumed and print out the charges with names

2. An election is contested by five candidates. The candidates are numbered 1 to 5 and a voting is
done by marking the candidate number in a ballot paper. Write a C++ program to read the ballot
and count the votes cast for each candidate using an array variable count. In case, a number read is
outside the range 1 to 5 the ballot should be considered as a spoilt ballot, and the program should
also count the number of spoilt ballots

3. Write a C++ program to perform different arithmetic operation such as addition, subtraction,
division, modulus and multiplication using inline function.

4. Write a C++ program to create three objects for a class named pntr_obj with data members such
as roll_no & name . Create a member function set_data() for setting the data values and print()
member function to print which object has invoked it using this pointer.

5. Write a C++ program to explain virtual function (polymorphism) by creating a base class
c_polygon which has virtual function area(). Two classes c_rectangle and c_traingle derived from
c_polygon and they have area() to calculate and return the area of rectangle and triangle
respectively.

6. Write a C++ program to count the number of persons inside a bank, by increasing count
whenever a person enters a bank, using an increment(++) operator overloading function, and
decrease the count whenever a person leaves the bank using a decrement(--) operator overloading
function inside a class .

7.Write a C++ program to create two objects of a class called company and add their data
members using an operator overloaded function for + operator and -operator .

8. Write a program to accept the student detail such as name and 3 different marks by get_data()
method and display the name and average of marks using display() method. Define a friend class
for calculating the average of marks using the method mark_avg().
9. Write a program to explain class template by creating a template T for a class named pair
having two data members of type T which are inputted by a constructor and a member function
get-max() return the greatest of two numbers to main. Note: the value of T depends upon the data
type specified during object creation.

10. Create the equivalent four-function calculator. The program should request the user to enter a
number, an operator, and another number. It should then carry out the specified arithmetical
operation: adding, multiplying, or dividing the two numbers. (It should use a switch statement to
select the operation). Finally it should display the result. When it finishes the calculation, the
program should ask if the user wants to do another calculation. The response can be Y or N
.

11. Make a class Employee with a name and salary. Make a class Manager inherit from
Employee. Add an instance variable, named department, of type string. Supply a method to string
that prints the managers name, department and salary. Make a class Executive inherit from
Manager. Supply a method to string that prints the string Executive followed by the information
stored in the Manager super class object. Supply a test program that tests these classes and
methods.

12. Create a class complex with two integer data member s as real and imaginary. Design a
method to input the complex number, design a function to perform addition operation between the
two complex numbers by overloading the + operator. Finally display the result. Write a program
to test this class.

13. Declare a class cont with a integer static data member cnt to store the number of objects
active, a constructor function to increment cnt, a destructor function to decrement cnt, and a static
function showcnt( ) to display the value of cnt at that instance. Write a program to test this class.

14. Consider the following class definition class


father{
Protected : int age;
Public :
Father (int x) {age = x;}
Virtual void iam( )
{ cout << I am the father, my age is :<<age<<endl
;}
};
Derive the two classes son and daughter from the above class and for each, define suitable
constructors for these classes. Now, write a main ( ) that creates objects of the three classes and
then call iam( ) for them. Declare pointer to father. Successively, assign addresses of objects of
the two derived classes to this pointer and in each case, call iam( ) through the pointer to
demonstrate polymorphism in action.

15. A hospital wants to create a database regarding its indoor patients. The information to store
include:
a) Name of the patient
b) Date of admission.
c) Disease.
d) Date of discharge.
Create a class to store the date (year, month and date as its members). Create a base class to store
the above information. The member function should include functions to enter information and
display a list of all the patients in the database. Create a derived class to store the age f the
patients. List the information about all to store the age of patients. List the information about all
the pediatric patients (less than twelve years in age).

16. Create a base class called shape. Use this class to store two double type values that could be
used to compute the area of figures. Derive two specific classes called triangle and rectangle from
the base shape. Add to the base class, a member function get_data ( ) to initialize base class data
members and another member function display_area ( ) to compute and display the area of
figures. Make display_area ( ) as a virtual function and redefine this function in the derived
classes to suit their requirements. Using these three classes, design a program that will accept
dimensions of a triangle or a rectangle interactively and display the area. Remember the two
values given as input will be treated as lengths of two sides in the case of rectangles and as base
and height in the case of triangles and used as follows:
Area of rectangle = x * y
Area of triangle = * x * y

17. To write a C++ program to add two private data members using friend functions.

18. To write a C++ program to perform matrix addition using dynamic memory allocation.

19.

Вам также может понравиться