Assignment 5
Assignment 5
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.
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.
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:
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.