Question

C++

/*

Colesha Pearman

CIS247C

ATM Application

May 4,2020

*/

//Bring in our libaries

#include"stdafx.h"

#include<iostream>

#include<conio.h>

#include<string>

#include<fstream>//read/write to files

#include<ctime>//time(0)

#include<iomanip>//setpresision std

using namespace std;

 

//create constant vaules-- cannot be changed

const int EXIT_VALUE = 5;

const float DAILY_LIMIT = 400.0f;

const string FILENAME = "Account.txt";

 

//create balance variable

double balance = 0.0;

 

//prototypes

void deposit(double* ptrBalance);

void withdrawal(double* ptrBalance, float dailyLimit);  //overloaded method-this verision does not take withdrawal amount

void withdrawal(double* ptrBalance, float dailyLimit, float amount);  //overloaded method that takes withdrawal amount

 

///Enrty point to the application

int main()

{

 

                //look for the starting balance; otherwise generate a random balance

                ifstream iFile(FILENAME.c_str());

                if (iFile.is_open())

                {

                                // did the file open? if so,read the balance

                                iFile >> balance;

                                iFile.close();

                }

                else

                {

                                //if the file did not open or does not exit,create a

                                //random  for the starting balance

 

                                srand(time(0));

                                const int MIN = 1000;

                                const int MAX = 10000;

                                balance = rand() % (MAX - MIN + 1) + MIN;

                }

 

                cout << fixed << setprecision(2) << "Starting Balance:$" << balance << endl;

 

                //pause before we clear the screen

                cout << "\nPress any key to continue...";

                _getch();

 

                //let's create pointer and set it to the balance variable location

                double*ptrBalance = &balance; //&means "address of"

 

//create loop variable BEFORE the loop

                short choice = 0;

 

                //Start the application

                do

                {

                                //show the menu

                                system("CIS");

                                cout << "Menu\n" << endl;

                                cout << "1)Deposit" << endl;

                                cout << "2)Withdrawal" << endl;

                                cout << "3)Check Balance" << endl;

                                cout << "4)Quick $40" << endl;

                                cout << "5)Exit" << endl;

 

                                //get user input

                                cout << "\nEnter your choice:";

                                cin >> choice;

 

                                //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:

                                                cout << "Showing the current balance..." << endl;

                                                break;

                                case 4:

                                                cout << "Getting a quick $40..." << endl;

                                                break;

                                case 5:

                                                cout << "\nError. Please select from the menu." << endl;

                                                break;

                                }

                                cout << "\nPress any key to continue...";

                                _getch();

                } while (choice != EXIT_VALUE);


// now that the application is over, write the new balance to the file

ofstream oFile(FILENAME.c_str());

oFile << balance << endl;

oFile.close();

 

return 0;

}

 

///Make a deposit

void deposit(double* ptrBalance)

{

// get deposit and validate it

float deposit = 0.0f;

 

do

{

cout << "\nEnter deposit amount:";

 

cin >> deposit;

 

 

if (cin.fail()) // did 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.\n" << endl;

deposit = -1; //set deposit to a "bad" number

continue; //restart the loop

 

}

if (deposit < 0.0f)   //check for negative number

cout << "\nError.Invalid deposit amount.\n" << endl;

} while (deposit < 0.0f);

 

//how do we get the double value location at the pointer?

//Dereference it using an asterisk!

*ptrBalance += deposit;    //same as:*ptrBalance = *ptrBalance + deposit;

 

cout << fixed << setprecision(2) << "\nCurrent ptrBalance: $" << *ptrBalance << endl;  // notice the asterisk

}

 

/// Make a withdrawal

void withdrawal(double* ptrBalance, float dailyLimit)

{

// get the withdrawal(you should vaildate this input)

float amount = 0.0f;

cout << "\nEnter withdrawal amout:";

cin >> amount;

 

//call the overloaded method version that takes

// the balance, dailyLimit, and withdrawal amount

withdrawal(ptrBalance, dailyLimit, amount);

}

 

/// Make a withdrawal- this overload accepts balance, dailyLimit and withdrawal amount

 

void withdrawal(double* ptrBalance, float dailyLimit, float amount)

{

//take away money from account and show the balance

if (amount > dailyLimit)

{

cout << "\nError.Amount eceeds daily limit." << endl;

}

else if (amount > *ptrBalance) //notic the aterisk to derference the pointer!

{

cout << "\nError. Insufficient funds." << endl;

}

else

{

*ptrBalance -= amount; // same as: *ptrBalance = *ptrBalance -amount;

cout << "\nHere is your cash: $" << amount << endl;

}

 

 

cout << fixed << setprecision(2) << "\nCurrent Balance: $" << *ptrBalance << endl;

}





0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 9 more requests to produce the answer.

1 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
C++
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • C++ Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money...

    C++ Banks offer various types of accounts, such as savings, checking, certificate of deposits, and money market, to attract customers as well as meet their specific needs. Two of the most commonly used accounts are savings and checking. Each of these accounts has various options. For example, you may have a savings account that requires no minimum balance but has a lower interest rate. Similarly, you may have a checking account that limits the number of checks you may write....

  • C++ programming I need at least three test cases for the program and at least one...

    C++ programming I need at least three test cases for the program and at least one test has to pass #include <iostream> #include <string> #include <cmath> #include <iomanip> using namespace std; void temperatureCoverter(float cel){ float f = ((cel*9.0)/5.0)+32; cout <<cel<<"C is equivalent to "<<round(f)<<"F"<<endl; } void distanceConverter(float km){ float miles = km * 0.6; cout<<km<<" km is equivalent to "<<fixed<<setprecision(2)<<miles<<" miles"<<endl; } void weightConverter(float kg){ float pounds=kg*2.2; cout<<kg<<" kg is equivalent to "<<fixed<<setprecision(1)<<pounds<<" pounds"<<endl; } int main() { string country;...

  • In c++ please How do I get my printVector function to actually print the vector out?...

    In c++ please How do I get my printVector function to actually print the vector out? I was able to fill the vector with the text file of names, but I can't get it to print it out. Please help #include <iostream> #include <string> #include <fstream> #include <algorithm> #include <vector> using namespace std; void openifile(string filename, ifstream &ifile){    ifile.open(filename.c_str(), ios::in);    if (!ifile){ cerr<<"Error opening input file " << filename << "... Exiting Program."<<endl; exit(1); }    } void...

  • THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #inclu...

    THIS IS FOR C++ PROGRAMMING USING VISUAL STUDIO THE PROGRAM NEEDS TO BE IN C++ PROGRAMMING #include "pch.h" #include #include using namespace std; // Function prototype void displayMessage(void); void totalFees(void); double calculateFees(int); double calculateFees(int bags) {    return bags * 30.0; } void displayMessage(void) {    cout << "This program calculates the total amount of checked bag fees." << endl; } void totalFees() {    double bags = 0;    cout << "Enter the amount of checked bags you have." << endl;    cout <<...

  • im not sure why my code isnt working? include <iostream> #include <iomanip> using namespace std; int...

    im not sure why my code isnt working? include <iostream> #include <iomanip> using namespace std; int main() { int amountOfCoffee; double Price; char salesTaxChargeability; double TotalAmount; const double SALESTAX = 0.035; // 3.5 % cout << "\nEnter the number of pounds of coffee ordered in Pounds :"; cin >> amountOfCoffee; cout << "\nEnter the price of coffee per Pound :"; cin >> Price; cout << "\nIs sales tax Chargeable (y or n): "; cin >> salesTaxChargeability; if ( (salesTaxChargeability ==...

  • Trying to figure out how to complete my fourth case 4 (option exit), write a function...

    Trying to figure out how to complete my fourth case 4 (option exit), write a function that display a “Good Bye” message and exits/log out from user’s account displaying a menu (sign in, balance, withdraw and exit.. #include<iostream> #include <limits> using namespace std; void printstar(char ch , int n); double balance1; int main() { system("color A0"); cout<<"\n\t\t ========================================="<< endl; cout<<"\t\t || VASQUEZ ATM SERVICES ||"<< endl; cout<<"\t\t ========================================\n\n"<< endl; int password; int pincode ; cout<<" USERS \n"; cout<<" [1] -...

  • c++ programming : everything is done, except when you enter ("a" ) in "F" option ,...

    c++ programming : everything is done, except when you enter ("a" ) in "F" option , it does not work. here is the program. #include <iostream> #include <string> #include <bits/stdc++.h> #include <iomanip> #include <fstream> using namespace std; #define MAX 1000 class Inventory { private: long itemId; string itemName; int numberOfItems; double buyingPrice; double sellingPrice; double storageFees; public: void setItemId(long id) { itemId = id; } long getItemId() { return itemId; } void setItemName(string name) { itemName = name; } string...

  • Please use C++ and add comments to make it easier to read. Do the following: 1)...

    Please use C++ and add comments to make it easier to read. Do the following: 1) Add a constructor with two parameters, one for the numerator, one for the denominator. If the parameter for the denominator is 0, set the denominator to 1 2) Add a function that overloads the < operator 3) Add a function that overloads the * operator 4) Modify the operator<< function so that if the numerator is equal to the denominator it just prints 1...

  • C++ Check Book Program I need to have a checkbook program that uses the following items....

    C++ Check Book Program I need to have a checkbook program that uses the following items. My code that I have appears below. 1) Math operations using built-in math functions 2) Class type in a separate .h file with member functions (accessor functions, get, set, show, display find, etc). There needs to be an overloaded function base/derived classes or a template. 3) Binary File #include <iostream> using namespace std; int main() {     double checking,savings;     cout<<"Enter the initial checking...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT