-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlane.h
79 lines (72 loc) · 1.82 KB
/
Plane.h
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
/*
-Tui coppy struct va cac ham load file trong file AD.H qua day
-File nay co bo sung ham "int SerchPlane(DSMayBay &ds, char* planeid)"
*/
#pragma once
#include <iostream>
#include <iomanip>
#include <windows.h>
#include <fstream>
#define MAX 300
#define MaMayBay 15
#define LoaiMayBay 40
using namespace std;
struct MayBay {
char SoHieuMB[MaMayBay+1];
char LoaiMB[LoaiMayBay+1];
int SoDay;
int SoDong;
};
struct DSMayBay{
MayBay* n [MAX];
int SoMayBay=0;
};
int SerchPlane(DSMayBay &ds, char* planeid){
int index = -1;
for(int i = 0; i < ds.SoMayBay; i++){
if(strcmp(ds.n[i]->SoHieuMB, planeid) == 0){
index = i;
break;
}
}
return index;
}
int readfile(DSMayBay &c) {
ifstream f("Data\\Planes.txt");
if (!f.is_open()) {
cout << "Khong the mo file" << endl;
return 0;
}
string line;
while (getline(f, line)) {
MayBay *newMayBay = new MayBay;
sscanf(line.c_str(), "%[^|]|%[^|]|%d|%d", newMayBay->SoHieuMB, newMayBay->LoaiMB, &newMayBay->SoDong, &newMayBay->SoDay);
for(int i=0;i<c.SoMayBay;i++){
if(strcmp(newMayBay->SoHieuMB,c.n[i]->SoHieuMB)==0){
cout<<"Load file may bay khong thanh cong!"<<endl;
return 0;
}
}
c.n[c.SoMayBay++] = newMayBay;
}
f.close();
}
void savedata(DSMayBay &c) {
ofstream f("Data\\Planes.txt");
if (!f.is_open()) {
cout << "Khong the mo file" << endl;
return;
}
for(int i = 0; i < c.SoMayBay; i++) {
f << c.n[i]->SoHieuMB << "|" << c.n[i]->LoaiMB << "|" << c.n[i]->SoDong << "|" << c.n[i]->SoDay << "\n";
}
f.close();
}
void freeing_plane(DSMayBay &c){
for(int i=0;i<c.SoMayBay;i++){
delete c.n[i];
c.n[i]==nullptr;
}
c.SoMayBay=0;
cout<<"Giai phong bo nho may bay hoan tat!"<<endl;
}