![]() |
|
#1
|
|||
|
|||
Help with class, member functions and consructorHello, I'm new here. I'm having trouble with an excersice program. I can't seem to implement a debit function that will deduct from the initial balance of an account, as well as a credit function.
It asks to create a class called Account. The class should include one data member of type int to represent the account balance. Your class should prode a construtor that recieves an initial balance and uses it to initialize the data member. It should also validate it that it's greater or equal to 0.. Okay, my problem is that it requres three member funcitons. Member function credit should add an amount to the current balance. Member function debit should withdraw money from the Account and should ensure that the debit amount does not exceed the Account's balance. Member funciton getBalance should return the current balance. Create a program that creates two Account objects and tests the member functios of class Account. This is my code so far: CPP / C++ / C Code:
I hope I'm the right track. Thanks |
|
#2
|
|||
|
|||
Re: Help with class, member functions and consructorQuote:
The code looks good, as far as it goes. Thank you for using code tags. (How many times have I said that for a first post? --- Not many.) Just give the debit() and credit() functions parameters (arguments). Then calculate the new balance as the balance - the argument (for debit()) or balance + the argument (for credit()). Assuming integers (which you are using everywhere): CPP / C++ / C Code:
Then, in main(), to credit your account number 1 with, say, 100: CPP / C++ / C Code:
Regards, Dave |
|
#3
|
|||
|
|||
Re: Help with class, member functions and consructorThanks for the help. It worked.
|
Recent GIDBlog
Meeting the local Iraqis by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The