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

I need Help Solving My Project 2 I have Added the Completed Code from project 1!

ID: 3862203 • Letter: I

Question

I need Help Solving My Project 2 I have Added the Completed Code from project 1! Please help this is due on Friday Night and cant figure out what to do! Can someone please help me solve this!

#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");

}

C201 Team Project 2 1 Goa 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 files: project2.cpp that is based on project1.cpp. bank.h that Your final program should include three 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 a 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 nked list) Your bank.cpp file should contain the definitions (implementations) of the functions declared in Based on project 1, for every transaction, the following information should be stored in a text file (say transactions txt) o Account number o 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, 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. u 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.

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);
}
cout << "Do you wants more operation (Y/y) by default No : ";
cin >> ch;
} while (ch == 'Y' || ch == 'y');

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