summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
blob: 275786cd47592bb51791198e92af43b235fd6f77 (plain) (blame)
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 <fstream> // For the files!!!!
#include <iomanip> // For manipulators & formatting options
using namespace std;
const int MAX = 50;
int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float
	dist[], float fare[], float toll[]);
void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int
	psgr[], float dist[], float fare[], float toll[],
	int counter);
void PrintTotalsAndSummary(ofstream& out, int pick[], int drop[], int
	psgr[], float dist[], float fare[], float toll[], float TF[]);
int main()
{
	int pick[MAX];
	int drop[MAX];
	int psgr[MAX];
	float dist[MAX];
	float fare[MAX];
	float toll[MAX];
	float TF[MAX];
	int record_counter(0);
	string nameFile;
	ifstream inFile;

	cout << "Please Enter the file name with the file extension :" << endl;
	cin >> nameFile;

	// Notice how this automatically opens the file
	ofstream outFile("Lab3_OutputTest.txt");
	inFile.open(nameFile);
	if (inFile.is_open())
	{
		record_counter = ReadData(inFile, pick, drop, psgr, dist,
			fare, toll);
		
		inFile.close();
		if (outFile.is_open())
		{
			WriteOutputFile(outFile, pick, drop, psgr,
				dist, fare, toll, record_counter);
			PrintTotalsAndSummary(outFile,
				pick, drop,
				psgr, dist, fare, toll,TF);
			outFile.close();
		}
		else
		{
			cout << "Trouble Opening File";
			cout << "\n\n\t\t ** About to EXIT NOW! ** ";
		}
	}
	else
	{
		cout << "Trouble Opening File";
		cout << "\n\n\t\t ** About to EXIT NOW! ** ";
	}
	return 0;
}
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
	while (!inFile.eof())
	{
		cout << setiosflags(ios::left) << setw(5)
			<< pick[counter] << resetiosflags(ios::left)
			<< setw(10) << drop[counter] <<
			resetiosflags(ios::left)
			<< setw(12) << psgr[counter] <<
			resetiosflags(ios::left)
			<< setw(14) <<
			dist[counter] << resetiosflags(ios::left)
			<< setw(14) << fare[counter] <<
			resetiosflags(ios::left)
			<< setw(14) << toll[counter]
			<< endl;
		counter++;
		inFile >> pick[counter] >> drop[counter] >> psgr[counter]
			>> dist[counter] >> fare[counter] >> toll[counter];
	}
	return counter;
}
void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int
	psgr[], float dist[], float fare[], float toll[],
	int counter)
{
	outFile << setiosflags(ios::left) << setw(5)
		<< "Trip#" << resetiosflags(ios::left)
		<< setw(10) << "Pass#" <<
		resetiosflags(ios::left)
		<< setw(12) << "Dist." <<
		resetiosflags(ios::left)
		<< setw(14) <<
		"Fare" << resetiosflags(ios::left)
		<< setw(14) << "Toll" <<
		resetiosflags(ios::left)
		<< setw(14) << "Total"
		<< setw(14) << "Cost/MI"
		<< endl;
	for (int r = 0; r <= counter - 1; r++)
	{
		outFile << setiosflags(ios::left) << setw(5)
			<< pick[r] << resetiosflags(ios::left)
			<< setw(10) << drop[r] <<
			resetiosflags(ios::left)
			<< setw(12) << psgr[r] <<
			resetiosflags(ios::left)
			<< setw(14) <<
			dist[r] << resetiosflags(ios::left)
			<< setw(14) << fare[r] <<
			resetiosflags(ios::left)
			<< setw(14) << toll[r]
			<< endl;
	}
}

void PrintTotalsAndSummary(ofstream& outFile, int pick[], int drop[], int
	psgr[], float dist[], float fare[], float toll[] , float TF[])
{
	
	// To screen
	cout << "Total People Transported: " << endl
		<< "Total Paid: " << TF[] << endl //TFare = fare + toll
		<< "Average Cost Per Person " << endl; //Cost Per Mile = Fare / Distance
	// To file
	outFile << "\n\n\t** Total People Transported: "  << endl
		<< "Total Paid: " << endl
		<< "Average Cost Per Person " << endl;
}