IN NEED OF SOME HELP WHERE DO I GO FROM HERE? It reads commands from a bank.txt
ID: 3772175 • Letter: I
Question
IN NEED OF SOME HELP WHERE DO I GO FROM HERE?
It reads commands from a bank.txt file. Your program must process the following four commands.
Create account amount Deposit account amount Withdraw account amount Balance account
In all of the above commands, account is an integer and amount is a double. The following program behavior is required –
Valid account numbers are 1-9. This requires the program to have an array of references to Account objects.
If the first word on any line contains a command other than the four listed above, an error message should be displayed and that line ignored.
The create command creates a new account object with the given account number and initial balance. If an account already exists with that number an error message should be displayed and the command ignored.
The Deposit and Withdraw commands perform the indicated operation on an existing account. If no account with that number has been created, an error message is displayed and the command ignored.
The Balance command displays the balance of the requested account. No change to the account occurs. If no account with that number has been created, an error message is displayed and the command ignored.
Helpful Hints
I have included a working example and sample bank.txt file along with the assignment.
The .exe file and .txt files can be copied into any Windows directory to be run. You can
explore other behaviors of the program by modifying the .txt file.
Your Account class can be used exactly as it is although you will need to copy it to your
new project for Lab 5
One way to skip the rest of a line if there is a bad command or account number is – string junk;
if (inFile.peek() != ' ') getline(inFile, junk);
Test your program extensively to make sure it behaves as it should. I will use a different bank.txt file to test your programs.
This is not an assignment that can be completed in a single day. Don’t put it off. Upload: Your .h and .cpp files.
THIS IS WHAT I HAVE SO FAR,
HEADER.H
#ifndef Header_H
#define Header_H
#include <iostream>
#include <string>
class Name{
private:
int nextName;
string CommonName[];
void findRecursive(string name, int low, int high);
public:
Name();
void addName(pair CommonName);
void sorthName();
int findLinear(string name);
int findBinary(string name);
};
class CommonName{
private:
int newField;
string name;
public:
int gerOrdinal();
string getName();
CommonName(int ord, string aName);
};
#endif
HEADER.CPP
#include "Account.h"
using namespace std;
Account::Account()
{
balance = 0;
}
Account::Account(int newId, double initialBalance)
{
id = newId;
balance = initialBalance;
}
void Account::setId(int newId)
{
id = newId;
}
void Account::setBalance(double newBalance)
{
balance = newBalance;
}
void Account::withdraw(double amount)
{
balance = balance - amount;
}
void Account::deposit(double amount)
{
balance = balance + amount;
}
MAIN.CPP
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
#include "Account.h"
int main() {
double checkBal = 0.0, savBal = 0.0;
double checkDeposit = 0.0, savDeposit = 0.0;
double checkWdraw = 0.0, savWdraw;
Account checkAccount;
Account savingsAccount;
checkAccount.setId(11777);
savingsAccount.setId(22999);
cout << setprecision(2) << fixed << endl;
cout << "Please enter the initial balance for Account #" << checkAccount.getId() << ": $";
cin >> checkBal;
checkAccount.setBalance(checkBal);
cout << "Please enter the initial balance for Account #" << savingsAccount.getId() << ": $";
cin >> savBal;
savingsAccount.setBalance(savBal);
cout << "How much will you deposit into Account #" << checkAccount.getId() << ": $";
cin >> checkDeposit;
checkAccount.deposit(checkDeposit);
cout << "How much will you withdraw from Account #" << checkAccount.getId() << ": $";
cin >> checkWdraw;
checkAccount.withdraw(checkWdraw);
cout << "The current Balance in Account #" << checkAccount.getId()
<< " is: $" << checkAccount.getBalance()
;
cout << " How much will you deposit into Account #" << savingsAccount.getId() << ": $";
cin >> savDeposit;
savingsAccount.deposit(savDeposit);
cout << "How much will you withdraw from Account #" << savingsAccount.getId() << ": $";
cin >> savWdraw;
savingsAccount.withdraw(savWdraw);
cout << "The current Balance in Account #" << savingsAccount.getId()
<< " is: $" << savingsAccount.getBalance() << " ";
return 0;
}
Explanation / Answer
Create a table Deposit with fields AccNo Number (8) Primary key Name Character (25) Not Null Branch Character (20) Amount Number (8, 2) Not Null Branches can be CALICUT, COCHIN, or TRICHUR. SQL> CREATE TABLE DEPOSIT( 2 ACCNO NUMBER(8) PRIMARY KEY, 3 NAME CHARACTER(25) NOT NULL, 4 BRANCH CHARACTER(20) CHECK(BRANCH IN('CALICUT','COCHIN','TRICHUR')), 5 AMOUNT NUMBER(8,2) NOT NULL); Table created. SQL> INSERT INTO DEPOSIT VALUES(&ACCNO,'&NAME','&BRANCH',&AMOUNT); Enter value for accno: 1001 Enter value for name: SYAM KUMAR Enter value for branch: CALICUT Enter value for amount: 55000 old 1: INSERT INTO DEPOSIT VALUES(&ACCNO,'&NAME','&BRANCH',&AMOUNT) new 1: INSERT INTO DEPOSIT VALUES(1001,'SYAM KUMAR','CALICUT',55000) 1 row created. SQL> / Enter value for accno: 1002 Enter value for name: RAM KUMAR Enter value for branch: COCHIN Enter value for amount: 25000 old 1: INSERT INTO DEPOSIT VALUES(&ACCNO,'&NAME','&BRANCH',&AMOUNT) new 1: INSERT INTO DEPOSIT VALUES(1002,'RAM KUMAR','COCHIN',25000) 1 row created. SQL> / Enter value for accno: 1003 Enter value for name: KRISHNA KUMAR Enter value for branch: TRICHUR Enter value for amount: 45000 old 1: INSERT INTO DEPOSIT VALUES(&ACCNO,'&NAME','&BRANCH',&AMOUNT) new 1: INSERT INTO DEPOSIT VALUES(1003,'KRISHNA KUMAR','TRICHUR',45000) 1 row created. SQL> / Enter value for accno: 1004 Enter value for name: MOHAN KUMAR Enter value for branch: COCHIN Enter value for amount: 5000 old 1: INSERT INTO DEPOSIT VALUES(&ACCNO,'&NAME','&BRANCH',&AMOUNT) new 1: INSERT INTO DEPOSIT VALUES(1004,'MOHAN KUMAR','COCHIN',5000) 1 row created. SQL> / Enter value for accno: 1005 Enter value for name: ANIL KUMAR Enter value for branch: TRICHUR Enter value for amount: 35000 old 1: INSERT INTO DEPOSIT VALUES(&ACCNO,'&NAME','&BRANCH',&AMOUNT) new 1: INSERT INTO DEPOSIT VALUES(1005,'ANIL KUMAR','TRICHUR',35000) 1 row created. SQL> / Enter value for accno: 1006 Enter value for name: DEVA KUMAR Enter value for branch: CALICUT Enter value for amount: 60000 old 1: INSERT INTO DEPOSIT VALUES(&ACCNO,'&NAME','&BRANCH',&AMOUNT) new 1: INSERT INTO DEPOSIT VALUES(1006,'DEVA KUMAR','CALICUT',60000) 1 row created. SQL> / Enter value for accno: 1007 Enter value for name: ASHOK KUMAR Enter value for branch: CALICUT Enter value for amount: 45000 old 1: INSERT INTO DEPOSIT VALUES(&ACCNO,'&NAME','&BRANCH',&AMOUNT) new 1: INSERT INTO DEPOSIT VALUES(1007,'ASHOK KUMAR','CALICUT',45000) 1 row created. SQL> SELECT * FROM DEPOSIT WHERE AMOUNT=(SELECT MAX(AMOUNT) FROM DEPOSIT); ACCNO NAME BRANCH AMOUNT ---------- ------------------------- -------------------- ---------- 1006 DEVA KUMAR CALICUT 60000 Q:5 Display all the records from the table DEPOSIT. SQL> SELECT * FROM DEPOSIT; ACCNO NAME AMOUNT BRANCH ---------- ------------------------- ---------- -------------------- 1001 SYAM KUMAR 55000 CALICUT 1002 RAM KUMAR 25000 COCHIN 1003 KRISHNA KUMAR 45000 TRICHUR 1004 MOHAN KUMAR 5000 COCHIN 1005 ANIL KUMAR 35000 TRICHUR 1006 DEVA KUMAR 60000 CALICUT 1007 ASHOK KUMAR 45000 CALICUT 7 rows selected.