Menu

[solved]-Ciud Lupel Include Include Include Include Include Using Namespace Std Void Deposit Double Q39056225

CIUD Lupel #include <conio.h> #include <string> #include <fstream> #include <ctime> #include <iomanip> using namespace std; vWeek 1: Lab //pause before we clear the screen system(pause); Step 5 Lets create the application loop. The loop should runWeek Lab 710/2010 Ilshow the balance cout << Showing the current balance... << endl; break; case 4: llget a quick $40 coutWeek Entry point to the application int main() Now, go below the end of the main function (very bottom of your file) and creaWeek 1: Lab 7/10/2019 case 2: cout << Making a withdrawal... << endl; break; New code: case 2: withdrawal ptrBalance, DAILYWeckt: cout << nError. Insufficient funds. << endl; else *ptrBalance -- amount; cout << nHere is your cash: $ << amount
Need help with these last few steps pleaseCIUD Lupel #include <conio.h> #include <string> #include <fstream> #include <ctime> #include <iomanip> using namespace std; void deposit(double* ptrBalance); void withdrawal (double” ptrBalance, float dailyLimit); void withdrawal (double* ptrBalance, float dailyLimit, float amount); const int EXIT_VALUE – 5; const float DAILY_LIMIT – 400.0f; const string FILENAME = “Account.txt”; double balance – 0.; ON //Entry point to the application int main() ifstream File(FILENAME.c_str(); double – ptrBalance = 8balance; //make balance pointer if(IFile.is_open() iFile >> balance;// take data from file File.close(); D else// if file not exsist get random value balance srand(time()); const int MIN – 100e; const int MAX = 10000; balance – rand() % (MAX – MIN + 1) + MIN; 44 cout << fixed << setprecision(2) << “Starting Balance: $” << balance << endl;// print value for starting balance double * ptr Balance – Sbalance; 45 system(“pause”); 100% Week 1: Lab //pause before we clear the screen system(“pause”); Step 5 Let’s create the application loop. The loop should run until the user hits the exit value that we set as a constant at the top of the main method. This loop code should follow the code in Step 4. It is inside of the main function. In the loop code, notice that we print a menu of 5 options for the user. The user enters a number from 1 to 5 and we read it into the variable, choice. Then we do a switch statement on the value of choice; this is like an if statement. A different action is taken depending on the value of choice. At this time, we just print a statement of what we plan to do: shortly, we will replace some of these statements with a call to a function. See the explanation on “stubs” below the code. Il create loop variable BEFORE the loop short choice = 0; I/start the application loop do l/show the menu system(“cls”); //clears the console screen cout << “Menuln” << endl; cout << “1) Deposit” << endl; cout << “2) Withdrawal” << endl; cout << “3) Check Balance” << endl; cout << “4) Quick $40” << endl; cout << “5) Exit” << endl; i/get user input cout << “nEnter your choice:”; cin >> choice; l/run code based on the user’s choice switch (choice) case 1: cout << “Making a deposit…” << endl; break; case 2 cout << “Making a withdrawal…” << endl; break; case 3: Week Lab 710/2010 Ilshow the balance cout << “Showing the current balance…” << endl; break; case 4: llget a quick $40 cout << “Getting a quick $40…” << endl; break; case 5: cout << “nGoodbye” << endl; break; default: cout << “nError. Please select from the menu.” << endl; break; i/pause system(“pause”); while (choice != EXIT_VALUE ); Run your application now. How does it look? When you press 1. you will receive a temporary message called a stub. Each choice gives you a message about what the choice will eventually do. This structure is called stubs programming. You create a stub for each branch. You have all experienced stubs programming. Do you remember going to a website and clicking on a link only to get an “Under Construction” message? The website builders are using stubs programming. Step 6 Now, let’s do the first stub. In the switch statement, replace the first case with a method call. In other words, under “case 1.”, replace the statement: cout << “Making a deposit…” << endl; with: deposit( ptr Balance ); //passing a pointer so only four bytes have to go across the system bus! Go to the top of your file and create a prototype just above the point where you started the main function. Prototypes are also called method forwards. Prototypes let us point to the method and then create the method below the main function. The top of the main function is shown in green so you can see better where to place the prototype code: i/prototypes void deposit( double ptrBalance : Week Entry point to the application int main() Now, go below the end of the main function (very bottom of your file) and create the first method. Notice from the prototype that we are passing a pointer, so that the double, which is eight bytes. will only require four bytes to pass across the system bus. Four bytes for the pointer is half the size of the double. When we create pointers to our obiects later in the course, we will point to the objects made up of hundreds of bytes with just a four byte pointers. Il/Make a deposit void deposit ( double* ptrBalance ) Ilget deposit and validate it float deposit = 0.0f; do cout << “nEnter deposit amount”: cin >> deposit; if (cin.fail() ) Ildid they give us a character instead of a number? cin.clear(); //clears fail state cin.ignore(INT16_MAX, ‘n’); // clears keyboard buffer cout << “nError. Please use numbers only.in” << endl; deposit = -1; //set deposit to a “bad” number continue; //restart loop else if (deposit < 0.0f) I/check for negative number cout << “nError. Invalid deposit amount.In” << endl; while (deposit < 0.01); l/how do we get the double value located at the pointer? I/Dereference it using an asterisk! *ptrBalance += deposit: cout << fixed << setprecision(2) << “nCurrent ptrbalance: $” << *ptrBalance << endl; Step 7 Go to your second case in the switch. Replace the stub with a call to the withdrawal method. Old code: Week 1: Lab 7/10/2019 case 2: cout << “Making a withdrawal…” << endl; break; New code: case 2: withdrawal ptrBalance, DAILY_LIMIT); break; Go to your prototypes section just above the main function and add two prototypes for the withdrawal method. We are going to overload the withdrawal method to give us more flexibility Remember, if you have two methods with the same name but different parameters, the two methods are called an overloaded method. I/ prototypes void deposit( double ptrBalance ): void withdrawal double ptrBalance, float dailyLimit); Iloverloaded method – this version does not take withdrawal amount void withdrawal double* ptrBalance, float dailyLimit, float amount); lloverloaded method that takes withdrawal amount Go to the very bottom of the file, below the main function and below the deposit method. Add the code for the two overloads of the withdrawal method. ll/Make a withdrawal void withdrawal double ptr Balance, float dailyLimit) Ilget the withdrawal and validate float amount = 0.0f; cout << “nEnter withdrawal amount”: cin >> amount: i/call the overloaded method version that takes i/the balance, dailyLimit and withdrawal amount withdrawal ptrBalance, dailyLimit, amount): Wi/Make a withdrawal – this overload accepts balance, daily Limit and withdrawal amount void withdrawal double *ptrBalance, float dailyLimit, float amount) Il/take away money from the account and show the balance if (amount > daily Limit) cout << “nError. Amount exceeds daily limit.” << endl; else if (amount>”ptrBalance) Weckt: cout << “nError. Insufficient funds.” << endl; else *ptrBalance — amount; cout << “nHere is your cash: $” << amount << endl; cout << fixed << setprecision(2) << “nCurrent balance: $” << *ptrBalance << endi Step 8 Go to your switch statement and delete the stubs. Replace them with the third and fourth cases as follows: case 3: Ilshow the balance cout << fixed << setprecision(2) << “nCurrent Balance: $” << balance << endl; break; case 4: l/get a quick $40 withdrawal ptrBalance, DAILY_LIMIT, 40.0f): break; When the user hits the exit value and the loop ends, you need to save the current balance to the file. Add this code to the end of the main function – after the end of the while loop and before the system(“pause”). These are shown to help you place the new code: while (choice != EXIT_VALUE ); I/now that the application is over, write the new balance to the file ofstream ofile( FILENAME.c_str()); ofile << balance << endl; ofile.close(); system(“pause”); return 0; Show transcribed image text CIUD Lupel #include #include #include #include #include using namespace std; void deposit(double* ptrBalance); void withdrawal (double” ptrBalance, float dailyLimit); void withdrawal (double* ptrBalance, float dailyLimit, float amount); const int EXIT_VALUE – 5; const float DAILY_LIMIT – 400.0f; const string FILENAME = “Account.txt”; double balance – 0.; ON //Entry point to the application int main() ifstream File(FILENAME.c_str(); double – ptrBalance = 8balance; //make balance pointer if(IFile.is_open() iFile >> balance;// take data from file File.close(); D else// if file not exsist get random value balance srand(time()); const int MIN – 100e; const int MAX = 10000; balance – rand() % (MAX – MIN + 1) + MIN; 44 cout

Expert Answer


Answer to CIUD Lupel #include #include #include #include #include using namespace std; void deposit(double* ptrBalance); void with… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *