The ABC Hardware Company\" has hired you to write a program for it\'s Accounts R
ID: 3855465 • Letter: T
Question
The ABC Hardware Company" has hired you to write a program for it's Accounts Receivable department (AR are accounts that owe ccounts that owe money to the company because they have purchased items and have not yet paid for them) There are two types of input data 1) A master file in ascending order by customer number (customer numbers are 4 digits long). The file also contains a 20 character customer name and a balance due. 2) A transaction file that contains records of each transaction. This file is also in ascending order by customer number There should be more than one transaction record per master record. Each related group of data in a fle b called a record. A record should be stored in a structure. Each record starts with a character, "O* for order or "P for payment. Each record also contains the tour-digit customer number, a four-digit transaction number, and up to three more values It the code is 'or, the record contains the ltem ordered (20 characters), the quanthy ordered (an integer) plus the cost of the item. (You must multiply to get the total cost) If the code is "P", the record contains the amount of the payment You are to read in records one at a time from the two files and use the transaction file records to file. Process all transaction records transaction record contains a "P" in column 1, subtract the payment from the balance due. K Balance of ABC Company (That is the sum of the balances due for each customer. transaction file records to update the master the next master recordlfthe for each master record belore going on to record contains an "O" in column 1, calculate the order amount and add it to the balance due. If the payment from the balance due. Keep a nunning total of the AR Your program should. Check for errors such as duplicate master records or records in the transaction file that do not appear in the master file. After processing a master record and all It's transactions the program should which lists the customer name, number, previous balance (balance before transactions were performed) transactions, and the final balance due (balance after transactions are prepare an invoice for each customer all performed. The output should look something like this.. CUSTOMER NAMECUSTOMER NUMBER PREVIOUS BALANCE $XXX.XX ITEM ORDERED ITEM ORDERED PAYMENT ITEM ORDERED $ ORDER AMOUNT $ ORDER AMOUNT PAYMENT AMOUNT $ ORDER AMOUNT TRANSACTION # TRANSACTION TRANSACTION # BALANCE DUE data using at least 7 Dont forget, payments reduce the balance and orders increase it. You are to create your own customers with an average of 5 transactions each.Explanation / Answer
SOLUTION:
# include <iostream>
# include <fstream>
# include <iomanip>
# include <string>
using namespace std;
struct master {
double custnum;
char name[100];
double balance;
};
struct transactions {
char transtype;
int custnum;
int transnum;
char item[100];
int quantity;
double price;
double amountpaid;
};
int main ()
{
ifstream masterfile ("MASTER.txt");
ifstream transfile ("TRANSACTION.txt");
int prevbalance[7];
master main [7];
for (int i=0; !masterfile.eof(); i++) {
masterfile>>main[i].custnum>>main[i].name>>main[i].balance;
}
for (int i=0;!masterfile.eof();i++) {
cout << main[i].custnum<<" ";
cout << main[i].name<<" ";
cout << main[i].balance<<" "<<
endl<<endl;
prevbalance[i] = main[i].balance;
}
double companybalance = 0;
double orderamt=0;
transactions tran[35];
for (int i=0; !transfile.eof(); i++) {
transfile>> tran[i].transtype;
cout<<tran[i].transtype<<" ";
if (tran[i].transtype == 'O') {
transfile>>tran[i].custnum;
cout<<tran[i].custnum<<" ";
transfile>> tran[i].transnum;
cout<<tran[i].transnum<<" ";
transfile>>tran[i].item;
cout<<tran[i].item<<" ";
transfile>>tran[i].quantity;
cout<<tran[i].quantity<<" ";
transfile>>tran[i].price;
cout<<tran[i].price<<" "<<endl<<endl;
orderamt= tran[i].price*tran[i].quantity;
main[i].balance+= orderamt;
companybalance += main[i].balance;
}
else if (tran[i].transtype == 'P'){
transfile>>tran[i].custnum;
cout<<tran[i].custnum<<" ";
transfile>> tran[i].transnum;
cout<<tran[i].transnum<<" ";
transfile>>tran[i].amountpaid;
cout<<tran[i].amountpaid<<endl<<endl<<endl;
main[i].balance-tran[i].amountpaid;
companybalance += main[i].balance;
}}
for(int i=0; i<50; i++) {
cout<<"Name: "<< main[i].name <<" Customer #: "<< main[i].custnum<<endl<<endl;
cout<<"Previous Balance "<<prevbalance[i]<<endl;
for(int j=0; j<7; j++){
cout<<"Transaction #: "<<tran[j].transnum<<" "<<tran[j].item<<" $"<<orderamt<<endl; }
cout<<"Balance Due: "<<main[i].balance<<endl;
}
}
MASTER FILE:
TRANSACTION FILE:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.