| | |
Another Bank Account class
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2008
Posts: 3
Reputation:
Solved Threads: 0
Hello, everyone. I need help with a bank account class. I was supposed to create a class called Account which houses an attribute called balance that is protected and returns a double data type. There are some other things required of me which have been completed in the coded below. However, now i am being asked to create a menu to deposit, withdraw and show current balance. I am having a problem because what i am doing is not related to the class. Take a look at the code below please and give me some suggestions as to how to make an efficient menu. Help me with deposits and i will endeavor to work on the others.
C++ Syntax (Toggle Plain Text)
#include <iostream.h> //predefined header file #include <stdlib.h> #include <conio.h> #include <iomanip.h> #include <stdio.h> #include <dos.h> #include <ctype.h> class Accounts { //name of class protected: double balance; public: //public member function Accounts(); ~Accounts(); double getbal() const; void withdraw (double); double deposit(double); }; class savingsAccount: public Accounts { public: savingsAccount(double = 0.0); ~savingsAccount(); void payinterest(); void setrate(double); protected: //protected member function double rate; }; class checkingAccount : public Accounts { public: checkingAccount(double = 0.0); ~checkingAccount(); void withdraw (double); protected: double fees; }; Accounts::Accounts() : balance(0.0) { } Accounts::~Accounts(){ } double Accounts::getbal() const { return balance; } void Accounts::withdraw (double amount) { if (amount > 0 && balance >= amount) { balance -= amount; } } double Accounts::deposit (double amount) { if (amount > 0) { balance += amount; } return balance; } savingsAccount::savingsAccount(double initbalance) : rate(0.0) { balance = initbalance; } savingsAccount::~savingsAccount () { } void savingsAccount::payinterest() { balance = balance*rate/365/100; } void savingsAccount::setrate(double r) { if (r >= 0.0) { rate = r; } } checkingAccount::checkingAccount(double initbalance) : fees(0.0) { balance = initbalance; } checkingAccount::~checkingAccount() { } void checkingAccount::withdraw(double amount) { if (amount > 0 && balance >= amount) { balance -= (amount+fees); } } void main() { Accounts a; savingsAccount sa; checkingAccount ca; sa.setrate(16.30); cout<<""<<endl; cout<<""<<endl; cout<<""<<endl; cout<<" WELCOME TO MY ACOOUNTING SYSTEM "<<endl; cout<<""<<endl; cout<<""<<endl; cout<<"Please wait for system load"<<endl; cout<<""<<endl; cout<<" loading..."<<endl; sleep(3); clrscr(); char choice; cout<<" MAIN MENU"<<endl; cout<<""<<endl; cout<<""<<endl; cout<<" 1: Deposit"<<endl; cout<<" 2: Withdraw"<<endl; cout<<" 3: Account Balance"<<endl; cout<<" 4: Exit"<<endl; cout<<"Make Selection using the numbers ('X' to exit)"<<endl; cout<<"---> "<<endl; choice=toupper(getchar()); fflush (stdin); switch(choice) { int dep; case '1': cout<<"Enter amount of money to deposit:"<< endl; cin>>dep; sa.payinterest(); break; case '2': a.getbal(); break; case '3': a.getbal(); break; case '4': break; default: cout<<"Invalid menu item...Please re-enter your choice"<<endl; sleep(2); break; }//end of case cout<<""<<endl; cout<<"Savings Account Balance Before: $"<<sa.getbal()<<endl; cout<<"Checking Account Balance Before: $"<<ca.getbal()<<endl<<endl; //we do some operations here ca.withdraw(6700.43); sa.payinterest(); sa.deposit(1500.00); cout<<"Savings Account Balance After: $"<<sa.getbal()<<endl; cout<<"Checking Account Balance After: $"<<ca.getbal()<<endl; cout<<endl;endl; system("pause"); }
•
•
Join Date: May 2008
Posts: 88
Reputation:
Solved Threads: 9
•
•
•
•
I am having a problem because what i am doing is not related to the class.
•
•
•
•
Take a look at the code below please and give me some suggestions as to how to make an efficient menu
http://msdn.microsoft.com/en-ca/library/h21280bw.aspx
As for making an efficient menu, I would suggest moving all your menu initialization into another method (that stuff where you have "loading" and what not), and then the actual main menu to another method (called menu or whatever). This will just make things cleaner and easier to work with (in my opinion).
Then, based on whatever choice, you can move into separate sub-menus and whatnot (more functions)...I would also suggest you always have an option to return to the main menu (from a sub-menu if you implement this), and possibly might want to look into some error checking.
But if you really want my opinion on how to improve it, I would suggest making a program GUI...would make things way cleaner (from an end-user perspective), and would be a good way for you to start moving away from console applications....If you are interested (and I assume you are on windows), and have time on your hands, then look into Win32 programming.
Optimist: This glass is half full!
Pessimist: This glass is half empty!
Engineering Consultant: This glass is twice as big as it needs to be...
Pessimist: This glass is half empty!
Engineering Consultant: This glass is twice as big as it needs to be...
•
•
Join Date: May 2008
Posts: 3
Reputation:
Solved Threads: 0
How can i get the deposited funds from variable dep to be added to the savings account balance of 1500.
to b added to
in the code from my first post?
{
int dep;
case '1':
cout<<"Enter amount of money to deposit:"<< endl;
cin>>dep;
sa.deposit ();
break;to b added to
//we do some operations here
ca.withdraw(6700.43);
sa.payinterest();
sa.deposit(1500.00);in the code from my first post?
![]() |
Similar Threads
- Bank Account class (C++)
- Bank Account ===>Need help >.< Thk (C++)
- Bank Account Class (C++)
- Unable to view yahoo mail or online bank account etc (Viruses, Spyware and other Nasties)
- need to write a class schema asap (Computer Science)
- Bank account class (C++)
Other Threads in the C++ Forum
- Previous Thread: Sick large number multiplication
- Next Thread: save dialog
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings struct temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





