I just need to pass data from processesTransaction () function to the createFile
ID: 3648607 • Letter: I
Question
I just need to pass data from processesTransaction () function to the createFile () function.If the formating is not right I do apologize I copied and pasted from visual studio's. Most of the information In this program is comments so that someone understands what I was doing when I did it. I just need to understand what to do, can you please, please help me. I am having the most trouble with the out file.
#include <fstream> // file stream header file
#include <string> // string header file
#include <iostream> // for cout and cin header file
#include <iomanip> // formating header file
using namespace std;
void inputHeader(); // function prototype for the header (the columns)
void processesTransaction (); // function prototype that accesses the account file
void createFile(); // function prototype that accesses the accountSummary file
int main ()
{
inputHeader(); // my call to the header (the columns)
cout<< fixed << showpoint << setprecision (2); // decimal places that my doubles are using
processesTransaction (); // this is my call to access my account file
createFile(); // this is my call to access my accountSummary file
system ("pause");
return 0;
}
void inputHeader() //input header
{
cout<<"TRANS ID"<<setw(13)<<"DATE"<<setw(14)<<"AMOUNT"<<setw(14)"TYPE"<<setw(14)<<"TOTAL"<<endl;
}
// My function that accesses the account file
void processesTransaction ()
{
ifstream infile; // the variable name for my account file
int transactionID;
double total=0; // set the total to zero for a new account
double amount;
string date;
string type;
infile.open("account.txt"); //open the file
//check for file
if (infile.fail())
{
cerr<<"file does not exist:";
abort();
}
//checking for file input
while(! infile.eof())
if (infile >> transactionID)
{
infile >> date>>amount>>type;
if (type == "withdrawal") // if statement for withdrawal/deposit.
{
total=total-amount;
}
else
total = total+amount;
// reading from file
cout<<transactionID<<setw(14)<<date<<setw(14)<<amount<<setw(14)<<type<<setw(14)<<total;
if (total<0)
{
cout<< " overdrawn ";
}
cout<<endl;
}
infile.close();
}
void createFile() // function that creates the accountSummary file
{
ofstream outfile; // variable name for my accountSummary file
outfile.open("accountSummary.txt"); // open the file
/*number of transactions
Date of last transaction
the final total after all transactions are processed*/
// display
outfile<<"Number of transactions: "<< endl;
outfile<< "Date of the last transaction: "<< endl;
outfile<< "Balance: "<< endl;
outfile.close(); //closing accountSummary file
}
Explanation / Answer
can you please simplify the code ? use kodomo for that