Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
2#include <conio.h>
3#include <stdio.h>
4#include <iostream.h>
5#include <string.h>
6#include <math.h>
7#include <stdlib.h>
8#include <time.h>
9#include <dos.h>
10//*********************clasa abstracta
11class elem {
12public:
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28protected :
29
30
31};
32
33//******************************clasa derivata student
34class student
getch(); exit(1); }
35{
36 int cod;
37 char nume[20];
38 char prenume[20];
39 int an;
40 char raion[30];
41 char obiect[15];
42
43 public:
44
45
46
student()
{ cod=0; strcpy(nume,""); strcpy(prenume,""); an=0;
strcpy(raion,""); strcpy(obiect,"");
47
48
49
50
void setNume(char* n) {
51
52
53
54
55
56
57
58
59
60
61
62
63
64
strcpy(nume,n); }
65"<<obiect<<endl; }
66
67
68
return (this->cod>e2.cod);}
69
return (this->cod<e2.cod); }
70
71
return (this->cod<=e2.cod); }
72
73
return (this->cod>=e2.cod); }
74
75
return (this->cod==e2.cod); }
76
77
return (this->cod!=e2.cod); }
78
79};
tabel() {n=0;}
86
87
88
89
void sort();
90
91
92
93protected:
94
95
96
getch(); exit(1); }
97};
98
99template
100<class el>
101tabel<el>::tabel (char * file) {
102
FILE *pf;
103
pf=fopen(file,"rt"); n=0;
104
while(!feof(pf))
105
if (t[n].fscanf_el(pf)>0)
106
n++;
107
fclose(pf); }
108template
109<class el>
110void tabel<el>::search (int c) { int position=-1,a,j;
111
112
for(int i=0;(position==-1)&&(i<n);i++)
113
{ a=t[i].getCod(); delay(100);
114
if(c==a )
115
{ position=i; t[i].show(); } }
116
117
else{
118
119
120
121
122template
123<class el>
124void tabel<el>::show(const char *opening,const char *ending)
125
{ cout<<opening;
126
for(int i=0;i<n;i++){
127
128
getch();clrscr();}
129
cout<<ending;
130
cout<<"\n " ;} }
131
132template
133<class el>
134void tabel<el>::sort()
135{
136 int j,count=0;
137 el aux;
138 for(int i=0;i<n-1;i++)
139 for(j=i;j<n;j++)
140 {
141
if(t[i].getCod()>t[j].getCod())
142
143
aux=t[i];
144
t[i]=t[j];
145
t[j]=aux;
146
count++;
147
148 }
149 // cout<<"\n Sortarea a fost indeplinita cu succes!:"<<" "<<count<<"\n";
150 getch();
151}
152
153
154
155template
156<class el>
157void tabel<el>::searchbin(int c)
158{
159 if(!n)
160 {
161 cout<<"ERROR! Introduceti date.";
162 getch();
return; }
f=m-1;
171
s=m+1;}
172
m=(s+f)/2; }
173 if(s<=f)
174 {
175
t[m].show();
176
177
178 }
179 else
180 {
181
182 }
183
184}
185
186
187void main()
188{
189clrscr();
190time_t first, second;
191tabel <student> gr("d:\\caro\\f1-1.txt");
192char ch='n';
193int id,i;
194gr.show("\n Continutul fisierului \n"," ");
195while(ch!='y'){
196clrscr();
197cout<<"\n Introduceti codul pt cautare:\n ";
198cin>>id;
199first = time(NULL);
200delay(1000);
201gr.search(id);
202second = time(NULL);
203// printf("\nTimpul de executie este : %f secunde \n",difftime(second,first));
204gr.sort();