Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need Help with my Project 2 I havea added below my Completed Code from Project

ID: 3802639 • Letter: I

Question

I need Help with my Project 2 I havea added below my Completed Code from Project 1 that Project 2 is based off of. I need help creating the bank.h header file that declares the structures and functions, creating the bank.cpp file that implements the functions delcared in bank.h and I need help creating the Project2.cpp that is built off the Project1.cpp code I provided below. Please help do this project! I know some parts of this assignment is unspecificed but the instructor said to our best best judgment in the instructions so I hope that helps! Again Please someone help!

P.S: I also included the instructions to Project 1 for reference to know what my Project1.cpp code is about.

Project1.cpp

#include<iostream>
#include <fstream>
#include <string>
using namespace std;
struct bank
{
int accNumber;
string Fname, Lname;
float balance;
};
static int j = 0;
struct bank B[5];
void read_from_file(const char* filename)
{
   /*Variable declarations*/
ifstream infile;
/*Opening file*/
infile.open (filename);
int i=0;
if (infile.is_open())
{
    /*Reading all details from file*/
while(!infile.eof()) // To get you all the lines.
{
  
   infile>>B[i].accNumber;
   infile>>B[i].Fname; // Saves the line in STRING.
   infile>>B[i].Lname;
   infile>>B[i].balance;
   /*To prevent read last line twice*/
if( infile.eof() )
       {
          break;
       }
   j++;
   i++;
  
  
}
/*Printing all account details after reading*/
for (i = 0; i<j; i++){
cout << B[i].accNumber << " " << B[i].Fname << " " << B[i].Lname << " " << B[i].balance << ' ';
}
infile.close();
}
}
int addAccount()
{
int accNum,i;
string fname, lname;
float balance;
cout << " --- Provide details --- ";
cout << "Acc Number: "; cin >> accNum;
for (i = 0; i<j; i++)
{
if (B[i].accNumber == accNum)
{
cout << "Error: No changes should be made to the database ";
return 0;
}
}
j = j + 1;
B[i].accNumber = accNum;
cout << "first name: "; cin >> B[i].Fname;
cout << "last name: "; cin >> B[i].Lname;
cout << "Balance:"; cin >> B[i].balance;
}
void deleteAccount()
{
int accNum;
cout << "Enter account number: "; cin >> accNum;
for (int i = 0; i<j; i++)
{
if (B[i].accNumber == accNum){
for (int k = i; k<j - 1; k++)
B[k] = B[k + 1];
}
}
}
void searchAccount()
{
int accNum;
cout << "Enter account number: "; cin >> accNum;
for (int i = 0; i<j; i++)
{
if (B[i].accNumber == accNum){
cout << B[i].accNumber << " " << B[i].Fname << " " << B[i].Lname << " " << B[i].balance << " ";
}
}
}
int withdraw()
{
float withd;
int accNum,flag=0;
cout << "Enter account number from you want to withdraw:";
cin >> accNum;
for (int i = 0; i<j; i++)
{
if (B[i].accNumber == accNum)
{
    flag=0;
cout << "Enter withdraw amount : ";
cin >> withd;
if (B[i].balance >= withd){
B[i].balance = B[i].balance - withd;
cout << "Total :" << B[i].balance << " ";
return 0;
}
else{
cout << "Error: No changes should be made to the database ";
return 0;
}
}
else{
flag=1;
}
}
if(flag==1){
    cout << "Error: No changes should be made to the database ";
return 0;
}
}
int deposit()
{
float dep;
int accNum,flag=0;
cout << "Enter account number you want to Deposit:";
cin >> accNum;
for (int i = 0; i<j; i++)
{
    flag=0;
if (B[i].accNumber == accNum)
{
cout << "Enter deposit amount : ";
cin >> dep;
B[i].balance = B[i].balance + dep;
cout << "Total :" << B[i].balance << " ";
return 0;
}
else{
flag=1;
}
}
if(flag==1){
    cout << "Error: No changes should be made to the database ";
return 0;
}
}
int transfer()
{
float tran;
int fromAcc, toAcc, fr, to, i, f1, f2;
cout << "Enter account number you want to transfer from "; cin >> fromAcc;
cout << "to "; cin >> toAcc;
for (i = 0; i<j; i++)
if (B[i].accNumber == fromAcc){
f1 = 1;
fr = i;
}
for (i = 0; i<j; i++)
if (B[i].accNumber == toAcc){
f2 = 1;
to = i;
}
if (f1 == 1 && f2 == 1)
{
cout << "Enter amount to transfer : ";
cin >> tran;
if (B[fr].balance >= tran){
B[to].balance = B[to].balance + tran;
B[fr].balance = B[fr].balance - tran;
}
else{
cout << "Error: No changes should be made to the database ";
return 0;
}
}
else{
cout << "Error: No changes should be made to the database ";
return 0;
}
}
void list()
{
for (int i = 0; i<j; i++)
cout << B[i].accNumber << " " << B[i].Fname << " " << B[i].Lname << " " << B[i].balance << " ";
}
/*Write into file*/
void write_into_file(const char* filename){
   int i;
   ofstream myfile (filename);
   if (myfile.is_open()) {
      
   for(i=0;i<j;i++){
       myfile<<B[i].accNumber<<" ";
   myfile<<B[i].Fname<<" "; // Saves the line in STRING.
   myfile<<B[i].Lname<<" ";
   myfile<<B[i].balance<<" ";
  
   }
  
}
}
int main()
{
int op,i;
char ch;
read_from_file("account.txt");
do{
cout << "-- Operations menu --- ";
cout << " 1. Add an Account "
"2. Delete an Account "
"3. Search for an account by account number and display the account info "
"4. Make a Withdraw "
"5. Make a Deposit "
"6. Transfer money from one account to another "
"7. List all accounts ";
cout << "Choose the operation : ";
cin >> op;
switch (op){
case 1: addAccount();
break;
case 2: deleteAccount();
break;
case 3: searchAccount();
break;
case 4: withdraw();
break;
case 5: deposit();
break;
case 6: transfer();
break;
case 7: list();
break;
default: cout << "Invalid operation ";
exit(0);
}
cout << "Do you wants more operation (Y/y) by default No : ";
cin >> ch;
} while (ch == 'Y' || ch == 'y');
/*Writing into File at the End of all operations*/
write_into_file("account.txt");

}

Project 2 Instructions

C201 Team Project 2

1 Goal

The purpose of this assignment is to get you familiar with structures, pointers, and linked list. Your goal is to extend the bank database application you implemented in Project 1.

2 Details and testing

Your final program should include three files: project2.cpp that is based on project1.cpp; bank.h that declares the structures and functions; and bank.cpp that implements the functions declared in bank.h.

The details are described below.

   Start with your finished project 1 (if you did not finish project 1, send me an email and I will give you my copy of the completed project 1).

   Your bank.h file should contain (1) the declaration of a data structure (say account), which is the node of a linked list used to store account information; and (2) at least three function declarations (two are used to insert a node into the linked list and one is used to show the contents in the linked list).

   Your bank.cpp file should contain the definitions (implementations) of the functions declared in bank.h file.

Based on project 1, for every transaction, the following information should be stored in a text file (say transactions.txt).

Account number

Transaction type (withdraw / deposit) o Amount of money associated with the transaction o Date and time of the transaction.

A transaction is defined as either a deposit or a withdraw.

Add an account is considered as a deposit transaction. Delete an account is NOT considered as a transaction.

A transfer is considered as two transactions (withdraw and deposit) associated with two accounts.

Add three more options to your main program (project2.cpp):

o List all records in the increasing order of account number; o List all the records in the increasing order of account balance; o List all the transactions (there is no order requirement).

   To implement the new options “List all records in the increasing order of account number” and “List all the records in the increasing order of account balance”, your main program (project2.cpp) need to use the data structure and functions declared and defined in bank.h and bank.cpp.           To list the records in some order, first you should read all the accounts from the database: for each account, create a node (instance of data structure, say account) and insert it (in some order) into a linked list, and second you display the records in the linked list.

3 Notes

   Some parts of the assignment are unspecified. Use your best judgment. State your assumptions clearly. Document your code properly.

     You do not need to rewrite the functions you implemented in project 1 with structures and linked list.

Structures and linked list should be used only if needed in the new functions you added in project 2.

The transactions information you implement in this project will be used in Project 3.

You are free to choose your new team members.

Anything that is not clear, please ask the instructor.

You must state clearly your team members at the beginning of the program.

4 Submission

Upload your source code files (.cpp and .h) using canvas. One team just needs to make one submission.

Project 1 Instructions

C201 Team Project 1

1 Goal

The purpose of this assignment is to get you familiar with Streams and File I/O. Your goal is to create a simple bank database (file) where all the individual accounts are stored in a file.

2 Requirements

The following data should be stored corresponding to each account:

Account Number: an integer number (must be unique for every account)

Name: two words corresponding to the first and last name Balance: a float point number

Your program should provide a menu of options that allow performing any of the following operations:

Add an account

Delete an account

Search for an account by account number and display the account info

Make a withdrawal

Make a deposit

Transfer money from one account to another List all accounts

Your program should be coded in a way such that all previous changes are written to the file before any new operations are performed.

3 Testing

Your program must be able to handle the following abnormal situations:

   For add an account option, if an existing account number is entered, the program should respond with a message and no new account should be created

   For delete an account option, if the account number could not be found, a message should be displayed and no account should be deleted

   For withdrawal operation, if the account number does not exist or the balance is not sufficient, a message should be displayed and no changes should be made to the database

   For deposit operation, if the account number does not exist, a message should be displayed and no changes should be made to the database

   For transfer operation, if the source account number or the destination account number does not exist, or the balance of the source account is not sufficient, a message should be displayed and no changes should be made to the database

4 Notes

Please ask the instructor if any part of the assignment is not clear. State your assumptions clearly. Document your code properly. Check and handle all error conditions related to file I/O and logical errors related to account operations (e.g. overdraws).

You must state clearly your team members at the beginning of the program.

5 Submission

Upload your source code files (.cpp and .h) using canvas. One team just needs to make one submission.

Explanation / Answer

#include<iostream>
#include <fstream>
#include <string>
using namespace std;
struct bank
{
int accNumber;
string Fname, Lname;
float balance;
};
static int j = 0;
struct bank B[5];
void read_from_file(const char* filename)
{
   /*Variable declarations*/
ifstream infile;
/*Opening file*/
infile.open (filename);
int i=0;
if (infile.is_open())
{
    /*Reading all details from file*/
while(!infile.eof()) // To get you all the lines.
{
  
   infile>>B[i].accNumber;
   infile>>B[i].Fname; // Saves the line in STRING.
   infile>>B[i].Lname;
   infile>>B[i].balance;
   /*To prevent read last line twice*/
if( infile.eof() )
       {
          break;
       }
   j++;
   i++;
  
  
}
/*Printing all account details after reading*/
for (i = 0; i<j; i++){
cout << B[i].accNumber << " " << B[i].Fname << " " << B[i].Lname << " " << B[i].balance << ' ';
}
infile.close();
}
}
int addAccount()
{
int accNum,i;
string fname, lname;
float balance;
cout << " --- Provide details --- ";
cout << "Acc Number: "; cin >> accNum;
for (i = 0; i<j; i++)
{
if (B[i].accNumber == accNum)
{
cout << "Error: No changes should be made to the database ";
return 0;
}
}
j = j + 1;
B[i].accNumber = accNum;
cout << "first name: "; cin >> B[i].Fname;
cout << "last name: "; cin >> B[i].Lname;
cout << "Balance:"; cin >> B[i].balance;
}
void deleteAccount()
{
int accNum;
cout << "Enter account number: "; cin >> accNum;
for (int i = 0; i<j; i++)
{
if (B[i].accNumber == accNum){
for (int k = i; k<j - 1; k++)
B[k] = B[k + 1];
}
}
}
void searchAccount()
{
int accNum;
cout << "Enter account number: "; cin >> accNum;
for (int i = 0; i<j; i++)
{
if (B[i].accNumber == accNum){
cout << B[i].accNumber << " " << B[i].Fname << " " << B[i].Lname << " " << B[i].balance << " ";
}
}
}
int withdraw()
{
float withd;
int accNum,flag=0;
cout << "Enter account number from you want to withdraw:";
cin >> accNum;
for (int i = 0; i<j; i++)
{
if (B[i].accNumber == accNum)
{
    flag=0;
cout << "Enter withdraw amount : ";
cin >> withd;
if (B[i].balance >= withd){
B[i].balance = B[i].balance - withd;
cout << "Total :" << B[i].balance << " ";
return 0;
}
else{
cout << "Error: No changes should be made to the database ";
return 0;
}
}
else{
flag=1;
}
}
if(flag==1){
    cout << "Error: No changes should be made to the database ";
return 0;
}
}
int deposit()
{
float dep;
int accNum,flag=0;
cout << "Enter account number you want to Deposit:";
cin >> accNum;
for (int i = 0; i<j; i++)
{
    flag=0;
if (B[i].accNumber == accNum)
{
cout << "Enter deposit amount : ";
cin >> dep;
B[i].balance = B[i].balance + dep;
cout << "Total :" << B[i].balance << " ";
return 0;
}
else{
flag=1;
}
}
if(flag==1){
    cout << "Error: No changes should be made to the database ";
return 0;
}
}
int transfer()
{
float tran;
int fromAcc, toAcc, fr, to, i, f1, f2;
cout << "Enter account number you want to transfer from "; cin >> fromAcc;
cout << "to "; cin >> toAcc;
for (i = 0; i<j; i++)
if (B[i].accNumber == fromAcc){
f1 = 1;
fr = i;
}
for (i = 0; i<j; i++)
if (B[i].accNumber == toAcc){
f2 = 1;
to = i;
}
if (f1 == 1 && f2 == 1)
{
cout << "Enter amount to transfer : ";
cin >> tran;
if (B[fr].balance >= tran){
B[to].balance = B[to].balance + tran;
B[fr].balance = B[fr].balance - tran;
}
else{
cout << "Error: No changes should be made to the database ";
return 0;
}
}
else{
cout << "Error: No changes should be made to the database ";
return 0;
}
}
void list()
{
for (int i = 0; i<j; i++)
cout << B[i].accNumber << " " << B[i].Fname << " " << B[i].Lname << " " << B[i].balance << " ";
}
/*Write into file*/
void write_into_file(const char* filename){
   int i;
   ofstream myfile (filename);
   if (myfile.is_open()) {
      
   for(i=0;i<j;i++){
       myfile<<B[i].accNumber<<" ";
   myfile<<B[i].Fname<<" "; // Saves the line in STRING.
   myfile<<B[i].Lname<<" ";
   myfile<<B[i].balance<<" ";
  
   }
  
}
}
int main()
{
int op,i;
char ch;
read_from_file("account.txt");
do{
cout << "-- Operations menu --- ";
cout << " 1. Add an Account "
"2. Delete an Account "
"3. Search for an account by account number and display the account info "
"4. Make a Withdraw "
"5. Make a Deposit "
"6. Transfer money from one account to another "
"7. List all accounts ";
cout << "Choose the operation : ";
cin >> op;
switch (op){
case 1: addAccount();
break;
case 2: deleteAccount();
break;
case 3: searchAccount();
break;
case 4: withdraw();
break;
case 5: deposit();
break;
case 6: transfer();
break;
case 7: list();
break;
default: cout << "Invalid operation ";
exit(0);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote