1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
ofstream fout;
void printReportHeader();
void printInvoiceHeader(string date);
void printLine();
double calcCost();
double accTotal();
void printTotal();
int main()
{
ifstream inputFile;
int transactions;
string date;
int items, unitCost;
// opening input.txt with data
inputFile.open("input.txt");
cout << fixed << setprecision(2);
printReportHeader(); //printing the header function
while (inputFile >> items >> date)
{
double totalCost = 0;
printInvoiceHeader(date); // printing the invoice date
for (int i = 0; i < 28; i++)
{
printLine(); // calls the reference number, name, quantity, price, and total
calcCost(); // calls the calculation price*unit
accTotal(); // calls the acount total for the given invoice
}
}
printTotal(); // prints total
return 0;
}
// calculates the quantity * unit cost to get TOTAL COST
double calcCost()
{
string transactions, date;
ifstream inputFile;
int name, invNum;
double totalCost=0;
double unitCost;
int quantity;
inputFile.open("input.txt");
inputFile >> transactions >> date >>
invNum >> name >> quantity >> unitCost;
// takes a the quantity and mulitplies the unit cost
// to get the total cost per unit given the quantity
totalCost = quantity*unitCost;
return totalCost;
}
// adds up lines to give total cost of invoice
double accTotal()
{
string transactions, date;
ifstream inputFile;
int name, invNum;
double totalCost = 0;
double unitCost;
int quantity;
inputFile.open("input.txt");
inputFile >> transactions >> date >>
invNum >> name >> quantity >> unitCost;
double newTotalCost;
newTotalCost = quantity++*unitCost++; // adds up each lines totals and creatates an new end total
return newTotalCost;
}
//void function that writes the invoice line
void printLine()
{
int transactions;
string date, name;
ifstream inputFile;
double unitCost, total;
int quantity;
int invNum;
inputFile.open("input.txt");
inputFile >> transactions >> date >>
invNum >> name >> quantity >> unitCost;
// prints the line for invoice #, name of par, quantity, and the cost per unit
cout << invNum << " " << name << " " << quantity << " " << unitCost << endl;
}
//void function to print "Total.. with account total
void printTotal()
{
cout << "Total ................................" << accTotal();
cout << endl;
}
//void function for invoice Header with DATE
void printInvoiceHeader(string date)
{
int transactions;
ifstream inputFile;
inputFile.open("input.txt");
inputFile >> transactions >> date;
cout << "Invoice date: " << date << endl << endl;
}
//Void function for report Heade with Company name
void printReportHeader()
{
cout << " Erie Industrial Supply Corporation \n";
}
|