-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
100 lines (76 loc) · 2.52 KB
/
Source.cpp
File metadata and controls
100 lines (76 loc) · 2.52 KB
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
/***************************************************************************************************
CSC 326 Information Structures
Lab #2
The Parking Garage (Stack)
Student: Maria Romanova
***************************************************************************************************/
#include <iostream>
#include <fstream>
#include "Messages.h"
#include "Garage.h"
#include "Shell.h"
#include "Car.h"
using namespace std;
int main()
{
Shell<string> shell; // to format output
Garage<Car> g;
char status = ' '; // 'A' - arrival, 'D' - departure
string plateNumber; // any string with no restrictions
int lineCounter = 0; // counts lines in file
int errorCounter = 0; // counts invalid entries in file (which does not begin with A or D)
ifstream inFile;
shell.displayHeader();
// open file --------------------------
inFile.open(FILE_NAME);
if (!inFile)
{
shell.highlight(ERROR_OPEN_FILE, 12); // error message text in light_red
Sleep(5000); // delay output for 5 sec
return 1;
}
// check file for invalid entries --------------------------------------------
while (!inFile.eof())
{
inFile >> status >> plateNumber;
if (status != 'A' && status != 'D')
errorCounter++;
}
if (errorCounter > 0)
{
shell.highlight(INVALID_FILE, 12); // error message text in light_red
cout << "\n\tNumber of invalid entries = " << errorCounter << endl;
Sleep(5000); // delay output for 5 sec
return 1;
} // end check file for invalid entries ----------------------------------------
// return to the beginning of the file
inFile.clear();
inFile.seekg(0, ios::beg);
// Processing valid file -------------------------
while (!inFile.eof())
{
lineCounter++;
inFile >> status >> plateNumber;
Car car(plateNumber);
cout << "\n\t" << lineCounter << "\t";
if (status == 'A')
{
shell.highlight(ARRIVAL, 10); // message "Arrival" in light_green
cout << plateNumber << " ";
if (!g.arrival(car))
shell.highlight(FULL_GARAGE); // message "Garage is FULL" in light_gray
}
else //(status == 'D')
{
shell.highlight(DEPARTURE, 12); // message "Departure" in light_red
cout << plateNumber << " ";
if (!g.departure(car))
shell.highlight(CAR_NOT_FOUND, 14); // error message "NOT IN THE GARAGE" in light_yellow
}
}// end while
inFile.close();
// pause screen
cout << "\n\n\t";
system("pause");
return 0;
} // End main()