-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTruck.h
More file actions
177 lines (140 loc) · 4.08 KB
/
Truck.h
File metadata and controls
177 lines (140 loc) · 4.08 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
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
#pragma once
#include"Header.h"
using namespace std;
class Truck
{
string TruckID;
string DriverName;
string line;
BinStack* myJobs;
public:
BinStack* Jobs_from_file;
Truck(const string& truckID, const string& driverName)
{
TruckID = truckID;
DriverName = driverName;
myJobs = new BinStack();
Jobs_from_file = new BinStack();
Read_jobs_from_file();
// menus
}
~Truck()
{
delete myJobs;
}
void Menu()
{
cout << "\033[1;36m";
cout << "1. View current Jobs" << endl;
cout << "\033[0m";
cout << "************" << endl;
}
void Write_job_in_file(Bin* currentJob)
{
// Open the file in append mode
ofstream outFile("jobsfordriver.txt", ios::app);
if (outFile.is_open())
{
// Write the job information to the file
outFile << currentJob->BinLocation << ";" << currentJob->filledPercent << "%" << endl;
// cout << "Job information written to 'jobs.txt' successfully." << endl;
// Close the file
outFile.close();
}
else
{
cerr << "Error opening 'jobs.txt' for writing." << endl;
}
}
void getBins(Bin* arr, int size)
{
myJobs->empty();
for (int i = 0; i < size; ++i)
{
Write_job_in_file(&arr[i]);
CheckNotification(&arr[i]);
myJobs->Push_job(&arr[i]);
}
}
void AddnewJob(Bin job)
{
myJobs->Push_job(&job);
}
void Read_jobs_from_file()
{
std::ifstream inFile("jobsfordriver.txt");
if (inFile.is_open())
{
std::string line;
int i = 0;
while (std::getline(inFile, line))
{
if (i == 0)
{
}
else
{
std::istringstream iss(line);
std::string location;
int filledPercent;
// Read location and filled percentage from the line
if (std::getline(iss, location, ';') && (iss >> filledPercent))
{
Bin* newJob = new Bin(location, filledPercent);
Jobs_from_file->Push_job(newJob);
}
}
i++;
}
// std::cout << "Jobs read from 'jobs.txt' successfully." << std::endl;
inFile.close(); // Close the file
}
else
{
std::cerr << "Error opening 'jobs.txt' for reading." << std::endl;
}
}
void ReadNotification(std::string& notificationString)
{
std::ifstream inFile("Notification.txt");
if (inFile.is_open())
{
std::stringstream buffer;
buffer << inFile.rdbuf(); // Read the entire content of the file into the stringstream
notificationString = buffer.str();
inFile.close(); // Close the file
}
else
{
std::cerr << "Error opening 'Notification.txt' for reading." << std::endl;
}
}
void CheckNotification(Bin* currentJob)
{
ofstream outFile("Notification.txt", ios::app);
if (outFile.is_open())
{
// Write the job information to the file
outFile << currentJob->BinLocation << ";" << currentJob->filledPercent << "%";
// cout << "Job information written to 'Notification.txt' successfully." << endl;
// Close the file
outFile.close();
}
else
{
cerr << "Error opening 'Notification.txt' for writing." << endl;
}
}
void currentJobs()
{
cout << "\033[1;33m";
cout << "Truck " << TruckID << " with driver " << DriverName << " is on the way with the following jobs" << endl;
myJobs->Display();
cout << "\033[0m";
}
void Send_Truck_to_Bins()
{
myJobs->Pop_job();
myJobs->Display();
}
};