summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
diff options
context:
space:
mode:
authorTaylor Rogers <[email protected]>2022-11-28 15:23:49 -0800
committerTaylor Rogers <[email protected]>2022-11-28 15:23:49 -0800
commitd19c28ad5573d4994a59b60edd9dca911b76f045 (patch)
treeab6ab6bac8f61b44576113807360c7e1bf5bead5 /BlankConsoleLab/BlankConsoleLab.cpp
parentAdded headers to input file data display (diff)
downloadcst116-lab3-taylorrog-d19c28ad5573d4994a59b60edd9dca911b76f045.tar.xz
cst116-lab3-taylorrog-d19c28ad5573d4994a59b60edd9dca911b76f045.zip
Formatting
Diffstat (limited to 'BlankConsoleLab/BlankConsoleLab.cpp')
-rw-r--r--BlankConsoleLab/BlankConsoleLab.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/BlankConsoleLab/BlankConsoleLab.cpp b/BlankConsoleLab/BlankConsoleLab.cpp
index 15d941d..571be2d 100644
--- a/BlankConsoleLab/BlankConsoleLab.cpp
+++ b/BlankConsoleLab/BlankConsoleLab.cpp
@@ -1,5 +1,7 @@
// Lab3
//
+// CST116
+//
// Taylor Rogers
//
@@ -29,6 +31,7 @@ void PrintTotalsAndSummary(ofstream& out, int totalRecords, int totalPassengers,
int main()
{
+ // MAX set to 50 since big.txt is <50
int pick[MAX];
int drop[MAX];
int psgr[MAX];
@@ -38,17 +41,16 @@ int main()
float total[MAX];
float cpm[MAX];
int record_counter(0);
-
string fnameinput;
- // Filename from user input
+ // Filename string from user input
cout << "Enter the file name you wish to read data from: ";
cin >> fnameinput;
cout << endl;
ifstream inFile;
- ofstream outFile("lab3_Report.txt");
+ ofstream outFile("CST116-Lab3_Report-Rogers.txt");
inFile.open(fnameinput);
@@ -65,25 +67,27 @@ int main()
}
else
{
- cout << "Trouble Opening File";
- cout << "\n\n\t\t ** About to EXIT NOW! ** ";
+ cout << "Trouble Opening File" << endl;
+ cout << "Exiting..." << endl;
}
}
else
{
- cout << "Trouble Opening File";
- cout << "\n\n\t\t ** About to EXIT NOW! ** ";
+ cout << "Trouble Opening File" << endl;
+ cout << "Exiting..." << endl;
}
return 0;
}
+// Reads data from the user specified file
int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[])
{
int counter = 0;
inFile >> pick[counter] >> drop[counter] >> psgr[counter] >> dist[counter] >> fare[counter] >> toll[counter]; // Priming Read
+ // Column headers
cout << "Data read from file:" << endl;
cout << setw(5) << "Pickup" << resetiosflags(ios::left)
<< setw(10) << "Dropoff" << resetiosflags(ios::left)
@@ -94,7 +98,6 @@ int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[],
while (!inFile.eof())
{
-
cout << setiosflags(ios::left)
<< setw(5) << pick[counter] << resetiosflags(ios::left)
<< setw(10) << drop[counter] << resetiosflags(ios::left)
@@ -111,9 +114,11 @@ int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[],
}
+// Writes data to the output file Lab3_Report.txt. This function includes a "total" and "cost per mile" column which it calculates using the file data. The passenger and cost totals are summed.
void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], float total[], float cpm[],
int counter)
{
+ // Column headers
outFile << "Here is the Output File" << endl;
outFile << endl;
outFile << setw(5) << "Pickup" << resetiosflags(ios::left)
@@ -127,12 +132,15 @@ void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], floa
for (int r = 0; r <= counter - 1; r++)
{
+ // New columns for total cost and cost per mile
total[r] = fare[r] + toll[r];
cpm[r] = total[r] / dist[r];
+ // Summing
psgrsum += psgr[r];
totalsum += total[r];
+ // Transcribing data from file and adding total and cmp columns
outFile << setiosflags(ios::left)
<< setw(5) << pick[r] << resetiosflags(ios::left)
<< setw(10) << drop[r] << resetiosflags(ios::left)
@@ -147,6 +155,7 @@ void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], floa
}
+// This function outputs the total number of entries from the data file, along with some statistics derived from the provided data.
void PrintTotalsAndSummary(ofstream& outFile, int totalRecords, int totalPassengers, float totalSum)
{
float avgcost = 0;