summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
blob: 2adcb040ef6bbffa3492f66a3143f143ee9d4b64 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//Lab 3



#include <iostream>
#include <fstream>	
#include <iomanip>	
using std::cin;
using std::cout;
using std::endl;
using std::setw;
using std::setprecision;
using std::fixed;
using std::ios;

using std::ifstream;
using std::ofstream;


const int MAX = 100;

int ReadData(ifstream& inFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[], float tfare[], float CPM[]);
void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[],
	int counter);
void PrintTotalsAndSummary(ofstream& outFile, int totalRecords);
void PassengerCount(int psgr[], int counter, int &pplt);
void TotalPaid(float tfare[], int counter, float &paid);
void AverageCostPerPerson(float paid, int pplt, float ACM);

int main()
{

	int pick[MAX];
	int drop[MAX];
	int psgr[MAX];
	float dist[MAX];
	float fare[MAX];
	float toll[MAX];
	int counter = 0;
	float tfare[MAX];
	float CPM[MAX];
	int pplt = 0;
	float paid = 0;
	float ACM = 0;
	int record_counter(0);

	ifstream inFile;

	ofstream outFile("C:\\TEMP\\lab3_report.txt");

	inFile.open("C:\\TEMP\\lab3_data.txt");

	if (inFile.is_open())
	{
		record_counter = ReadData(inFile, pick, drop, psgr, dist, fare, toll, tfare, CPM);
		inFile.close();

		if (outFile.is_open())
		{
			WriteOutputFile(outFile, pick, drop, psgr, dist, fare, toll, record_counter);
			PassengerCount(psgr, record_counter, pplt);
			TotalPaid(tfare, record_counter, paid);
			AverageCostPerPerson(paid, pplt, ACM);
			PrintTotalsAndSummary(outFile, record_counter);
			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[], float tfare[], float CPM[])
{
	int counter = 0;
	inFile >> pick[counter] >> drop[counter] >> psgr[counter] >> dist[counter] >> fare[counter] >> toll[counter];

	cout << setiosflags(ios::left)
		<< "Pickup location" << resetiosflags(ios::left)
		<< setw(24) << "Drop-off location" << resetiosflags(ios::left)
		<< setw(15) << "# of ppl" << resetiosflags(ios::left)
		<< setw(17) << "Distance" << resetiosflags(ios::left)
		<< setw(11) << "Fare" << resetiosflags(ios::left)
		<< setw(15) << "Toll" << resetiosflags(ios::left)
		<< setw(16) << "Total Fare" << resetiosflags(ios::left)
		<< setw(18) << "Cost Per Mile" << resetiosflags(ios::left)
		<< endl << endl;

	while (!inFile.eof())
	{
		tfare[counter] = fare[counter] + toll[counter];

		if (dist[counter] == 0)
			CPM[counter] = 0;

		else
		CPM[counter] = fare[counter] / dist[counter]; 
			

		cout << fixed << setprecision(2) << setiosflags(ios::left) << setw(10)
			<< pick[counter] << resetiosflags(ios::left)
			<< setw(20) << drop[counter] << resetiosflags(ios::left)
			<< setw(20) << psgr[counter] << resetiosflags(ios::left)
			<< setw(19) << dist[counter] << resetiosflags(ios::left)
			<< setw(14) << fare[counter] << resetiosflags(ios::left)
			<< setw(14) << toll[counter] << resetiosflags(ios::left)
			<< setw(14) << tfare[counter] << resetiosflags(ios::left)
			<< setw(14) << CPM[counter] << resetiosflags(ios::left)
			<< endl;
		counter++;
		inFile >> pick[counter] >> drop[counter] >> psgr[counter] >> dist[counter] >> fare[counter] >> toll[counter] >> tfare[counter];
	}

	return counter;
}

void WriteOutputFile(ofstream& outFile, int pick[], int drop[], int psgr[], float dist[], float fare[], float toll[],
	int counter)
{
	outFile << "   Here is the Output File" << endl;
	for (int i = 0; i < counter; i++)
	{
		outFile << setiosflags(ios::left) << setw(5)
			<< pick[i] << resetiosflags(ios::left)
			<< setw(10) << drop[i] << resetiosflags(ios::left)
			<< setw(12) << psgr[i] << resetiosflags(ios::left)
			<< setw(14) << dist[i] << resetiosflags(ios::left)
			<< setw(14) << fare[i] << resetiosflags(ios::left)
			<< setw(14) << toll[i]
			<< endl;
	}
}
void PassengerCount(int psgr[], int counter, int &pplt)
{

	for (int i = 0; i < counter; i++)
	{
		pplt = pplt + psgr[i];
		

	}

	cout << endl << "Total number of passengers transported: " << pplt << endl;
}

void TotalPaid(float tfare[], int counter, float &paid) 
{

	for (int i = 0; i < counter; i++)
	{
		paid = paid + tfare[i];
		

	}

	cout  << "Total fairs paid: $" << paid << endl;
}

void AverageCostPerPerson(float paid, int pplt, float ACM)
{

	ACM = paid / pplt;


	cout << "Average cost per person: $" << ACM << endl;

}

void PrintTotalsAndSummary(ofstream& outFile, int totalRecords)
{

	cout << "\n\n\t\t\t\t\t\t** Total Records: " << totalRecords << " **\n"
		<< "\t\t\t\t\t\t\t The End \n";

	
	outFile << "\n\n\t** Total Records: " << totalRecords << " **\n"
		<< "\t\t The End \n";
}