In: Computer Science
C++ I will thumb it up if its accurate.
Learning Objective: To implement friend functions, and overload operators as friend functions and member functions
Instructions:
Part 1 Overload the +, -,* and /, >=, and <= as friend Functions
ex of overloaded operator as friend function prototype: friend BankAccount operator +(const BankAccount& account1, const BankAccount& account2); friend BankAccount operator -(const BankAccount& account1, const BankAccount& account2); friend bool operator >=(const BankAccount& account1, const BankAccount& account2) friend bool operator =<(const BankAccount& account1, const BankAccount& account2) friend bool operator ==(const BankAccount& account1, const BankAccount& account2)
Part 2 Overload the +=, -=, and == as member functions
Grading criteria
The following is the basic criteria to be used to grade your submission. You start with 30 points and then you start losing points, as you don't do something that is required.
-5: missing header
-5: does not implement friend functions properly
-5: missing constructors
-5: does not implement accessors and mutators where necessary
-5: does not use const where necessary
-5: coding style: missing indentation
-5 missing an operator
-5 does not overload as member function properly
-10: Incorrect output.
-30: Late submission.
Here is the answer for your question in C++ Programming Language.
Kindly upvote if you find the answer helpful.
NOTE : I have used dev-c++ to run this code, hence I had to used #include "BankAccount.cpp" in main.cpp,
if including #include "BankAccount.h" please include header file only.
###################################################################################
CODE :
BankAccount.h
#include<iostream> using namespace std; class BankAccount{ |
################################################
BankAccount.cpp
//Include header //Implementing constructors //Implementing accessors and mutators BankAccount operator-(const BankAccount& account1,
const BankAccount& account2){ bool operator>=(const BankAccount& account1,
const BankAccount& account2){ bool operator<=(const BankAccount& account1,
const BankAccount& account2){ bool operator==(const BankAccount& account1, const
BankAccount& account2){ /* |
###############################################################
main.cpp
#include "BankAccount.cpp" int main(){ |
####################################################################
SCREENSHOTS :
Please see the screenshots of the code below for the indentations of the code.
BankAccount.h
#######################################################
BankAccount.cpp
################################################################
main.cpp
#########################################################################
OUTPUT :
NOTE : I had to put the comment "Using friend functions: " after displaying account balances. Kindly change accordingly.
Any doubts regarding this can be explained with pleasure :)