Final Question Paper 07 Oct-2024
Final Question Paper 07 Oct-2024
Instructors: Nidhi Kalra, Palika Chopra, Suresh Raikwar, Harpreet Singh, Seemu Sharma, Lokendera,
Tanu Goyal
Note: Attempt all questions (subparts) in sequence at one place. Assume missing data, if, any, suitably. Pencil work will
not be evaluated.
Q1 a) Design a class Triangle with private attributes: base and height. Implement 3
a public function compareArea(Triangle &t1, Triangle &t2) that compares
the areas of two triangles passed as arguments and returns the triangle with
the larger area.
b) Design a C++ program with a variable named int count that tracks both the
2
number of items and the number of customers in the same program.
Initialize the count variable with no. of items=20 and no. of customers=12,
respectively. In main(), display the no. of items only. Ensure that the
solution does not use classes and :: operator.
Q2 a) Design a Car class with private attributes: speed and fuel, and implement 3
a constructor that uses this pointer to initialize these attributes. Develop
all the necessary methods required to display the details.
b) Explain the following concepts in object-oriented programming with the
help of a suitable example:
2
i. Data Abstraction
ii. Polymorphism
Q3 5
You are provided with the ShoppingCart class, as shown above. Write the main()
function for the given class. Your task is to:
Take input from the user for the number of shopping carts (n) and dynamically
create an array of n ShoppingCart objects. Initialize the objects using the
parameterized constructor by taking the input at run-time. Display the details.
Finally, release the dynamically allocated memory for the shopping carts before the
program terminates.
Q4 Develop a Donation Management System in C++ that efficiently manages the 5
transfer of donations between accounts utilizing classes. The system consists of the
[P.T.O]
following components: Donor Class contains private data members: string
donor_name, double balance. Write the following functions in public section:
set_details(string name, double amount)
display()
double get_balance()
Recipient Class contains the private data member: string recipient_name, double
account_balance, double amount_required needed by the recipient and the
following functions in public section:
set_details(string name, double balance, double amount)
display()
double get_balance()
Additionally, the program includes the following function:
transfer (Donor &donor, Recipient &recipient, double amount)
This function facilitates the transfer of funds between a donor and a recipient. This
function will verify whether the donor has sufficient funds for the transfer. If the
donor has adequate funds, both the donor's and recipient's balances will be updated
accordingly. Complete the program using the above-mentioned conditions.
Q5 Implement the class with four private integer data members and public: showdata() 5
function for the below main() code snippet.
Q6 5