Bank Account C++ Help

You have been developing a BankAccount class for Parkville Bank that contains several fields and functions.

Add arithmetic operators that operate as follows:
» The += operator takes a double parameter, which can represent a deposit (or credit) to be added to the BankAccount balance. (If the parameter is negative, it will represent a withdrawal or debit from the account.)
» The + operator takes an integer parameter that increases the account number, returning a new BankAccount object with the new account number.
Include < and > operators that determine whether one account is less than or greater than another. These comparisons are based on balances. Include an == operator that makes a comparison based on account numbers.
Include extraction and insertion operators for the class.
If you do not already have one, create a default constructor that assigns 0 to all the class fields.
Write a main()function that declares an array of five BankAccount objects. (Use the default constructor, so all the data fields will be initialized to 0s.) For each account, prompt the user for a series of transactions. The user enters a positive number for each deposit, a negative number for each withdrawal, and a 0 to quit entering transactions for an account. After the user has entered transactions for all five accounts, display the resulting details for each BankAccount. Save the file as BankAccountPartE.cpp.
Alter the main()function so that the user is prompted for starting account data instead of accepting the default 0 values. Save the file as BankAccountPartF.cpp.
Modify the main()function so that no two accounts are allowed with the same account number. Reprompt the user for a new account number when a duplicate occurs. Save the file as BankAccountPartG.cpp.
Modify the main()function to display the data for the accounts with the highest and lowest balances after all the data has been entered. Save the file as BankAccountPartH.cpp.


Here is my code so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
  #include<iostream>
using namespace std;
#include <stdlib.h>

class BankAccount
{
friend ostream& operator<<(ostream&, BankAccount);
friend istream& operator>>(istream&, BankAccount&);
private:
int acctNum;
double balance;
double annualRate;
public:
BankAccount(int, double = 0.0, double = 0.0);
BankAccount();
//void enterAccountData();
void enterAccountData();
//void computeInterest(int);
//void displayAccount();
void displayaccount();
BankAccount operator+=(double);
BankAccount operator-=(double);
BankAccount operator+(const BankAccount&);
bool operator<(BankAccount);
bool operator>(BankAccount);
bool operator==(BankAccount);
};

BankAccount::BankAccount(int acct, double bal, double rate)
{
//Provide code
acctNum=acct;
balance=bal;
annualrate=rate;
}
BankAccount::BankAccount()
{
//provide code
}
/*
void BankAccount::enterAccountData()
{
//
}
*/
void BankAccount::computeInterest(int years)
{
//provide code
}
/*
void BankAccount::displayAccount()
{
//provide code
} **/
//Work on these overloading operators

BankAccount BankAccount::operator+=(double deposit)
{
// write your code here
cout << "How much would you like to deposit?" << endl;
cin >> deposit;
balance = balance + deposit;
return balance;
}

BankAccount BankAccount::operator-=(double withdrawal)
{
// write your code here
cout << "How much would you like to withdrawal?" << endl;
cin >> withdrawal;
balance = balance - withdrawal;
return balance;
}

BankAccount BankAccount::operator+(const BanAccount &acct)
{
BanAccount sum(9999, 0);
sum.balance = BankAccount::balance + acct.balance;
return sum;
}

bool BankAccount::operator>(BankAccount account)
{
// write your code here
if (myAccount > yourAccount)
cout << "My account has more than your account" << endl;
}
bool BankAccount::operator<(BankAccount account)
{
// write your code here
if (myAccount < yourAccount)
cout << "Your account has more than mine" << endl;
}
bool BankAccount::operator==(BankAccount account)
{
// write your code here
if (myAccount == yourAccount)
cout << "Our accounrds have the same amount" << endl;
}

ostream& operator<<(ostream& out, BankAccount account)
{
// provide code
}
istream& operator>>(istream& in, BankAccount& account)
{
// provide code
}


int main()
{
BankAccount myAccount, yourAccount (1111, 100, 0.12);
double increment = 4.50; int val = 2;

//the following statment demonstrate that your overloaded insertion operators works
cout << myAccount <<endl;
cout <<yourAccount<<endl;
//the following statement demonstrate that your extraction operator works
cin >> myAccount;

//The following statement dipalys that += ans -= work
myAccount += increment;
cout <<myAccount;
myAccount -= increment;
cout <<myAccount;

//The following statements demonstrate that the + operaotr works
BankAccount temp;
temp = myAccount + yourAccount;
cout <<temp;

//The following statements demonstrate that the < operaotr works
cout <<(myAccount<yourAccount);

//The following statements demonstrate that the > operaotr works
cout <<(myAccount>yourAccount);

//The following statements demonstrate that the == operaotr works
cout <<(myAccount==yourAccount);
system ("PAUSE");
return 0;
}
Last edited on
You forgot to "Write your question here", we have no idea what you want.
better?
Still missing a question. You are just showing the assignment. What exactly is not working or what would you like help with?
You have been developing a BankAccount class for Parkville Bank that contains several fields and functions.

Add arithmetic operators that operate as follows:
» The += operator takes a double parameter, which can represent a deposit (or credit) to be added to the BankAccount balance. (If the parameter is negative, it will represent a withdrawal or debit from the account.)
» The + operator takes an integer parameter that increases the account number, returning a new BankAccount object with the new account number.
Include < and > operators that determine whether one account is less than or greater than another. These comparisons are based on balances. Include an == operator that makes a comparison based on account numbers.
Include extraction and insertion operators for the class.
If you do not already have one, create a default constructor that assigns 0 to all the class fields.
Write a main()function that declares an array of five BankAccount objects. (Use the default constructor, so all the data fields will be initialized to 0s.) For each account, prompt the user for a series of transactions. The user enters a positive number for each deposit, a negative number for each withdrawal, and a 0 to quit entering transactions for an account. After the user has entered transactions for all five accounts, display the resulting details for each BankAccount. Save the file as BankAccountPartE.cpp.
Alter the main()function so that the user is prompted for starting account data instead of accepting the default 0 values. Save the file as BankAccountPartF.cpp.
Modify the main()function so that no two accounts are allowed with the same account number. Reprompt the user for a new account number when a duplicate occurs. Save the file as BankAccountPartG.cpp.
Modify the main()function to display the data for the accounts with the highest and lowest balances after all the data has been entered. Save the file as BankAccountPartH.cpp.
You just posted the assignment again..

admin wrote:
When You Ask Choose your forum carefully
Be sensitive in choosing where you ask your question. You are likely to be ignored if you:
•post your question to a forum where it's off topic
•post a very elementary question to a forum where advanced technical questions are expected, or vice-versa

Use meaningful, specific subject headers
The subject header is your golden opportunity to attract qualified experts' attention. Don't waste it on babble like 'Please help me' Don't try to impress us with the depth of your anguish; use the space for a super-concise problem description instead.

More generally, imagine looking at the index of an archive of questions, with just the subject lines showing. Make your subject line reflect your question well enough that the next guy searching the archive with a question similar to yours will be able to follow the thread to an answer rather than posting the question again.

Write in clear, grammatical, correctly-spelled language
Expressing your question clearly and well is important. Spend the extra effort to polish your language. It doesn't have to be stiff or formal. But it has to be precise.

Don't TYPE IN ALL CAPS; this is read as shouting and considered rude.

If you write like a semi-literate boob you will very likely be ignored. So don't use instant-messaging shortcuts.

Be precise and informative about your problem
•Describe the symptoms of your problem carefully and clearly.
•Describe the environment in which it occurs (machine, OS, application, whatever).
•Describe the research you did to try and understand the problem before you asked the question.
•Describe the diagnostic steps you took to try and pin down the problem yourself before you asked the question.

Do the best you can to anticipate the questions a respondent will ask, and answer them in advance in your request for help.

Volume is not precision
You need to be precise and informative. This end is not served by simply dumping huge volumes of code or data into a help request. If you have a large, complicated test case that is breaking a program, try to trim it and make it as small as possible.

This is useful for at least three reasons. One: being seen to invest effort in simplifying the question makes it more likely you'll get an answer, Two: simplifying the question makes it more likely you'll get a useful answer. Three: In the process of refining your bug report, you may develop a fix or workaround yourself.

Describe the problem's symptoms, not your guesses
It's not useful to tell programmers what you think is causing your problem. So, make sure you're telling them the raw symptoms of what goes wrong, rather than your interpretations and theories. Let them do the interpretation and diagnosis. If you feel it's important to state your guess, clearly label it as such and describe why that answer isn't working for you.
Describe the goal, not the step

If you are trying to find out how to do something, begin by describing the goal. Only then describe the particular step towards it that you are blocked on.
Often, people who need technical help have a high-level goal in mind and get stuck on what they think is one particular path towards the goal. They come for help with the step, but don't realize that the path is wrong. It can take substantial effort to get past this.

Be explicit about your question
Open-ended questions tend to be perceived as open-ended time sinks. Those people most likely to be able to give you a useful answer are also the busiest people (if only because they take on the most work themselves). People like that are allergic to open-ended time sinks, thus they tend to be allergic to open-ended questions.

You are more likely to get a useful response if you are explicit about what you want respondents to do (provide pointers, send code,..). This will focus their effort and implicitly put an upper bound on the time and energy a respondent must allocate to helping you.

When asking about code
Don't ask others to debug your broken code without giving a hint what sort of problem they should be searching for. Posting a few hundred lines of code, saying "it doesn't work", will get you ignored. Posting a dozen lines of code, saying "after line 7 I was expecting to see <x>, but <y> occurred instead" is much more likely to get you a response.

If you simply want a code review, say as much up front, and be sure to mention what areas you think might particularly need review and why.


http://www.cplusplus.com/forum/beginner/1/

giblit wrote:
Still missing a question. You are just showing the assignment. What exactly is not working or what would you like help with?


*fixed quote tag had [ instead of ]
Last edited on
I'm getting a bunch of errors. Can I just post all of them?
Compiler errors? Sure most of the time they say exactly what is wrong though and the key to fixing that is to solve the first one then try and compile and repeat. Since most of the times the first error will cause numerous others. So ignore all but the first.
Topic archived. No new replies allowed.