Понятно,
, файл отчистился. Тогда какой массив взять чтоб переписать. С главной функции нечего взять, я запутался уже.
Добавлено через 21 час 50 минут
Вопрос решён, всем спасибо.
C++ |
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
| #include <stdlib.h>
#include <fstream.h>
#include <conio.h>
#include <stdio.h>
#define N 103
struct info
{
int tab;
char fam[20];
float oklad;
info()
{
tab=0; oklad=0;
}
}; info T[N];
int hesh(int key){ return key % N;}
void forms(char fl[]);//formiruet hesh tabl T iz faila fl
void output();//vivod mas T na ekran
int search(int p);//funkc vozvrash index zapisi s tab nomerom=p ili -1
void add (info g);//dobavl zapic g v tabl T
void del (info g);//udalenie
void record();
void main()
{
int z,k,s;
info m,n;
clrscr();
forms("1.txt");
cout<<endl;
output();
cout<<"Vvedidet tab fam oklad novogo sotr:"<<endl;
cout<<"Tab nom:";
while (cin>>m.tab)
{
cout<<"Familiya:"; cin>>m.fam;
cout<<"Oklad:"; cin>>m.oklad;
int i=search(m.tab);
if (i!=-1)
{
cout<<"3anogo"<<endl;
T[i]=m;
}
else {add(m); break;}
}
output();
for (int i=0; i<3; i++)
{
cout<<"\n\nVvedite tab nom poiska:";
cin>>z;
k=search(z);
if (k==-1) cout<<"Ne naiden"; else
cout<<T[k].tab<<'\t'<<T[k].fam<<'\t'<<T[k].oklad<<'\n';
}
cout<<endl<<"Vvedidet tab nomer del:"<<endl;
cin>>n.tab;
del(n);
record();
output();
getch();
}
/////////////////////////////////////////////////////////////////////////////
void add (info g)
{
int j=0;
int i=hesh(g.tab);
while (T[i].tab!=0 && j<N)
{
i=hesh(i+1);
j++;
}
if (j==N){ cout<<"Tabl perepolnena";getch(); exit (0);}
else T[i]=g;
}
/////////////////////////////////////////////////////////////////////////////
void forms(char fl[])
{
ifstream F(fl);
info x;
while (F>>x.tab>>x.fam>>x.oklad)
add(x);
}
/////////////////////////////////////////////////////////////////////////////
void output()
{
cout<<"index tab fam oklad "<<endl;
for (int i=0; i<N; i++)
if (T[i].tab!=0)
cout<<i<<'\t'<<T[i].tab<<'\t'<<T[i].fam<<'\t'<<T[i].oklad<<'\n';
}
/////////////////////////////////////////////////////////////////////////////
int search (int p)
{
int j=0, i=hesh(p);
while (j++<N && T[i].tab)
{
if (T[i].tab==p)
return i;
i=hesh(i+1);
}
return -1;
}
/////////////////////////////////////////////////////////////////////////////
void del (info g)
{
int i=hesh(g.tab);
if (search) T[i].tab=NULL;
}
void record()
{
ofstream fl("1.txt");
for (int i=0; i<N; i++)
if (T[i].tab!=0)
fl<<T[i].tab<<"\t"<<T[i].fam<<"\t"<<T[i].oklad<<endl;
} |
|