In this C++ practice assignment, the task is to implement an ATM Code in C++ that will do the following:

  1. Enter the account balance
  2. Enter in the money to deposit
  3. Calculate the final balance
  4. Calculate the interest
  5. Display the number of $50 notes available
  6. Generate a random value for the variable amount2Deposit
  7. Display all values to the screen

Const:  As you can see in the ATM code in c++, we have three const declarations for the variables BANKNOTE, INTEREST, MIN_DEPOSIT, and MAX_DEPOSIT. The reason we are using the const keyword in the declaration is to prevent modifications to the data. In simple words, it’s going to be the same assigned value when the program is running.

//----------------------------------------------------------
// Sample test B
// ATM Program
//----------------------------------------------------------
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
 
using namespace std;
 
//--------------------------------------------------
// Global variables
//--------------------------------------------------
const int BANKNOTE = 50;
const double INTEREST = 0.065;
int const MIN_DEPOSIT = 100, MAX_DEPOSIT = 10000;
double accountBalance;
 
int Amount1Deposit, Amount2Deposit;
double totalBalance1, totalBalance2, totalInterest1, totalInterest2;
int noOf50s;
 
//--------------------------------------------------
// Function prototypes
//--------------------------------------------------
int getBanknotes(double & amount);
int getRandom();
int main()
{
cout << "Enter in the account balance\n"; cin >> accountBalance;
 
// For Amount1, the user will enter in the value
// To Deposit
cout << "\nEnter in Amount1 to deposit\n"; cin >> Amount1Deposit;
 
// Calculate final balance
totalBalance1 = accountBalance + Amount1Deposit;
 
// Calculate interest
totalInterest1 = totalBalance1 * INTEREST;
// Display the original balance, amount to withdraw
// number of banknotes, final balance and interest after one year
// For Account 1
cout << "\nAccount 1 Information\n";
cout << "Original Balance" << setw(20) << accountBalance << "\n";
cout << "Amount to Deposit" << setw(18) << Amount1Deposit << "\n";
cout << "Number of $50 Notes" << setw(18) << getBanknotes(totalBalance1) << "\n";
cout << "Final Balance" << setw(30) << totalBalance1 << "\n";
cout << "Interest after 1 Year" << setw(20) << totalInterest1 << "\n";
 
// Generate a random value for amount2Deposit and display
// number of banknotes, final balance and interest after one year
// For Account 2
// Please note here that the columns have not been properly formatted but the objective of the whole program works
Amount2Deposit = getRandom();
totalBalance2 = accountBalance + Amount2Deposit;
 
totalInterest2 = totalBalance2 * INTEREST;
 
cout << "\nAccount 2 Information\n";
cout << "Original Balance" << accountBalance << "\n";
cout << "Amount to Deposit" << Amount2Deposit << "\n";
cout << "Number of $50 Notes " << getBanknotes(totalBalance2) << "\n";
cout << "Final Balance " << totalBalance2 << "\n";
cout << "Interest after 1 Year" << totalInterest2 << "\n";
 
return 0;
}
 
//--------------------------------------------------------------
// Get Bank Notes function implementation
// This will calculate how many 50 dollar notes are required
//--------------------------------------------------------------
int getBanknotes(double& amount)
{
return noOf50s = amount / BANKNOTE;
}
 
//--------------------------------------------------------------
// Get Random function implementation
//--------------------------------------------------------------
int getRandom()
{
// Seed the time
srand(time(NULL));
 
// Generates and returns an integer
// random number in the range 100 and 10000.
return Amount2Deposit = rand()%(MAX_DEPOSIT - MIN_DEPOSIT + 1) + MIN_DEPOSIT;
}

 

Share this post