summaryrefslogtreecommitdiff
path: root/BlankConsoleLab/BlankConsoleLab.cpp
blob: 86a8534f237fb11e0c0650e220c3237f6ca9f7eb (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
//Lab 3
//Trevor Bouchillon

#include <iostream>
#include <fstream> // For the files!!!!
#include <iomanip> // For manipulators & formatting options
using std::cin;
using std::cout;
using std::endl;
using std::setw;
using std::ios;
using std::ifstream;
using std::ofstream;
using std::left;
using std::setprecision;
const int MAX = 100;

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, float TotalFare[], float CostPerMile[]);
void PrintTotalsAndSummary(ofstream& out, int totalRecords);

int main()
{
	int pick[MAX];
	int drop[MAX];
	int psgr[MAX];
	float dist[MAX];
	float fare[MAX];
	float toll[MAX];
	float TotalFare[MAX];
	float CostPerMile[MAX];
	int record_counter(0);
	ifstream inFile;
	// Notice how this automatically opens the file
	ofstream outFile("C:\\TEMP\\largeout.txt");
	inFile.open("C:\\TEMP\\large.txt");

	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, TotalFare, CostPerMile);
			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[])
{
	int counter = 0;
	inFile >> pick[counter] >> drop[counter] >> psgr[counter] >> dist[counter] >> fare[counter] >> toll[counter]; // Priming Read
	cout << setiosflags(ios::left) << left << setw(20) << "PickUpLoc" << setiosflags(ios::left) << setw(20) << left << "DropOffLoc" << setiosflags(ios::left) << left << setw(20) << "PassengerCount"
		<< setiosflags(ios::left) << left << setw(20) << "Distance" << setiosflags(ios::left) << left << setw(20) << "Fare" << setiosflags(ios::left) << left << setw(20) << "Toll"
		<< setiosflags(ios::left) << left << setw(20) << "TotalFare" << setiosflags(ios::left) << left << setw(20) << "CostPerMile" << endl;
	
	
	while (!inFile.eof())
	{
		float TotalFare[MAX];
		float CostPerMile[MAX];

		for (int r = 0; r <= counter ; r++) {
			TotalFare[r] = toll[r] + fare[r];
			CostPerMile[r] = fare[r] / dist[r];
			if (dist[r] == 0) {
				CostPerMile[r] = 0;
			}
		}
		cout << setiosflags(ios::left) << setw(20) << pick[counter] << resetiosflags(ios::left) << left << setw(20) << drop[counter] << resetiosflags(ios::left) << left << setw(20) << psgr[counter]
			<< resetiosflags(ios::left) << left << setw(20) << dist[counter] << resetiosflags(ios::left) << left << setw(20) << fare[counter] << resetiosflags(ios::left) << left << setw(20) << toll[counter]
			<< resetiosflags(ios::left) << left << setw(20) << TotalFare[counter] << resetiosflags(ios::left) << left << setw(20) << setprecision(3) << CostPerMile[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, float TotalFare[], float CostPerMile[])
{
	outFile << "   Here is the Output File" << endl;
	for (int r = 0; r <= counter - 1; r++)
	{
		TotalFare[r] = toll[r] + fare[r];
		CostPerMile[r] = fare[r] / dist[r];
		if (dist[r] == 0) {
			CostPerMile[r] = 0;
		}
		outFile << setiosflags(ios::left) << left << setw(10) << pick[r] << resetiosflags(ios::left) << left << setw(10) << drop[r] << resetiosflags(ios::left) << left << setw(10) << psgr[r] << resetiosflags(ios::left) << left
			<< setw(14) << dist[r] << resetiosflags(ios::left) << left << setw(10) << fare[r] << resetiosflags(ios::left) << left << setw(10) << toll[r] << resetiosflags(ios::left) << left << setw(14) << TotalFare[r]
			<< resetiosflags(ios::left) << left << setw(14) << setprecision(3) << CostPerMile[r] << endl;
	}
}

void PrintTotalsAndSummary(ofstream& outFile, int totalRecords)
{
	// To screen
	cout << "\n\n\t** Total Records: " << totalRecords << " **\n" << "\t\t The End \n";
	// To file
	outFile << "\n\n\t** Total Records: " << totalRecords << " **\n" << "\t\t The End \n";
}