Note that there are some explanatory texts on larger screens.

plurals
  1. POConfusion with Constructors, Classes, and separate files
    text
    copied!<p>I'm supposed to write a main program that prompts the user for a name and initial balance. Your program should create two objects, one using the default constructor and another using the constructor that allows the user-entered name and balance to be used to initialize its object. Then prompt the user for one amount to be credited to an account and one amount to be debited. Use creditAccount to credit money to the object created with the parameterized constructor and debitAccount to subtract the debit amount from the object created with the default constructor. Use displayBalance to display the balance in both objects. Repeat the cycle above until the user enters an option to exit the program. I just don't understand where to go from here to have it actually build and use the class. Main.cpp</p> <pre><code>//9/17/2013 // //I have read and understand the Lab Submittal Policy document on BB. #include &lt;iostream&gt; #include &lt;sstream&gt; #include &lt;string&gt; #include "Account.h" using namespace std; int main() { char Redo; string CustomerName; do { float InitialBalance = -1; float balance1 = 0; float balance2 = 0; Account Account; Account.CreditAccount (balance1, InitialBalance); Account.DebitAccount (balance2, InitialBalance); Account.DisplayBalance (CustomerName, balance1, balance2); //Asks user if they want redo the program cout &lt;&lt; "Would you like to redo the program?\n"; cout &lt;&lt; "Please enter Y or N: \n \n"; cin &gt;&gt; Redo; }while(Redo == 'Y' || Redo == 'y'); char exitchar; //Exit's the program. cout &lt;&lt; "\nPress any key and &lt;enter&gt; to exit the program.\n"; cin &gt;&gt; exitchar; return 0; } </code></pre> <p>Account.h</p> <pre><code>using namespace std; class Account { public: float balance1; float balance2; string CustomerName; float InitialBalance; float CreditAccount(float&amp; balance1, float InitialBalance); float DebitAccount(float&amp; balance2, float InitialBalance); float DisplayBalance(string CustomerName, float balance1, float balance2); Account (); Account(float balance) { SetInitialBalance(balance); } void Account::SetInitialBalance(float balance) { if(balance &gt;= 0) { InitialBalance = balance; } else cout &lt;&lt; "Error! Initial Balance cannot be less than 0." &lt;&lt; endl; } }; Account::Account(void) { string CustomerName; cout &lt;&lt; "Your Account Machine" &lt;&lt; endl; cout &lt;&lt; "Please enter your last name." &lt;&lt; endl; cin &gt;&gt; CustomerName; while(InitialBalance &lt; 0) { cout &lt;&lt; "Please enter your account balance. No Commas." &lt;&lt; endl; cin &gt;&gt; InitialBalance; if(InitialBalance &lt; 0) cout &lt;&lt; "Error account balance must be positive." &lt;&lt; endl; } } float Account::CreditAccount(float&amp; balance1, float InitialBalance) { float CreditInput = -1; while(CreditInput&lt;0){ cout &lt;&lt; "Would you like to credit the account? Enter the amount you would like to credit." &lt;&lt; endl; cin &gt;&gt; CreditInput; if (CreditInput&lt;0) cout &lt;&lt; "Credit must be positive." &lt;&lt; endl; } balance1 = (CreditInput + InitialBalance); return balance1; } float Account::DebitAccount(float&amp; balance2, float InitialBalance) { float DebitInput = 0; while((InitialBalance - DebitInput)&lt;0){ cout &lt;&lt; "Would you like to debit the account? Enter the amount you would like to debit." &lt;&lt; endl; cin &gt;&gt; DebitInput; if((InitialBalance-DebitInput)&lt;0) cout &lt;&lt; "You cannot debit more than you have avalaible." &lt;&lt; endl; } balance2 = (InitialBalance - DebitInput); if( DebitInput &gt; InitialBalance) { cout &lt;&lt; "Debit amount exceeds account balance." &lt;&lt; endl; return 0; } else return balance2; } float Account::DisplayBalance(string CustomerName, float balance1, float balance2) { cout &lt;&lt; "Customer Name: " &lt;&lt; CustomerName &lt;&lt; endl; cout &lt;&lt; "Account Balance for credited account: " &lt;&lt; balance1 &lt;&lt; endl; cout &lt;&lt; "Account Balance for debited account: " &lt;&lt; balance2 &lt;&lt; endl; return 0; } </code></pre> <p><em>Updated</em> I updated my code and I just have one question. I would like to know why my program is not reading in any CustomerName or InitialBalance. Everything else works to my liking.</p> <p>Thank you again!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload