In: Computer Science
PLease use c++
Write a checkbook balancing program. The program will read in, from the console, the following for all checks that were not cashed as of the last time you balanced your checkbook: the number of each check (int), the amount of the check (double), and whether or not it has been cashed (1 or 0, boolean in the array). Use an array with the class as the type. The class should be a class for a check. There should be three member variables to record the check number, the check amount, and whether or not the check was cashed. The class for a check will have a member variable of type Money (as defined on page 662 in the book; Display 11.9) to record the check amount. So, you will have a class used within a class. The class for a check should have accessor and mutator functions as well as constructors and functions for both input and output of a check. In addition to the checks, the program also reads all the deposits (from the console; cin), the old and the new account balance (read this in from the user at the console; cin). You may want another array to hold the deposits. The new account balance should be the old balance plus all deposits, minus all checks that have been cashed.
The program outputs the total of the checks cashed, the total of the deposits, what the new balance should be, and how much this figure differs from what the bank says the new balance is. It also outputs two lists of checks: the checks cashed since the last time you balanced your checkbook and the checks still not cashed.
[ edit: if you can, Display both lists of checks in sorted order from lowest to highest check number.]
#include <iomanip>
#include <iostream>
#include <cmath>
using namespace std;
//Declaring_methods
float Check_process(float, float, float); //check_process_method
float Deposit_process(float, float); //deposit_process_method
float Program_End(float, float); //program_end_method
int main ()
{
float my_balance = -1; //will_be_used_to_store_balance, -1 for_initial_flag
char transact_type = 'f'; //transaction_type_(Valid_types: C or D or E)
int exit1 = 0; //used_to_exit_the_program
float totServiceChg; // used_to_store_total_service_charges
const float serviceChg = 0.25; // constant_for_each_service_charge
//Get_initial_balance
cout << "C++ Check Book Balancing Code\n\n";
cout << "Please Enter the Starting Account_Balance: ";
cin >> my_balance;
//Round_balance_to_2_decimal_places
floor(my_balance*pow(10,2))/pow(10,2);
cout << "\nInput_Commands:\n" << "C - Check processing" << "\nD - Depositing";
cout << "\nE - Exit the Program\n";
while ( exit1 == 0){
//user_input
cout << "\nPlease Input transaction type: ";
cin >> transact_type;
//checking_for_case
if (transact_type == 'C'){
cout << "Please Enter the transaction amount: ";
totServiceChg += serviceChg;
floor(totServiceChg*pow(10,2))/pow(10,2);
my_balance = Check_process(my_balance, serviceChg, totServiceChg);
}
//In_case_of_deposit
else if (transact_type == 'D'){
cout << "Please Enter the transaction_amount: ";
my_balance = Deposit_process(my_balance, totServiceChg);
}
//Exit_or_End_Month_Case
else if (transact_type == 'E'){
cout << "End Month Statement: ";
Program_End(my_balance, totServiceChg);
exit1 = 1;
}
else
cout << "Please Enter a correct transaction type. \n";
}
return 0;
}
//Check_process method, that returns the new balance
float Check_process(float my_balance, float serviceChg, float totServiceChg){
float transactionAmount = -1; //flag -1 for_transaction_amount
//Maintains_a_+ve_number_for_transaction
while (transactionAmount <= -1 ){
transactionAmount = 1;
cin >> transactionAmount;
if (!(transactionAmount > 0))
cout << "\nPlease Input a positive no. : ";
}
//process_the_check
cout << "Initializing check for $" << transactionAmount;
my_balance -= transactionAmount;
floor(my_balance*pow(10,2))/pow(10,2);
cout << "\nCurrent_Balance: $";
cout << setprecision(2) << fixed << my_balance;
cout << "\nService_charge: $" << serviceChg;
cout << " as per check policy";
cout << "\nTotal service_charges: $" ;
cout << setprecision(2) << fixed << totServiceChg;
cout << "\n";
return my_balance;
}
//Deposit+process method, returns_new_balance
float Deposit_process(float my_balance, float totServiceChg){
float transactionAmount = -1; // flag -1 for transaction amount
// while_loop_that_maintains_a_+ve_amount
while (transactionAmount <= -1 ){
transactionAmount = 1;
cin >> transactionAmount;
if (!(transactionAmount > 0))
cout << "\nPlease enter a positive number: ";
}
//Deposit_process
cout << "Initializing deposit for $" << transactionAmount;
my_balance += transactionAmount;
floor(my_balance*pow(10,2))/pow(10,2);
cout << "\nBalance: $";
cout << setprecision(2) << fixed << my_balance;
cout << "\nTotal service_charges: $";
cout << setprecision(2) << fixed << totServiceChg;
cout << "\n";
return my_balance;
}
//End_of_the_program
float Program_End(float my_balance, float totServiceChg){
my_balance -= totServiceChg;
cout << "\nFinal_Balance: $";
cout << setprecision(2) << fixed << my_balance;
return my_balance;
}
Output :
Summary : C++ Checkbook Balancing Program for bank accounts that reads from input, the transaction type, checking, depositing as per the requirements.
P.S. Hope this code solution helps you out, please give a thumbs up, as you know it was not easy to code all this within 2 hrs. Have a good day !