You are on page 1of 4

CS152T - Object Oriented Programming

Section: Assignment # 5 Total marks: 100

Name : __________________ Roll number : __________________

Submission:
• Email instructor if there are any questions. You cannot look at others’ solution or use others’
solution, however, you can discuss it with each other. Plagiarism will lead to a straight zero
with additional consequences as well.
• Submission after due time will not be accepted.
• Make a menu driven program (compulsory). Declare in structure.h. Define functions in
structure.cpp. Call these functions from main.cpp file using menu driven approach.(else if or
switch case). Create structure.h, structure.cpp, and main.cpp files by your self.

Task 1
Write a program that manages information about people using a custom data structure named
Person. The Person structure should have the following members:
name: A string representing the person's name.
age: An integer representing the person's age.
You need to overload the new and delete operators inside the Person structure to handle dynamic
memory allocation and deallocation for the Person objects.
Once you have defined the Person structure and overloaded the new and delete operators, the
program should allow the user to create new Person objects dynamically, input their name and
age, and display the information of each person.
To achieve this, you can follow the steps below:
Define the Person structure with appropriate members.
Overload the new operator inside the Person structure to handle dynamic memory allocation for
Person objects.
Overload the delete operator inside the Person structure to handle memory deallocation.
In the main function, create a menu-driven program that allows the user to perform the following
actions:
a. Create a new Person object dynamically.
b. Input the name and age for the new person.
c. Display the information of each person.
d. Exit the program.

Keep in mind that when overloading new and delete, you should handle memory allocation and
deallocation appropriately and handle any potential errors, such as failed memory allocation.

Task 2
Write a program that simulates a simple bank account using a custom data structure named
BankAccount.

The BankAccount structure represents an account with the following members:

accountNumber: An integer representing the account number.


balance: A double representing the account balance.

You need to overload the -> operator inside the BankAccount structure to provide a convenient
way to access the members of the account, such as its account number and balance, using a
pointer-like syntax.
Once you have defined the BankAccount structure and overloaded the -> operator, the program
should allow the user to create new bank accounts, input their account numbers and initial
balances, and display their information using the overloaded -> operator.

To achieve this, you can follow the steps below:

Define the BankAccount structure with appropriate members.


Overload the -> operator inside the BankAccount structure to provide access to its members
using a pointer-like syntax.
In the main function, create a menu-driven program that allows the user to perform the following
actions:
a. Create a new bank account.
b. Input the account number and initial balance for the new account.
c. Display the information of the account using the overloaded -> operator.
d. Exit the program.

Keep in mind that when overloading the -> operator, you should return a pointer to the current
BankAccount object so that its members can be accessed conveniently using the arrow (->)
operator.
Task 3
Write a program for creating a dynamic array of integers using a custom data structure named
IntArray to manage the memory allocation and deallocation. The IntArray should be designed as
a structure, and you need to overload the new and delete operators to handle the dynamic
memory allocation and deallocation for the array.
Your IntArray structure should have the following members:

data: A pointer to an integer representing the dynamic array.


size: An integer representing the size of the array.

The IntArray structure should be able to allocate and deallocate memory for the array using the
overloaded new and delete operators, respectively.
You need to demonstrate the usage of the IntArray structure by creating a dynamic array of
integers and performing basic operations on it, such as initialization, modification, and display.

To achieve this, you can follow the steps below:

Define the IntArray structure with appropriate members and methods.


Overload the new operator inside the IntArray structure to handle dynamic memory allocation
for the array.
Overload the delete operator inside the IntArray structure to handle memory deallocation.
Implement methods to initialize the array, modify its elements, and display its contents.
In the main function, create an IntArray object, allocate memory for the array using the
overloaded new operator, perform operations on the array, and deallocate memory using the
overloaded delete operator.
Keep in mind that when overloading new and delete, you will need to handle memory allocation
and deallocation appropriately and handle any potential errors, such as failed memory allocation.
Also, don't forget to handle the new[] and delete[] operators for dynamic arrays.

// Paste your code here


//Paste your output here

You might also like