0% found this document useful (0 votes)
8 views6 pages

C++ Operator Overloading & Bank System

The document contains an assignment by Anees Abbasi on Object Oriented Programming, featuring a C++ program that implements binary operator overloading for addition, subtraction, multiplication, and division of class objects, as well as unary decrement for array elements. It also outlines a project proposal for a Bank/Finance Management System, detailing its functionalities such as account creation, transactions, balance checking, and account management. The project aims to provide a computerized solution for managing bank accounts efficiently.

Uploaded by

aneesabbasitg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views6 pages

C++ Operator Overloading & Bank System

The document contains an assignment by Anees Abbasi on Object Oriented Programming, featuring a C++ program that implements binary operator overloading for addition, subtraction, multiplication, and division of class objects, as well as unary decrement for array elements. It also outlines a project proposal for a Bank/Finance Management System, detailing its functionalities such as account creation, transactions, balance checking, and account management. The project aims to provide a computerized solution for managing bank accounts efficiently.

Uploaded by

aneesabbasitg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Name: Anees Abbasi Submitted to: Dr Saima Jabeen

Department: Ai-22-Blue

Assignment No: 3
Object Oriented Programing
Question no 1:
Write a program to add, subtract, multiply and divide any two objects of a class using binary C++
Operator Overloading. Also, the same program should make use of unary decrement operator for the
array elements of a class (both subscript “[]” and “--” operators need to be overloaded).

Code:
#include <iostream>

using namespace std;

class MyClass

private:

int value;

public:

MyClass(int val = 0)

value = val;

MyClass operator+(const MyClass& other)

return MyClass(value + [Link]);

MyClass operator-(const MyClass& other)

return MyClass(value - [Link]);

}
Name: Anees Abbasi Submitted to: Dr Saima Jabeen
Department: Ai-22-Blue

MyClass operator*(const MyClass& other)

return MyClass(value * [Link]);

MyClass operator/(const MyClass& other)

if ([Link] == 0) {

cout << "Error: Division by zero!" << endl;

return MyClass();

return MyClass(value / [Link]);

MyClass& operator--()

value--;

return *this;

MyClass operator--(int)

MyClass temp = *this;

--(*this);

return temp;

int getValue() const {

return value;

};
Name: Anees Abbasi Submitted to: Dr Saima Jabeen
Department: Ai-22-Blue

int main() {

MyClass a(10);

MyClass b(5);

MyClass sum = a + b;

MyClass difference = a - b;

MyClass product = a * b;

MyClass quotient = a / b;

cout << "The Sum is= " << [Link]() << endl;

cout << "The Difference is = " << [Link]() << endl;

cout << "The Product is = " << [Link]() << endl;

cout << "The Quotient is = " << [Link]() << endl;

MyClass arr[3] = { MyClass(5), MyClass(8), MyClass(3) };

cout << "Array elements before decrement: ";

for (int i = 0; i < 3; i++) {

cout << arr[i].getValue() << " ";

cout << endl;

--arr[0];

arr[1]--;

cout << "Array elements after decrement: ";

for (int i = 0; i < 3; i++) {

cout << arr[i].getValue() << " ";

cout << endl;


Name: Anees Abbasi Submitted to: Dr Saima Jabeen
Department: Ai-22-Blue

return 0;

Output:

Question 2:

Project Requirements:
Title:
“Bank/Finance Management System”
Your Team Name:
Oop Coders
Name of Team lead:
Talha Mehmood Kiyani.
Team members:
Anees abbasi.
Abdul Rafay.
Talha Mehmood Kiyani.
Muhammad Ali.

Problem Specification/Inputs:
The Finance in Bank Management System project aims to provide a computerized solution for
managing bank accounts and other finances. The system allows users to perform various
operations such as creating new bank accounts, depositing money, withdrawing money,
checking balance, updating account details, and closing accounts.
The system maintains information about each bank account, including the account number,
account holder's name, type of account (current or savings), and the total amount of money
deposited in the account.
Name: Anees Abbasi Submitted to: Dr Saima Jabeen
Department: Ai-22-Blue

The main menu of the system offers different options for users to choose from. They can create
a new bank account by providing necessary details such as the account number, account
holder's name, type of account, and initial deposit. The system then creates the account and
assigns a unique account number to it.
Users can deposit or withdraw money from their accounts by entering the account number and
the desired amount. The system performs the requested transaction and updates the account
balance accordingly. It also ensures that sufficient balance is available for withdrawal and
provides an error message if the balance is insufficient.
The system allows users to check the balance of a specific account by entering the account
number. It displays the account details along with the current balance.
Users can also view a list of all bank account holders, showing their account numbers, names,
types of accounts, and balances. This feature provides an overview of all the accounts managed
by the system.
Account holders have the option to update their account details, including their names, types
of accounts, and balances. The system prompts users to enter the account number of the
account they wish to update and allows them to modify the desired fields.
Finally, the system allows users to close an account by providing the account number. It
removes the account from the system's records and updates the overall account list.
The Bank Management System project provides a user-friendly interface to facilitate banking
operations efficiently.

Output:
Interface:
Name: Anees Abbasi Submitted to: Dr Saima Jabeen
Department: Ai-22-Blue

Entering data in account:

Bank account Holder List:

Deleting Record:

Concepts used:
Class.
Functions.
File Management System.
Loops.
Conditions.

Common questions

Powered by AI

Advantages of a computerized Bank Management System include increased efficiency, accuracy in transaction processing, and ease of data management with reduced human error. It provides quick service through automated operations and centralized record-keeping, contributing to a better user experience. However, potential challenges involve system security risks such as data breaches, the complexity of maintaining and updating the system, and ensuring fail-proof error handling. Addressing these concerns involves implementing strict security protocols and regular system audits .

The Bank Management System facilitates user interaction through a main menu offering various options like creating accounts, managing transactions, and checking balances. Constructive programming elements include user prompts, input validation, and condition handling (e.g., loop constructs). The use of functions aids in organizing menu operations, while classes encapsulate account data and methods, enabling structured interaction and efficient handling of user requests .

Classes and functions serve as the fundamental building blocks in the Bank Management System design. The class structure allows for encapsulation of account-related data, such as account number, holder name, and balance, and methods for account management operations (e.g., transaction processing, balance updates). Functions facilitate modularity by encapsulating specific operations like account creation, money transactions, and balance checking, thus enabling code reuse and easier maintenance. These features collectively enhance system efficiency by organizing code logically and enabling efficient data management through object-oriented principles .

The Bank Management System ensures data integrity during transactions by implementing checks before executing operations. For withdrawals, the system verifies if the account balance is sufficient to cover the requested amount, preventing overdrafts. If the balance is inadequate, it provides an error message without performing the transaction. This approach of precondition checking and feedback helps maintain consistent and accurate account states, enhancing the system's reliability .

The program overloads the unary decrement operator (both prefix and postfix) to decrease the 'value' of a MyClass object by one. The prefix operator (--a) directly decrements the object, while the postfix operator (a--) stores the current state, applies the decrement, and then returns the original state. In the program's context, array elements are decremented using both operators, and the values before and after applying the operators are printed. Before decrement: 5 8 3. After decrement: 4 7 3 .

The program handles errors during division by checking if the denominator's 'value' is zero before performing the division. If 'other.value' is zero, it outputs an error message 'Error: Division by zero!' and returns a MyClass object with a default value (typically zero). This prevents a divide-by-zero exception .

Not handling division by zero in operator overloading can lead to undefined behavior and program crashes, resulting in potential system instability and security vulnerabilities. The current implementation addresses this by checking if the divisor's value is zero and providing an appropriate error message, preventing the execution of illegal operations and allowing the program to continue running safely. This practice reflects robust error handling, crucial for building reliable software systems .

The program uses overloaded unary operators for decrementing array elements, showcasing flexibility provided by operator overloading in object-oriented programming. By overloading the '[]' and '--' operators, array elements of MyClass instances can be intuitively accessed and modified as standard arithmetic types. This demonstrates polymorphism, where the same operation can have different implementations based on object types, thus enhancing code readability and maintaining abstraction while dealing with arrays of objects .

The testing of array elements with overloaded decrement operators reveals the program's ability to modify individual object states within an array intuitively. By decrementing elements and verifying post-decrement values, it demonstrates correct operator overloading and object state management. Edge cases, such as decrementing negative or zero values, might require additional checks to avoid unintended behavior, ensuring robust handling of all possible inputs and fostering comprehensive program behavior verification .

The C++ program implements binary operator overloading by defining custom operator functions within the MyClass class. For addition, subtraction, multiplication, and division, the respective operators (operator+, operator-, operator*, operator/) are overloaded to perform arithmetic operations between two MyClass objects. Each operator takes a constant reference to another MyClass object as a parameter, performs the relevant arithmetic operation on the 'value' member of both objects, and returns a new MyClass object with the result .

You might also like