-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcsearchname.cpp
More file actions
59 lines (59 loc) · 1.46 KB
/
csearchname.cpp
File metadata and controls
59 lines (59 loc) · 1.46 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
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include "classes.h"
using namespace std;
void Courier::csearchname(string courierfile){
ifstream fin;
ofstream fout;
fin.open(courierfile);
int i=0;
int k=0;
cout <<"Enter the name you want to find"<<endl;
string s;
while (!fin.eof()){//считаем количество строк
getline(fin, s);
k++;
}
k--;
int sidc;
string sname;
string sphone;
int sorderid1;
int sorderid2;
int scar;
int sdeliverytime;
Courier *a = new Courier[k+1];//создаем массив
fin.close();
fin.open(courierfile);
for (i=0; i<k; i++){//заполняем массив из файла
fin >> sidc;
fin >> sname ;
fin >> sphone;
fin >> sorderid1;
fin >> sorderid2;
fin >> scar;
fin >> sdeliverytime;
a[i].setidc(sidc);
a[i].setname(sname);
a[i].setphone(sphone);
a[i].setorderid1(sorderid1);
a[i].setorderid2(sorderid2);
a[i].setcar(scar);
a[i].setdeliverytime(sdeliverytime);
}
int tmp=-1;
cin >>sname;//искомое имя
for (i=0; i<k; i++){
if (a[i].getname()== sname){//ищем совпадения, выводим
fout << a[i].getidc() <<" "<<a[i].getname()<<" "<<a[i].getphone()<<" "<<a[i].getorderid1()<<" "<<a[i].getorderid2()<<" "<<a[i].getcar()<<" "<<a[i].getdeliverytime()<<endl;
tmp=1;
}
}
if (tmp==-1){//если имени не нашлось
cout<<"There's no such name"<<endl;
}
fout.close();
delete[]a;//уборка
}