Enjoy forums? Start your own community for free. | Welcome to C++ Game Dev. We hope you enjoy your visit.
You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.
Join our community!
If you're already a member please log in to your account to access all of our features:
|
Bank Account Simulator
| Stenny |
|

C++ Composer
        
Group: Members
Posts: 475
Member No.: 49
Joined: 17-January 06

|
Hello there reader, After reading some books (C++ for dummies, which is quite a good book!  ) I now know about classes, pointer, and functions. After I read about those I thought it was a good idea to first create a program with them and become familiar with them. So I came up with a banksaving simulator. You could deposit, withdraw money and check you're balance. After all, there are a lot here who posted a program...now it's my turn  There might be easier way to do these things, but remember I had to use pointers, classes and functions. Please give critics, here it is: | CODE | #include <cstdio> #include <cstdlib> #include <iostream> using namespace std;
class saving { public: int accountNumber; float balance; };
void deposit(int amount, saving* pAccount) { pAccount->balance += amount; }
void withdraw(int amount, saving* pAccount) { pAccount->balance -= amount; }
float getBalance(saving* pAccount) { return pAccount->balance; }
int main(int nNumberofArgs, char* pszArgs[]) { saving account; bool correct = false; int option; float amount;
while (correct == false) { system("CLS"); cout << "Welcome to you're very own banksaving program.\n" << "Here you can simulate you're own bank account\n" << "and in that check up you're balance. (yes I know,\n" << "you can also use a calculator)" << endl << "What is you're bankaccountnumber: "; cin >> account.accountNumber; cout << "What is you're current balance: "; cin >> account.balance;
cout << "\nGood, is this information correct?\naccountnumber: " << account.accountNumber << "\ncurrent balance: " << account.balance << "\n0 - no\n1 - yes" << endl;
cin >> correct; }
while (true) { system("CLS"); cout << "Now, what do you want to do?\n" << "1 - Deposit money\n" << "2 - Withdraw money\n" << "3 - Check my balance\n" << "4 - Quit\n"; cin >> option;
if (option == 1) { cout << "\nHow much money do you want to deposit?\n"; cin >> amount; deposit(amount, &account); cout << amount << " is deposited." << endl; system("PAUSE"); } if (option == 2) { cout << "\nHow much money do you want to withdraw?\n"; cin >> amount; withdraw(amount, &account); cout << amount << " is withdrawn." << endl; system("PAUSE"); } if (option == 3) { amount = getBalance(&account); cout << "You're balance is: " << amount << "." << endl; system("PAUSE"); } if (option == 4) { break; } }
system("CLS"); cout << "Thank you for using this program." << endl;
system("PAUSE"); return 0; } |
--------------------
 BLOOP!
|
|
|
| Neken |
|

DirectX Guru
         
Group: Global Moderators
Posts: 515
Member No.: 11
Joined: 24-September 05

|
defining a class method in the class definition is touchy. it all depends of where you declare it.
if you define the class in a source file (.cpp), it won't change anything ... like this :
| CODE | class saving { public: int m_accountNumber; float m_balance;
void deposit(int amount) { m_balance += amount; }
void withdraw(int amount) { m_balance -= amount; }
float getBalance() { m_return balance; } };
|
HOWEVER, if you declare your class in a header (.h) and define some methods there too, they will be inline and you will show their content :
inline : the code in inline functions is not compiled there. except, it is copied where it is needed then compiled there. if you use it really often, and it is kinda big, it can really make you .exe bigger. since (.h) are never compiled, it's kinda logic the defined function there will be inline.
show their content : most of the time, in a header, you don't want users of the class to see all the implementation of it. they want to see a brief view of the class possibilities, their methods.
--------------------
|
|
|
 Free Forums with no limits on posts or members.
Track this topic
Receive email notification when a reply has been made to this topic and you are not active on the board.
Subscribe to this forum
Receive email notification when a new topic is posted in this forum and you are not active on the board.
Download / Print this Topic
Download this topic in different formats or view a printer friendly version.
|