Design a program that will serve as a database for keeping track of a student’s
ID: 3635587 • Letter: D
Question
Design a program that will serve as a database for keeping track of a student’s checking account and its history. This application will allow for the entering of checks (payee, date, amount, check number) and the entering of deposits (date and amount) and store that information into a database (text file). The application will also need to be able to retrieve that information based on data that is to be input by the user of the program.Your program should be interactive, presenting the user with a menu of choices, such as the following:
1. Enter Deposit
2. Enter Check/Withdrawal
3. Search for Check by Payee
4. Search for Checks Written in a Particular Month
5. Show a Listing of All Checks Written/Deposits Made
6. Display Current Checking Balance
7. Save Register to a file
8. Load Register from a file
9. Exit
Here is a brief explanation of what I am looking for to be contained with each menu item:
1. Enter Deposit. The user will be able to enter information pertaining to a deposit to the checking
account. You should ask the user for the date and the amount of the deposit. Either this option, option 2, or option 8 must be done before 3, 4, 5, 6, or 7 can be chosen.
2. Enter Check/Withdrawal. The user will be able to enter information related to a check that is written from the account. The user will need to enter the name of the Payee, the date the check is written, its amount, and the check number. Either this option, option 1, or option 8 must be done before 3, 4, 5, 6, or 7 can be chosen, meaning you must prevent a user from trying options 3, 4, 5, 6, or 7 until option 1, 2 or 8 has been chosen.
3. Search for Check by Payee. This option will prompt the user for a payee’s name (ie., Brian M Morgan) and return any information on checks written to that person. If there have been not been any checks written to that particular payee, a message stating this fact should be displayed. Information that should be displayed if a match exists for a given payee would include all of the check’s information entered in option 2. NOTE: Your program should not allow the user to do #3 unless #1, #2 or #8 has been performed at least once. The output format should resemble that of what is on the next page:
Check # Payee Date Amount
1005 Brian M Morgan 4/17/2009 ($300.15) 2132 Brian M Morgan 1/17/2010 ($ 68.13)
4. Search for Checks Written in a Particular Month. For this option, your program will output the details for checks written during a particular month (includes month and year, ie February 2010). This output will consist of a table similar to the one above. NOTE: Your program should not allow the user to do #4 unless #1, #2 or #8 has been performed at least once.
5. Show a Listing of All Checks Written/Deposits Made. This option will produce a similar listing to the one in option 3 above, but will simply list every single check and deposit made and its corresponding data. Deposits are shown WITHOUT the () around the amount. It is typical to show withdrawals (negatives) with the (). NOTE: Your program should not allow the user to do #5 unless #1, #2 or #8 has been performed at least once.
6. Display Current Checking Balance. For this option, your program will calculate and output the current balance of the checking account. NOTE: Your program should not allow the user to do #6 unless #1, #2 or #8 has been performed at least once.
7. Save Register to a file. All of the entered data should be written to a data file (plain .txt file is ok) in a format so that it is easy to retrieve later (see below). You must prompt the user for the name of the file.
8. Load Register from a file. Data will be read back into your program from a previously saved data file. You must prompt the user for the name of the file.
9. Exit the program gracefully, including closing all files.
Explanation / Answer
#include "stdafx.h"
#include <iostream.h>
#include <conio.h>
#include <windows.h>
struct accounts{
int acnum1;
int acnum2;
int acnum3;
double balance1;
double balance2;
double balance3;
};
typedef struct accounts account;
account init (account);
account deposit (account);
account withdraw (account);
void query (account);
void showall (account);
int main(int argc, char* argv[])
{
account <strong class="highlight">bank</strong>;
<strong class="highlight">bank</strong> = init (<strong class="highlight">bank</strong>);
char transaction;
while (transaction != 'E'){
cout<<" ++++++++++ ";
cout<<"WORLD BANK ";
cout<<" ++++++++++ ";
cout<<"deposit -----> <press> D ";
cout<<"withdraw -----> <press> W ";
cout<<"Query -----> <press> Q ";
cout<<"Show All -----> <press> S ";
cout<<"Exit -----> <press> E ";
cout<<" ";
cout<<"please select your transaction :";
cin>>transaction;
switch(transaction){
case 'D':
<strong class="highlight">bank</strong> = deposit(<strong class="highlight">bank</strong>);
break;
case 'W':
<strong class="highlight">bank</strong> = withdraw(<strong class="highlight">bank</strong>);
break;
case 'Q':
query(<strong class="highlight">bank</strong>);
break;
case 'S':
showall(<strong class="highlight">bank</strong>);
break;
case 'E' || 'e':
exit(0);
break;
default:
"please select one of the items from the menu item";
break;
}
<strong class="highlight">system</strong>("CLS");
}
return 0;
}
account init (account buffer){
buffer.acnum1 = 11111;
buffer.acnum2 = 22222;
buffer.acnum3 = 33333;
buffer.balance1 = 0;
buffer.balance2 = 0;
buffer.balance3 = 0;
return buffer;
}
account deposit (account <strong class="highlight">bank</strong>){
int ac_num;
double balance,deposit_amt;
cout<<" enter account number";
cin>>ac_num;
switch(ac_num){
case 11111:
cout<< "enter deposit amount ";
cin>>deposit_amt;
<strong class="highlight">bank</strong>.balance1 = <strong class="highlight">bank</strong>.balance1 + deposit_amt;
balance = <strong class="highlight">bank</strong>.balance1;
<strong class="highlight">system</strong>("CLS");
cout<<"TRANSACTION APPROVED";
cout<<" ++++++++++++++++++++++ ";
cout<<"Balance on your account : "<<"#"<<ac_num<<" is $"<<balance;
cout<<" presss ne button to continue";
cout<<endl;
getch();
break;
case 22222:
cout<< "enter deposit amount ";
cin>>deposit_amt;
<strong class="highlight">bank</strong>.balance2 = deposit_amt + <strong class="highlight">bank</strong>.balance2;
balance = <strong class="highlight">bank</strong>.balance2;
<strong class="highlight">system</strong>("CLS");
cout<<"TRANSACTION APPROVED";
cout<<" ++++++++++++++++++++++ ";
cout<<"Balance on your account : "<<"#"<<ac_num<<" is $"<<balance;
cout<<" presss ne button to continue";
cout<<endl;
getch();
break;
case 33333:
cout<< "enter deposit amount ";
cin>>deposit_amt;
<strong class="highlight">bank</strong>.balance3 = deposit_amt + <strong class="highlight">bank</strong>.balance3;
balance = <strong class="highlight">bank</strong>.balance3;
<strong class="highlight">system</strong>("CLS");
cout<<"TRANSACTION APPROVED";
cout<<" ++++++++++++++++++++++ ";
cout<<"Balance on your account : "<<"#"<<ac_num<<" is $"<<balance<<".00";
cout<<" presss ne button to continue";
cout<<endl;
getch();
break;
default:
cout<<"acount number does not exist";
break;
}
return <strong class="highlight">bank</strong>;
}
account withdraw (account <strong class="highlight">bank</strong>){
int ac_num;
double balance,withdrawl_amt;
cout<<" enter account number";
cin>>ac_num;
switch(ac_num){
case 11111:
cout<< "enter withdrawl amount ";
cin>>withdrawl_amt;
<strong class="highlight">bank</strong>.balance1 = <strong class="highlight">bank</strong>.balance1 - withdrawl_amt;
balance = <strong class="highlight">bank</strong>.balance1;
<strong class="highlight">system</strong>("CLS");
cout<<"TRANSACTION APPROVED";
cout<<" ++++++++++++++++++++++ ";
cout<<"Balance on your account : "<<"#"<<ac_num<<" is $"<<balance;
cout<<" presss ne button to continue";
cout<<endl;
getch();
break;
case 22222:
cout<< "enter withdrawl amount ";
cin>>withdrawl_amt;
<strong class="highlight">bank</strong>.balance2 = <strong class="highlight">bank</strong>.balance2 - withdrawl_amt;
balance = <strong class="highlight">bank</strong>.balance2;
<strong class="highlight">system</strong>("CLS");
cout<<"TRANSACTION APPROVED";
cout<<" ++++++++++++++++++++++ ";
cout<<"Balance on your account : "<<"#"<<ac_num<<" is $"<<balance;
cout<<" presss ne button to continue";
cout<<endl;
getch();
break;
case 33333:
cout<< "enter withdrawl amount ";
cin>>withdrawl_amt;
<strong class="highlight">bank</strong>.balance3 = <strong class="highlight">bank</strong>.balance3 - withdrawl_amt;
balance = <strong class="highlight">bank</strong>.balance3;
<strong class="highlight">system</strong>("CLS");
cout<<"TRANSACTION APPROVED";
cout<<" ++++++++++++++++++++++ ";
cout<<"Balance on your account : "<<"#"<<ac_num<<" is $"<<balance<<".00";
cout<<" presss ne button to continue";
cout<<endl;
getch();
break;
default:
cout<<"acount number does not exist";
break;
}
return <strong class="highlight">bank</strong>;
}
void query (account <strong class="highlight">bank</strong>){
int ac_num;
cout<<" enter account number";
cin>>ac_num;
switch(ac_num){
case 11111:
<strong class="highlight">system</strong>("CLS");
cout<<"TRANSACTION APPROVED";
cout<<" ++++++++++++++++++++++ ";
cout<<"Balance on your account : "<<"#"<<ac_num<<" is $"<<<strong class="highlight">bank</strong>.balance1;
cout<<" presss ne button to continue";
cout<<endl;
getch();
break;
case 22222:
<strong class="highlight">system</strong>("CLS");
cout<<"TRANSACTION APPROVED";
cout<<" ++++++++++++++++++++++ ";
cout<<"Balance on your account : "<<"#"<<ac_num<<" is $"<<<strong class="highlight">bank</strong>.balance2;
cout<<" presss ne button to continue";
cout<<endl;
getch();
break;
case 33333:
<strong class="highlight">system</strong>("CLS");
cout<<"TRANSACTION APPROVED";
cout<<" ++++++++++++++++++++++ ";
cout<<"Balance on your account : "<<"#"<<ac_num<<" is $"<<<strong class="highlight">bank</strong>.balance3<<".00";
cout<<" presss ne button to continue";
cout<<endl;
getch();
break;
default:
cout<<"acount number does not exist";
break;
}
}
void showall (account <strong class="highlight">bank</strong>){
<strong class="highlight">system</strong>("CLS");
cout<<"DISPLAYING ALL EXISTING ACCOUNTS";
cout<<" ++++++++++++++++++++++++++++++ ";
cout<<"ACCOUNT BALANCE ";
cout<<"------- ------- ";
cout<<<strong class="highlight">bank</strong>.acnum1<<" "<<<strong class="highlight">bank</strong>.balance1<<" ";
cout<<<strong class="highlight">bank</strong>.acnum2<<" "<<<strong class="highlight">bank</strong>.balance2<<" ";
cout<<<strong class="highlight">bank</strong>.acnum3<<" "<<<strong class="highlight">bank</strong>.balance3<<" ";
cout<<" press ne key to continue";
cout<<endl;
getch();
}
or u can also try with the following
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
#include <fstream.h>
#include <stdlib.h>
#include <dir.h>
#include "Manager.h"
Account_Manager AM;
//These are all the functions used
void Deposit(int bal);
void Withdrawal(int bal);
void Balance(int bal);
void AccManager();
void Menu();
void FinOrganizer();
void Exit();
//These are the variables used
int Dnum;
int bal;
char select;
int main(){
//This function clears the screen everytime the program comes back to
//the main menu function.
// clrscr();
//Main menu function
Menu();
return 0;
}
//The deposit function handles deposits coming into the program
void Deposit(){
clrscr();
cout <<" Enter an amount: $";
cin >>Dnum;
/*The balance is read from the Bank file and is added to the amount
deposited. When starting the program for the first time the bal will
be 0, but when a deposit amount is given, it is added to the bal so
the next time the bal is read from the Bank file it will be what
was added to the bal which was 0 and now the balance becomes the
first deposit and the process continues every time a deposit is made.*/
ifstream balin("Bank.tcd");
balin>>bal;
balin.close();
bal = bal + Dnum;
/*If someone tries to enter an amount which is valid like 0 the program
does not process it. Otherwise it adds it to the bal and displays the
amount deposited and also the new balance.*/
if(Dnum != 0){
ofstream Depo("Bank.tcd");
Depo<<bal;
Depo.close();
cout <<" Amount deposited: $"<<Dnum<<endl;
cout <<" Your balance is now: $"<<bal<<endl;
}else{
cout<<" Incorrect amount, try again."<<endl;
getch();
AccManager();
}
cout <<" Press any key to contine..."<<endl;
getch();
AccManager();
}
//The Withdrawal function is what it says it is. It withdraws any amount
//entered but will not minus the account.
void Withdrawal(){
clrscr();
int Wnum;
cout <<" Enter an amount: ";
cin >>Wnum;
if(Wnum != 0){
ifstream Without("Bank.tcd");
Without>>bal;
Without.close();
bal = bal - Wnum;
if(bal < 0){
cout <<"Your account can not be minus, please enter another amount."<<endl;
getch();
Withdrawal();
}
ofstream Within("Bank.tcd");
Within<<bal;
Within.close();
}
cout <<" Amount withdrewed: $"<<Wnum;
cout <<" Your balance is now: $"<<bal;
cout <<" Press any key to continue..."<<endl;
getch();
AccManager();
}
//The balance function displays what ever amount is in the Bank file
void Balance(){
clrscr();
bal;
ifstream Balout("Bank.tcd");
Balout>>bal;
Balout.close();
/*This "if" function compares the value of the bal integer and if
it contains this number 2408428 it sets it to 0. I did this because,
when I started writing this program the value of bal keep on reseting
to 2408428 which is the amount of an integer value on my
computer(yours maybe different). Though the problem is fixed now
I still use this test to make sure that it does not happen again. You
may want to change it because if someone enters an amount greater than
this number, yes, the program is going to reset the value of balance.*/
if(bal > 2408428){
bal = 0;
}
ofstream Balin("Bank.tcd");
Balin<<bal;
Balin.close();
cout <<" Your current balance is: "<<bal;
cout <<" Press any key to continue..."<<endl;
getch();
AccManager();
}
//This is the overall main menu list
void Menu(){
clrscr();
cout <<" Main Menu"<<endl;
cout <<" ========="<<endl;
cout <<" 1) Account Manager"<<endl;
cout <<" 2) Finance Organizer"<<endl;
cout <<" 3) Quit"<<endl;
cout <<" Enter selection: ";
cin >>select;
if(select == '1'){
AccManager();
}else{
if(select == '2'){
FinOrganizer();
}else{
if(select == '3'){
Exit();
}else{
Menu();
}
}
}
}
//This the main program list
void AccManager(){
clrscr();
cout <<" Account Manager"<<endl;
cout <<" =============="<<endl;
cout <<" 1) Make a Deposit"<<endl;
cout <<" 2) Make a Withdrawal"<<endl;
cout <<" 3) Check your Balance"<<endl;
cout <<" 4) Main Menu"<<endl;
cout <<" 5) Quit"<<endl;
cout <<" Enter your selection: ";
cin >>select;
if(select == '1'){
Deposit();
}else{
if(select == '2'){
Withdrawal();
}else{
if(select == '3'){
Balance();
}else{
if(select == '4'){
Menu();
}else{
if(select == '5'){
Menu();
}else{
AccManager();
}
}
}
}
}
}
void FinOrganizer(){
clrscr();
AM.Manager();
Menu();
}
void Exit(){
clrscr();
cout <<" Program Comments"<<endl;
cout <<" ---------------"<<endl;
cout <<" This program was designed and writen by wongyingyuan,"<<endl;
cout <<" Writing this program was fun for me because"<<endl;
cout <<" this is the first program that I personaly like since I began"<<endl;
cout <<" programing in C++, which is not that long a go. "<<endl;
getch();
}
*end of this program, i save the upsite program in the file name "bank.cpp" .
------------------------------------------------------------------------
*this is a new file, i save it as "manager.h" .
class Account_Manager{
public:
void Manager(){ //Manager is the main program function because it
//controls access to all the other functions.
clrscr();
char select;
cout<<" Finance Organizer"<<endl;
cout<<" =============="<<endl;
cout<<" Add Events(A)"<<endl;
cout<<" Veiw Events(V)"<<endl;
cout<<" Delete Events(D)"<<endl;
cout<<" Post Events(P)"<<endl;
cout<<" About Event Controller(I)"<<endl;
cout<<" Quit(Q)"<<endl;
cout<<" Enter selection: ";
cin>>select;
//This is a very straightforward if else statement.
//To activate any of the proceeding functions you have to type
//the corresponding letter eg (V --> View).
if((select == 'V')||(select == 'v')){
View();
}else{
if((select == 'A')||(select == 'a')){
Add();
}else{
if((select == 'P')||(select == 'p')){
Post();
}else{
if((select == 'Q')||(select == 'q')){
}else{
if((select == 'I')||(select == 'i')){
About();
}else{
if((select == 'D')||(select == 'd')){
Delete();
}else{
Manager(); //if a letter is typed that does not have a corresponding
//function the program loops back and refreshes the main
//menu.
} } } } } } }
int Add(){ //The Add function like the name describes adds new events
//to the program.
clrscr(); //this function clears the screen everytime the add
//function is activated.
//These are the variables that are used for entering information
//like the name, amount, post and balance.
char add;
char Event_Name[20];
int Event_Amount = 0;
int Event_Post = 0;
int Event_Balance = 0;
cout<<" Event Name: ";
cin>>Event_Name; //Note add a name please don't leave any space between
cout<<" Event Amount: ";
cin>>Event_Amount;
Event_Balance = Event_Amount; //Event_Balance equals Event_Amount
//because nothing has been posted yet, otherwise Event_Balance would
//contain the balance from the amount posted.
ofstream NameOut("Combine.cyl"); //This file was created in order to
//hold the name of the file thats going to hold the account information
//for instance the name of the Event you enter eg (phone bill)
//will become the name of the file (phonebill.txt)
//I don't know any other way to merge two separate text.
NameOut<<Event_Name<<".txt"<<endl;
NameOut.close();
char File[20];
ifstream NameIn("Combine.cyl");
NameIn>>File; //the text already being join together is retrieved
//by the variable File as one word.
NameIn.close();
ofstream Out(File); //now it's being saved as a text file and the
//following information is being entered.
Out<<Event_Name<<endl;
Out<<Event_Amount<<endl;
Out<<Event_Post<<endl;
Out<<Event_Balance<<endl;
Out.close();
cout<<" Do you want to add another(y/n): ";
cin>>add;
if((add == 'y')||(add == 'Y')){
Add();
}else{
Manager();
}
}
void Post(){ //The Post function post the amount you entered for the event
//and gives you the balance as and saves that information back
//in the same file.
clrscr();
int E_Num;
int E_Amt;
cout<<" Post Events"<<endl;
cout<<" ============"<<endl;
cout<<" #"<<" "<<"Event Name"<<" "<<"Event Amount"<<" "<<"Event Posted"<<" "<<"Event Balance"<<endl;
cout<<"======================================================================"<<endl;
File_Content(); //this function is described in more detail below.
//After the File_Content function is activated you're left
//with the content of all the files you've entered and by
//selecting an Event Number (1) and the amount you want to
//post (300) you're telling the program to post 300 for file 1.
cout<<" Enter an Event Number: ";
cin>>E_Num;
cout<<" Enter an Event Amount: ";
cin>>E_Amt;
char Event_Name[20];
int Event_Amount;
int Event_Post;
int Event_Balance;
int new_Balance;
char post;
char File_Name[20];
struct ffblk f;
char ff_name[26];
int count = 0;
//the findfirst() function finds all the txt files in the
//corrent folder
int done = findfirst("*.txt",&f,FA_HIDDEN);
while(!done){ //this while function loops brining up all the text file
//in the folder until there is no more.
count++; //this is a counter that adds 1 every time a new file is found.
ifstream In(f.ff_name); //f.ff_name becomes the file name that the information
//is coming out of.
In>>Event_Name;
In>>Event_Amount;
In>>Event_Post;
In>>Event_Balance;
In.close();
done = findnext(&f);
if(count == E_Num){ //if the counted is equal to the number you first entered the loop will stop.
ofstream Out(f.ff_name);
Out<<Event_Name<<endl;
Out<<Event_Amount<<endl;
Out<<E_Amt<<endl;
new_Balance = Event_Balance - E_Amt;
Out<<new_Balance<<endl;
Out.close();
break;
}else{
continue;
}
}
cout<<" The amount <"<<E_Amt<<"> has been posted to Event Number <"<<count<<">."<<endl;
cout<<" Do you want to post another(y/n): ";
cin>>post;
if((post == 'y')||(post == 'Y')){
Post();
}else{
Manager();
}
}
void View(){ //you will be able to view all the events you have entered
clrscr();
cout<<" View Events"<<endl;
cout<<" ============"<<endl;
cout<<" #"<<" "<<"Event Name"<<" "<<"Event Amount"<<" "<<"Event Posted"<<" "<<"Event Balance"<<endl;
cout<<"======================================================================"<<endl;
File_Content();
cout<<" Press any key to go to the main menu...."<<endl;
getchar();
Manager();
}
private:
void File_Content(){ //File_Content is what brings up all the files that is in the
// current folder.
//Everything here was explaned in the post function
char Event_Name[20];
int Event_Amount = 0;
int Event_Post = 0;
int Event_Balance = 0;
struct ffblk f;
char ff_name[26];
int count = 0;
int done = findfirst("*.txt",&f,FA_HIDDEN);
while(!done){
count++;
ifstream In(f.ff_name);
In>>Event_Name;
In>>Event_Amount;
In>>Event_Post;
In>>Event_Balance;
In.close();
cout<<" "<<count<<setw(15)<<Event_Name<<setw(15)<<Event_Amount<<setw(15)<<Event_Post<<setw(15)<<Event_Balance<<endl;
done = findnext(&f);
} getchar();
}
void About(){
clrscr();
char opt;
cout<<" Event Controller"<<endl;
cout<<" ================"<<endl;
cout<<" Hi, I’m wong"<<endl;
cout<<" Do you want to quit or return to main menu(q/m): ";
cin>>opt;
if(opt == 'q'){
exit(1);
}else{
Manager();
}
}
void Delete(){ //The Delete function is very important because after
//the full amount has been posted for an event you
//could delete to save space.
int E_Num;
clrscr();
cout<<" Delete Events"<<endl;
cout<<" ============"<<endl;
cout<<" #"<<" "<<"Event Name"<<" "<<"Event Amount"<<" "<<"Event Posted"<<" "<<"Event Balance"<<endl;
cout<<"======================================================================"<<endl;
File_Content();
cout<<" Enter an Event Number: ";
cin>>E_Num;
char del;
struct ffblk f;
char ff_name[26];
int count = 0;
int done = findfirst("*.txt",&f,FA_HIDDEN);
while(!done){
count++;
ifstream In(f.ff_name);
In.close();
done = findnext(&f);
if(count == E_Num){
remove(f.ff_name);
break;
}else{
continue;
}
}
cout<<" Do you want to delete another(y/n): ";
cin>>del;
if((del == 'y')||(del == 'Y')){
Delete();
}else{
Manager();
}
}
};
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.