forked from lukovka08/Laba-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosearchid.cpp
More file actions
46 lines (45 loc) · 1.17 KB
/
osearchid.cpp
File metadata and controls
46 lines (45 loc) · 1.17 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
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include "classes.h"
using namespace std;
void osearchid(string orderfile){//поиск заказа по id
ifstream fin;
ofstream fout;
fin.open(orderfile);
int i=0;
int k=0;
cout <<"Enter the id you want to find"<<endl;
string s;
while (!fin.eof()){//количество строк
getline(fin, s);
k++;
}
k--;
Order *a = new Order[k+1];//массив из заказов
fin.close();
fin.open(orderfile);
for (i=0; i<k; i++){
fin >> a[i].ido;//заносим данные из файла в массив
fin >> a[i].price;
fin >> a[i].deadline;
fin >> a[i].dtime;
fin >> a[i].address;
fin >> a[i].courierid;
}
int tmp=-1;
int ido;
cin >>ido;//искомый id
for (i=0; i<k; i++){
if (a[i].ido== ido){//ищем id, выводим, если есть
cout << a[i].ido<<" " <<a[i].price <<" " << a[i].deadline <<" "<< a[i].dtime <<" " << a[i].address<<" " << a[i].courierid <<endl;
tmp=1;
}
}
if (tmp==-1){//если не было совпадений
cout<<"---------------There's no such id---------------"<<endl;
}
fout.close();
delete[]a;//уборка
}