In: Computer Science
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.
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 <iostream>
#include <cstdlib>
#include <cctype>
#include "checkbook.cpp"
using namespace std;
class checkbook
{
private:
float balance;
public:
void initbalance(float x);
void writecheck(float x);
void makedeposit( float x);
float getbalance() const;
};
//Here is the class definition, checkbook.cpp.
void checkbook::initbalance(float x)
{
if (x >=0)
balance = x;
else
cout <<"Invalid initialization "<<x<<endl;
}
void checkbook::writecheck(float x)
{
if (x > balance)
cout << "Insufficient funds -- current balance is"<<balance<<endl;
else
balance -=x;
}
void checkbook::makedeposit(float x)
{
if (x > 0)
balance += x;
else
cout <<"Invalid Deposit "<<x<<endl;
}
float checkbook::getbalance()const
{
return balance;
}
//Here's a little program which uses the class
int main()
{
checkbook mycheckbook; // mycheckbook is an object; checkbook is a class
mycheckbook.initbalance(500.00); // start with a balance of$500
mycheckbook.writecheck(50.0); // write a check for $50
mycheckbook.writecheck(345.76); // write a check for $345.76
mycheckbook.makedeposit(300.0); // make the deposit $300
cout<<"current balance : $"<<mycheckbook.getbalance()<<endl;
return 0;
}
This is my partial solution that you may want to use and modify.give a thumbs up if u get what u asked for, Please let me know if you need help more.