C++ Assignment
C++ Assignment
Assignment -1
(2 marks)
Chapter-2
Theory
Program
1. Define a class to represent a bank account .Include the following
Data members.
Name of the depositor
Account number
Type of account
Balance amount in the account
Member functions
To assign initial values
To deposit an amount
To withdraw an amount after checking the balance
To display name and balance.
Write a main program to test the program.
2. Create a class Employee with data members (id, name, Post, address, salary) and read
information of 20 Employees and display the name and post of employee whose salary
is greater than 50000.
3. Using class write a program that receives inputs principle amount, time and rate.
Keeping rate 12% as the default argument, calculate simple interest for five
customers.
4. WAP to perform addition of two times using friend function.
5. WAP to perform addition of two complex numbers using friend function.
6. WAP to swap contents of two variables of 2 different classes using friend function.
7. Create classes called Vechile1, Vechile2 and Vechile3 with each of having one private
member named price. Add member function to set a price(say setPrice()) one each
class. Add one more function max() that is friendly to all classes. max() function should
compare private member named price of three classes and show maximum among
them. Create one-one object of each class and then set a value on them. Display the
maximum price among them.
Assignment -2
(2 marks)
Chapter-3
1. What is message passing? Describe with example.
2. Differentiate message passing and procedure call with suitable example. What are
the possible memory errors in programming.
3. Explain message passing formalism with syntax in C++.What is stack Vs heap
memory allocation?
4. “A constructor is a special member function that automatically initializes the objects
of its class”, support this statement with a program of all types of constructors. Also
enlist the characters of constructors.
5. What is constructor? Is it mandatory to use constructor in class. Explain.
6. What is copy constructor in C++? Is it possible to pass object as argument in Copy
constructor? Explain with suitable program.
7. Differentiate between constructor and destructor. Can there be more than one
destructor in a program for destroying a same object. Illustrate you
answer.
8. What are constructors and destructors? Explain their types and uses with good
illustrative example? What difference would be experienced if the features of
constructors and destructors were not available in C++.
9. What is de-constructor? can you have two destructors in a class? Give example to
support your reason.
10. Discuss the various situations when a Copy constructor is automatically invoked.
How a default constructor can be equivalent to a constructor having default arguments.
11. What do you mean by dynamic constructor? Explain its application by a program to
compute complex numbers.
12. What is dynamic memory allocation? How memory is allocated and de-allocated in
C++? Explain with examples. List out the advantages of dynamic memory allocation?
Explain with suitable example.
Programs
Assignment -3
(2 marks)
Chapter-4
1. “Inheritance allows us to create a hierarchy of classes. Justify this statement. Discuss
private and public inheritance.
2. How does visibility mode control the access of members in the derived class? Explain
with an example.
3. Why protected access specifier used in C++? Explain different types of inheritance with
examples.
4. How does inheritance support reusability? What are the different forms of inheritance?
Explain with example.
5. When base class and derived class have the same function name what happens when
derived class object calls the function?
6. Inheritance supports characteristic of OOP. Justify your answer. Explain ambiguity that
occurs in multiple inheritance.
7. During the time of hybrid inheritance when there is hierarchical inheritance at the upper
level and multiple inheritance at lower level, ambiguity occurs due to the duplication of
data from multiple path at the grand child class. How this kind of ambiguity is resolved?
Explain with suitable example?
8. How are arguments are sent to base constructors in multiple inheritance? Who is
responsibility of it
9. How does inheritance influence working of constructors and destructors? Class ‘Y’ has
been derived from class ‘X’ .The class ‘Y’ does not contain any data members of its own.
Does the class ‘Y’ require constructors? If yes why.
10. What is containership? How does it differ from inheritance, describe how an object of a
class that contain object of another classes are created.
How composition differs from inheritance?
11. Explain how composition provide reusability?
12. Distinguish between subclass and subtype in light of principle of substitutability.
Support your answer with suitable example.
Differentiate between
Programs
1) WAP to enter information of n Employee and then display is using the concept multiple
inheritance.
2) Write a complete program with reference to the given figure.
3) The following figure shows the minimum information required for each class. Write a
progam by realizing the necessary member functions to read and display information of
individual object. Every class should contain at least one constructor and should be
inherited from other classes as well.
4) The following figure shows the minimum information required for each class. Write a
program to realize the above program with necessary member functions to create the
database and retrieve individual information .Every class should contain at least one
constructor and should be inherited to other classes as well.
5) Create a class called Person with suitable data members to represent their name and
age. Use member function to initialize and display these information. Derive Student
and Employee from the Person class with their unique features. Initialize object of these
class using constructor and display the information.
6) Write a program to input two vector coordinates from the base class named “Base”.
Class “Derived” inherits all the properties of class “Base”. Class “Derived” must contain a
function named add_vector() that add the two vectors input from the base class and
finally display the result from the function display() that is friend to the base class.
7) Create a class student with two data members represent name and age. Use appropriate
member function to read and print these data members name and roll. Derive a class marks
from student that has additional data member sessional1,sessional2 to store sessional
marks. Derive another class result from marks and add the sessional marks. Use appropriate
member function to read and display data in the class.
8) Create a class student with two data members to represent name and age. Use member
function to read and print those data. From this derive a class called boarder with member
data to represent room number .Derive another class called day-scholar from class student
with member data to represent address of student. In both derived class use function to
read and print respective data.
9)The following figure shows minimum information required for each class.
i) Write a Program to realize the above program with necessary member functions to
create the database and retrieve individual information
ii) Rewrite the above program using constructor on each class to initialize the data
members.
10) Write a program that allow you to book a ticket for person and use two classes Person,
Reservation. Class Reservation is composite class/ container class.
11) Develop a complete program for an institution, which wishes to maintain a database of its
staff. The database is divided into number of classes whose hierarchical relationship is shown in
the following diagram. specify all classes and define constructors and functions to create
database and retrieve the individual information as per requirements.
12) Develop a complete program for an institution which wishes to maintain a database of its
staff. Declare a base class STAFF which include staff_id and name. Now develop a records for
the following staffs with the given information below.
Lecturer (subject, department)
Administrative staff (Post, department)