-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
140 lines (129 loc) · 2.69 KB
/
main.cpp
File metadata and controls
140 lines (129 loc) · 2.69 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
#include <iostream>
#include "Customer.h"
#include "Date.h"
#include "Inventory.h"
#include "Tablet.h"
#include <fstream>
using namespace std;
void makeReservation(Tablet *t);
void moveBroken(Tablet *t);
void fixBroken(string);
void clearData();
int main()
{
Inventory *in=new Inventory(16);
in->loadAllTabs();
in->tabs[0]->setBroken(true);
makeReservation(in->tabs[1]);
moveBroken(in->tabs[0]);
fixBroken(in->tabs[0]->GetID());
return 0;
}
void makeReservation(Tablet *t)
{
t->SetonReserve(true);
string id;
int x=0;
ifstream file("available.txt");
ofstream temp("temp.txt");
string tname=t->GetID();
while(file>>id)
{
if(tname!=id)
temp<<id<<endl;
if(tname==id)
x=1;
}
file.clear();
file.seekg(0, ios::beg);
file.close();
temp.close();
remove("available.txt");
rename("temp.txt", "available.txt");
if(x==0)
{
cout << "There is no table with that id." << endl;
}
else
{
fstream file2("loan.txt");
file2<<tname<<endl;
}
}
void moveBroken(Tablet *t)
{
if(t->getBroken())
{
fstream file("broken.txt");
file<<t->GetID()<<endl;
t->SetonLoan(false);
}
string id;
int x=0;
ifstream file("available.txt");
ofstream temp("temp.txt");
string tname=t->GetID();
while(file>>id)
{
if(tname!=id)
temp<<id<<endl;
if(tname==id)
x=1;
}
file.clear();
file.seekg(0, ios::beg);
file.close();
temp.close();
remove("available.txt");
rename("temp.txt", "available.txt");
if(x==0)
{
cout << "There is no table with that id." << endl;
}
else
{
fstream file2("broken.txt");
file2<<tname<<endl;
}
}
void fixBroken(string tname)
{
string id;
int x=0;
ifstream file("broken.txt");
ofstream temp("temp.txt");
while(file>>id)
{
if(tname!=id)
temp<<id<<endl;
if(tname==id)
x=1;
}
file.clear();
file.seekg(0, ios::beg);
file.close();
temp.close();
remove("student.txt");
rename("temp.txt", "students.txt");
if(x==0)
{
cout << "There is no table with that id." << endl;
}
else
{
fstream file2("available.txt");
file2<<tname<<endl;
}
}
void clearData()
{
fstream file;
file.open("broken.txt",std::ofstream::out|std::ofstream::trunc);
fstream file2;
file2.open("loan.txt",std::ofstream::out|std::ofstream::trunc);
fstream file3;
file3.open("available.txt",std::ofstream::out|std::ofstream::trunc);
file.close();
file2.close();
file3.close();
}