Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Блоги Сообщество Поиск Заказать работу  
 
0 / 0 / 0
Регистрация: 10.05.2020
Сообщений: 8

Не получается скомпилировать код в code block

19.04.2021, 17:12. Показов 450. Ответов 3

Студворк — интернет-сервис помощи студентам
Исправил вроде все ошибки компилятора, не понимаю почему не работает. Помогите понять и исправить, чтобы сработало.
Это задача на методы поиска в таблице из файла.
Этот код взят с borland.



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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#include <conio.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>
#include <stdlib.h>
 
 
using namespace std;
 
class elem {
public:
        virtual int fscanf_el (FILE * f)=0;
        virtual int show(const char * opening,const char * ending)=0;
        virtual int free ()=0;
        int operator > (elem &) {
        error("Error should overcode operator \">\"!\n"); return 0; }
        int operator < (elem &) {
        error("Error should overcode operator \"<\"!\n"); return 0; }
        int operator >= (elem &) {
        error("Error should overcode operator \">=\"!\n"); return 0; }
        int operator <= (elem &) {
        error("Error should overcode operator \"<=\"!\n"); return 0; }
        int operator == (elem &) {
        error("Error should overcode operator \"==\"!\n"); return 0; }
        int operator != (elem &) {
        error("Error should overcode operator \"!=\"!\n"); return 0; }
protected :
        void error (char * message){
        cout<<message; cout<<"Apasa orice tasta pentru a finisa...\n";    getch(); exit(1); }
};
 
class LIBRARIE
{
public:
 int cod;
 char autor[20];
 char denumire[20];
 char editura[20];
 int an;
 int st;
 int dr;
 
    LIBRARIE()
        {  cod=0;  strcpy(autor,"");   strcpy(denumire,"");
           strcpy(editura,"");  an=0;  st=-1;   dr=-1;     }
         void setcod(int i) {  cod=i;}
         void setautor(char* n)  {    strcpy(autor,n); }
         void setdenumire(char* a) {   strcpy(denumire,a);}
         void setan(int i) {an=i; }
         void seteditura(char* d)  {   strcpy(editura,d);  }
         int getcod() {  return cod; }
         int set_st(int new_st)
            {
            st=new_st;
            return st;
            }
         int get_st()
            {
            return st;
            }
         int set_dr(int new_dr)
            {
            dr=new_dr;
            return dr;
            }
         int get_dr()
            {
            return dr;
            }
         char* getautor() {   return autor;  }
         char* getdenumire()  {  return denumire;}
         int getan(){ return an; }
         char* geteditura()  {  return editura;  }
         int fscanf_el (FILE * f)
             {return fscanf(f,"%i %s %s %s %i",&cod,autor,denumire,editura,&an);}
    void virtual show( ) {
              cout<<cod<<"  "<<autor<<"  "<<denumire<<"  "<<editura<<"  "<<an<<endl; }
    virtual int free() { return cod==0; }
    int operator >(LIBRARIE &e2) {
            return (this->cod>e2.cod);}
    int operator < (LIBRARIE &e2) {
            return (this->cod<e2.cod); }
    int operator <= (LIBRARIE &e2) {
            return (this->cod<=e2.cod); }
    int operator >= (LIBRARIE &e2){
            return (this->cod>=e2.cod); }
    int operator == (LIBRARIE &e2) {
            return (this->cod==e2.cod); }
    int operator != (LIBRARIE &e2) {
            return (this->cod!=e2.cod); }
};
 
template <class el> class tabel
{
protected:
    int n;
    el t[200];
public:
     tabel() {n=0;}
     tabel (char * file);
     void search (int c) ;
     void searchbin (int c);
     int  fib_search(el initial);
     int searchtree(LIBRARIE tmp);
     void createtree();
     void killtree();
     void sort();
 
     void show(const char *opening,const char *ending);
 
protected:
     void error(char *message){
     cout<<message; cout<<"Apasa orice tasta pentru a finisa...\n";
     getch(); exit(1); }
};
 
template
<class el>
      tabel<el>::tabel (char * file) {
      FILE *pf;
      pf=fopen(file,"rt");   n=0;
      while(!feof(pf))
      if (t[n].fscanf_el(pf)>0)
      n++;
      fclose(pf);
      }
 
template
<class el>
    void tabel<el>::search (int c) { int position=-1,a,j;
 
     for(int i=0;(position==-1)&&(i<n);i++)
     { a=t[i].getcod();
     if(c==a )
     {  position=i; t[i].show(); } }
     if(position==-1 ) cout<<"\nNu exista";
     else{
     cout<<"\nLungimea practica de cautare este:"<<position;
     cout<<"\nLungimea teoretica de cautare este:"<<n/2;  }
     }
 
 
template
<class el>
    int tabel<el>::fib_search(el initial)
    {
    int position=-1, contor=0, i=0, q=0, p=0;
    double durata;
    int fib[]={0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765};
     for(int j=0;;j++)
     {
        if(i>n)
        {
        i=fib[j-2];
        p=fib[j-3];
        q=fib[j-4];
        break;
        }
         else i=fib[j];
     }
        while(2<3)
        {
            contor++;
            if(initial==t[i]) {position=i; break;}
            if(initial<t[i])
            {
            if(q==0)  break;
            else {int v=p;i=i-q;p=q;q=v-q;}
            }
            if(initial>t[i])
            {
            if(p==1) break;
            else{ i=i+q; p=p-q; q=q-p;}
            }
        }
        if(position==-1){cout<<endl<<cout<<"Error!Error!"<<endl;}
        else
        {
        cout<<endl;
        t[position].show();
        cout<<endl<<"Lungimea practica de cautare este:"<<" "<<contor<<endl;
        float caut;
        caut=log(n)/log(2);
        cout<<"Lungimea teoretica de cautare este:"<<" "<<caut<<endl;
        }
        return position;
    }
 
template
<class el>
         void tabel<el>::show(const char *opening,const char *ending)
         { cout<<opening;
          for(int i=0;i<n;i++){
          t[i].show();if(i%20==0&&i!=0){ cout<<endl<<"Apasa pentru a vedea";
          getch();clrscr();}
          cout<<ending;
          cout<<"\n " ;} }
 
template
<class el>
void tabel<el>::sort()
{
 int j,count=0;
 el aux;
 for(int i=0;i<n-1;i++)
  for(j=i;j<n;j++)
  {
    if(t[i].getcod()>t[j].getcod())
    {
     aux=t[i];
     t[i]=t[j];
     t[j]=aux;
     count++;
    }
  }
  cout<<"Sortarea s-a terminat!"<<endl;
  getch();
}
 
template
<class el>
void tabel<el>::searchbin(int c)
{
 if(!n)
 {
  cout<<"ERROR! Introduceti datele";
  getch();    return; }
  int s=0,f=n-1,count=1,j;
 int m=(s+f)/2;
 
 while((c!=t[m].getcod())&&(s<=f))
 {  count++;
  if(t[m].getcod()>c)
    {     f=m-1;    }
  else
    {     s=m+1;}
    m=(s+f)/2;  }
 if(s<=f)
  {
    t[m].show();
    cout<<"\nLungimea practica de cautare este:"<<" "<<count;
    cout<<"\nLungimea teoretica de cautare este:"<<" "<<log(n)/log(2);
  }
 else
  {
     cout<<"\n Nu exista asa date!";
  }
}
 
template
<class el>
void tabel<el>::createtree()
{
    for(int i=1;i<n;i++)
    {
    int forw=1,j=0;
    while(forw)
    {
        if(t[i]<t[j])
        {
        if(t[j].get_st()==-1)
        {
            t[j].set_st(i);
            forw=0;
        }
        else
        j=t[j].get_st();
        }
        else
        if(t[i]>t[j])
        {
        if(t[j].get_dr()==-1)
        {
            t[j].set_dr(i);
            forw=0;
        }
        j=t[j].get_dr();
        }
    }
    }
}
 
template
<class el>
void tabel<el>::killtree()
{
    for(int i=0;i<n;i++)
    {
    t[i].set_st(-1);
    t[i].set_dr(-1);
    }
}
 
template
<class el>
int tabel<el>::searchtree(LIBRARIE tmp)
{
    int i=0,count=0,forw=1;
    while(forw)
    {
    if(tmp==t[i])
    {
        t[i].show();
        cout<<t[i].st<<" "<<t[i].dr<<endl;
        cout<<"Lungimea practica de cautare este:"<<count<<endl;
        cout<<"Lungimea teoretica maxima de cautare este:"<<n/2<<endl;
        cout<<"Lungimea teoretica minima de cautare este:"<<log(n)/log(2.0)*2.0;
        forw=0;
    }
    else
    {
        if(tmp<t[i])
        i=t[i].get_st();
        else
        i=t[i].get_dr();
        if(i==-1)
        {
        forw=0;
        cout<<"Elementul nu este gasit"<<endl;
        }
    }
    count++;
    }
return 0;
}
 
 
 
void main()
{
clrscr();
LIBRARIE pl,tmp;
tabel <LIBRARIE> gr("LIBRARIE.txt");
char ch, c;
int coden;
 
 
do{
 clrscr();
 cout<<"Menu:"<<endl;
 cout<<"*****************************************"<<endl;
 cout<<"0)Afisare tabel"<<endl;
 cout<<"1)Metoda secventila"<<endl;
 cout<<"2)Metoda arborescenta"<<endl;
 cout<<"3)Sortarea"<<endl;
 cout<<"4)Metoda binara"<<endl;
 cout<<"5)Metoda Fibonacci"<<endl;
 cout<<"6)Exit"<<endl;
 c=getch();
 switch(c)
 {
        case '0':
            ch='n';
            while(ch!='y')
            {
                clrscr();
                gr.show("Continutul fisierului:\n"," ");
                cout<<endl<<"Iesiti?(Y/N)";
                ch=getch();
            }
            break;
        case '1':
            ch='n';
            while(ch!='y')
            {
                clrscr();
                cout<<"Introduceti codul pentru cautare"<<endl;
                cin>>coden;
                gr.search(coden);
                cout<<endl;
                cout<<endl<<"Iesiti?(Y/N)";
                ch=getch();
            }
            break;
        case '2':
            ch='n';
            while(ch!='y')
            {
                clrscr();
                cout<<"Introduceti codul pentru cautare"<<endl;
                cin>>coden; cout<<endl;
                tmp.setcod(coden);
                gr.createtree();
                cout<<endl;
                gr.searchtree(tmp); cout<<endl;
                cout<<endl<<"Iesiti?(Y/N)";
                gr.killtree();
                ch=getch();
            }
            break;
        case '3':
                clrscr();
                gr.sort();
                getch();
            break;
        case '4':
            ch='n';
            while(ch!='y')
            {
                clrscr();
                cout<<"Introduceti codul pentru cautare"<<endl;
                cin>>coden;
                cout<<endl;
                gr.searchbin(coden); cout<<endl;
                cout<<endl<<"Iesiti?(Y/N)";
                ch=getch();
            }
            break;
        case '5':
            ch='n';
            while(ch!='y')
            {
                clrscr();
                cout<<"Introduceti codul pentru cautare"<<endl;
                cin>>pl.cod;
                cout<<endl;
                if(gr.fib_search(pl)==-1) cout<<endl<<"Eroare! Sortati!"<<endl;
                cin.ignore();
                cout<<endl;
                cout<<endl<<"Iesiti?(Y/N)";
                ch=getch();
            }
            break;
 } }
 while(c!='6');
}
0
cpp_developer
Эксперт
20123 / 5690 / 1417
Регистрация: 09.04.2010
Сообщений: 22,546
Блог
19.04.2021, 17:12
Ответы с готовыми решениями:

Не получается скомпилировать и запустить прогу в Code Blocks
В среде CodeBlocks 13.12 создаю проект (Console Application), пишу там свой код: #include &lt;stdio.h&gt; #include &lt;math.h&gt; int...

Code block и Build Как с компилировать код?
Здравствуйте ,дорогие форумчане! Помогите решить проблему с компиляцией в Code Blocks. Пытался сам решить проблему, гуглил, не понятно...

Как скомпилировать код в VS code
Доброго времени суток. Скачал VS code и установил туда c#. Как скомплировать код в VS code через их терминал? Открыл уже ранее готовый...

3
Модератор
Эксперт С++
 Аватар для zss
13769 / 10962 / 6491
Регистрация: 18.12.2011
Сообщений: 29,238
19.04.2021, 18:38
Исправил ошибки компиляции.
настоятельно рекомендую ПРАВИЛЬНО ФОРМАТИРОВАТЬ КОД
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
//#include <string.h>
#include <cmath>
#include <cstdlib>
 
#include <conio.h>
void clrscr()
{
    system("cls");
}
 
using namespace std;
 
class elem {
public:
    virtual int fscanf_el (FILE * f)=0;
    virtual int show(const char * opening,const char * ending)=0;
    virtual int free ()=0;
    int operator > (elem &) {
        error("Error should overcode operator \">\"!\n"); return 0; }
    int operator < (elem &) {
        error("Error should overcode operator \"<\"!\n"); return 0; }
    int operator >= (elem &) {
        error("Error should overcode operator \">=\"!\n"); return 0; }
    int operator <= (elem &) {
        error("Error should overcode operator \"<=\"!\n"); return 0; }
    int operator == (elem &) {
        error("Error should overcode operator \"==\"!\n"); return 0; }
    int operator != (elem &) {
        error("Error should overcode operator \"!=\"!\n"); return 0; }
protected :
    void error (char * message){
        cout<<message; 
        cout<<"Apasa orice tasta pentru a finisa...\n";    
        _getch(); 
        exit(1); 
    }
};
 
class LIBRARIE
{
public:
    int cod;
    char autor[20];
    char denumire[20];
    char editura[20];
    int an;
    int st;
    int dr;
 
    LIBRARIE()
    {  
        cod=0;  
        strcpy(autor,"");   
        strcpy(denumire,"");
        strcpy(editura,"");  
        an=0;  st=-1;   dr=-1;     
    }
    void setcod(int i) {  cod=i;}
    void setautor(char* n)  {    strcpy(autor,n); }
    void setdenumire(char* a) {   strcpy(denumire,a);}
    void setan(int i) {an=i; }
    void seteditura(char* d)  {   strcpy(editura,d);  }
    int getcod() {  return cod; }
    int set_st(int new_st)
    {
        st=new_st;
        return st;
    }
    int get_st()
    {
        return st;
    }
    int set_dr(int new_dr)
    {
        dr=new_dr;
        return dr;
    }
    int get_dr()
    {
        return dr;
    }
    char* getautor() {   return autor;  }
    char* getdenumire()  {  return denumire;}
    int getan(){ return an; }
    char* geteditura()  {  return editura;  }
    int fscanf_el (FILE * f)
    {
        return fscanf(f,"%i %s %s %s %i",&cod,autor,denumire,editura,&an);
    }
    void virtual show( ) {
        cout<<cod<<"  "<<autor<<"  "<<denumire<<"  "<<editura<<"  "<<an<<endl; 
    }
    virtual int free() { return cod==0; }
    int operator >(LIBRARIE &e2) {
        return (this->cod>e2.cod);}
    int operator < (LIBRARIE &e2) {
        return (this->cod<e2.cod); }
    int operator <= (LIBRARIE &e2) {
        return (this->cod<=e2.cod); }
    int operator >= (LIBRARIE &e2){
        return (this->cod>=e2.cod); }
    int operator == (LIBRARIE &e2) {
        return (this->cod==e2.cod); }
    int operator != (LIBRARIE &e2) {
        return (this->cod!=e2.cod); }
};
 
template <class el> class tabel
{
protected:
    int n;
    el t[200];
public:
    tabel() {n=0;}
    tabel (char * file);
    void search (int c) ;
    void searchbin (int c);
    int  fib_search(el initial);
    int searchtree(LIBRARIE tmp);
    void createtree();
    void killtree();
    void sort();
 
    void show(const char *opening,const char *ending);
 
protected:
    void error(char *message){
        cout<<message; cout<<"Apasa orice tasta pentru a finisa...\n";
        getch(); exit(1); 
    }
};
 
template
<class el>
tabel<el>::tabel (char * file) {
    FILE *pf;
    pf=fopen(file,"rt");   n=0;
    while(!feof(pf))
        if (t[n].fscanf_el(pf)>0)
            n++;
    fclose(pf);
}
 
template
<class el>
void tabel<el>::search (int c) { 
    int position=-1,a;
 
    for(int i=0;(position==-1)&&(i<n);i++)
    { 
        a=t[i].getcod();
        if(c==a )
        {  
            position=i; t[i].show(); 
        } 
    }
    if(position==-1 ) cout<<"\nNu exista";
    else{
        cout<<"\nLungimea practica de cautare este:"<<position;
        cout<<"\nLungimea teoretica de cautare este:"<<n/2;  
    }
}
 
 
template
<class el>
int tabel<el>::fib_search(el initial)
{
    int position=-1, contor=0, i=0, q=0, p=0;
    //double durata;
    int fib[]={0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765};
    for(int j=0;;j++)
    {
        if(i>n)
        {
            i=fib[j-2];
            p=fib[j-3];
            q=fib[j-4];
            break;
        }
        else i=fib[j];
    }
    while(true)
    {
        contor++;
        if(initial==t[i]) {position=i; break;}
        if(initial<t[i])
        {
            if(q==0)  
                break;
            else {int v=p;i=i-q;p=q;q=v-q;}
        }
        if(initial>t[i])
        {
            if(p==1) break;
            else{ i=i+q; p=p-q; q=q-p;}
        }
    }
    if(position==-1){cout<<endl<<cout<<"Error!Error!"<<endl;}
    else
    {
        cout<<endl;
        t[position].show();
        cout<<endl<<"Lungimea practica de cautare este:"<<" "<<contor<<endl;
        double caut;
        caut=log((double)n)/log(2.);
        cout<<"Lungimea teoretica de cautare este:"<<" "<<caut<<endl;
    }
    return position;
}
 
template
<class el>
void tabel<el>::show(const char *opening,const char *ending)
{ 
    cout<<opening;
    for(int i=0;i<n;i++){
        t[i].show();
        if(i%20==0&&i!=0){ 
            cout<<endl<<"Apasa pentru a vedea";
            _getch();
            clrscr();
        }
        cout<<ending;
        cout<<"\n " ;
    } 
}
 
template
<class el>
void tabel<el>::sort()
{
    int j,count=0;
    el aux;
    for(int i=0;i<n-1;i++)
        for(j=i;j<n;j++)
        {
            if(t[i].getcod()>t[j].getcod())
            {
                aux=t[i];
                t[i]=t[j];
                t[j]=aux;
                count++;
            }
        }
        cout<<"Sortarea s-a terminat!"<<endl;
        _getch();
}
 
template
<class el>
void tabel<el>::searchbin(int c)
{
    if(!n)
    {
        cout<<"ERROR! Introduceti datele";
        _getch();    
        return; 
    }
    int s=0,f=n-1,count=1;
    int m=(s+f)/2;
 
    while((c!=t[m].getcod())&&(s<=f))
    {  
        count++;
        if(t[m].getcod()>c)
        {     f=m-1;    }
        else
        {     s=m+1;}
        m=(s+f)/2;  
    }
    if(s<=f)
    {
        t[m].show();
        cout<<"\nLungimea practica de cautare este:"<<" "<<count;
        cout<<"\nLungimea teoretica de cautare este:"<<" "<<log((double)n)/log(2.);
    }
    else
    {
        cout<<"\n Nu exista asa date!";
    }
}
 
template
<class el>
void tabel<el>::createtree()
{
    for(int i=1;i<n;i++)
    {
        int forw=1,j=0;
        while(forw)
        {
            if(t[i]<t[j])
            {
                if(t[j].get_st()==-1)
                {
                    t[j].set_st(i);
                    forw=0;
                }
                else
                    j=t[j].get_st();
            }
            else
                if(t[i]>t[j])
                {
                    if(t[j].get_dr()==-1)
                    {
                        t[j].set_dr(i);
                        forw=0;
                    }
                    j=t[j].get_dr();
                }
        }
    }
}
 
template
<class el>
void tabel<el>::killtree()
{
    for(int i=0;i<n;i++)
    {
        t[i].set_st(-1);
        t[i].set_dr(-1);
    }
}
 
template
<class el>
int tabel<el>::searchtree(LIBRARIE tmp)
{
    int i=0,count=0,forw=1;
    while(forw)
    {
        if(tmp==t[i])
        {
            t[i].show();
            cout<<t[i].st<<" "<<t[i].dr<<endl;
            cout<<"Lungimea practica de cautare este:"<<count<<endl;
            cout<<"Lungimea teoretica maxima de cautare este:"<<n/2<<endl;
            cout<<"Lungimea teoretica minima de cautare este:"<<log((double)n)/log(2.0)*2.0;
            forw=0;
        }
        else
        {
            if(tmp<t[i])
                i=t[i].get_st();
            else
                i=t[i].get_dr();
            if(i==-1)
            {
                forw=0;
                cout<<"Elementul nu este gasit"<<endl;
            }
        }
        count++;
    }
    return 0;
}
 
 
 
int main()
{
    clrscr();
    LIBRARIE pl,tmp;
    tabel <LIBRARIE> gr("LIBRARIE.txt");
    char ch, c;
    int coden;
    do{
        clrscr();
        cout<<"Menu:"<<endl;
        cout<<"*****************************************"<<endl;
        cout<<"0)Afisare tabel"<<endl;
        cout<<"1)Metoda secventila"<<endl;
        cout<<"2)Metoda arborescenta"<<endl;
        cout<<"3)Sortarea"<<endl;
        cout<<"4)Metoda binara"<<endl;
        cout<<"5)Metoda Fibonacci"<<endl;
        cout<<"6)Exit"<<endl;
        c=_getch();
        switch(c)
        {
        case '0':
            ch='n';
            while(ch!='y')
            {
                clrscr();
                gr.show("Continutul fisierului:\n"," ");
                cout<<endl<<"Iesiti?(Y/N)";
                ch=_getch();
            }
            break;
        case '1':
            ch='n';
            while(ch!='y')
            {
                clrscr();
                cout<<"Introduceti codul pentru cautare"<<endl;
                cin>>coden;
                gr.search(coden);
                cout<<endl;
                cout<<endl<<"Iesiti?(Y/N)";
                ch=_getch();
            }
            break;
        case '2':
            ch='n';
            while(ch!='y')
            {
                clrscr();
                cout<<"Introduceti codul pentru cautare"<<endl;
                cin>>coden; cout<<endl;
                tmp.setcod(coden);
                gr.createtree();
                cout<<endl;
                gr.searchtree(tmp); cout<<endl;
                cout<<endl<<"Iesiti?(Y/N)";
                gr.killtree();
                ch=_getch();
            }
            break;
        case '3':
            clrscr();
            gr.sort();
            _getch();
            break;
        case '4':
            ch='n';
            while(ch!='y')
            {
                clrscr();
                cout<<"Introduceti codul pentru cautare"<<endl;
                cin>>coden;
                cout<<endl;
                gr.searchbin(coden); cout<<endl;
                cout<<endl<<"Iesiti?(Y/N)";
                ch=_getch();
            }
            break;
        case '5':
            ch='n';
            while(ch!='y')
            {
                clrscr();
                cout<<"Introduceti codul pentru cautare"<<endl;
                cin>>pl.cod;
                cout<<endl;
                if(gr.fib_search(pl)==-1) cout<<endl<<"Eroare! Sortati!"<<endl;
                cin.ignore();
                cout<<endl;
                cout<<endl<<"Iesiti?(Y/N)";
                ch=_getch();
            }
            break;
        } 
    }while(c!='6');
    return 0;
}
0
0 / 0 / 0
Регистрация: 10.05.2020
Сообщений: 8
19.04.2021, 21:31  [ТС]
Спасибо за ваш ответ. Но выдает уже эти ошибки.
Миниатюры
Не получается скомпилировать код в code block  
0
0 / 0 / 0
Регистрация: 10.05.2020
Сообщений: 8
19.04.2021, 21:58  [ТС]
Нашел проблему.
Нужно было ставить
#include <stdio.h>
#include <string.h>

Спасибо большое ! Вы меня спасли)
0
Надоела реклама? Зарегистрируйтесь и она исчезнет полностью.
raxper
Эксперт
30234 / 6612 / 1498
Регистрация: 28.12.2010
Сообщений: 21,154
Блог
19.04.2021, 21:58
Помогаю со студенческими работами здесь

Не получается скомпилировать код
Добрый день, Достаточно не давно, я решил заняться изучением ассемблера, после всяких его изучения в интернете. Решил попробовать,...

Что то не получается скомпилировать код
Пожалуйста проверьте и помогите исправить ошибки package zavd; import java.util.Scanner; public class den4zavd2 { public...

Не получается скомпилировать код на Delphi XE
Здравствуйте. У меня есть пример кода (анимация воды на Image c форматом JPG и TGA). Вот только не могу никак его скомпилировать на...

code::block 10-05
Доброго всем времени суток.Помогите разобраться.code::block 10-05 перестал компеллировать проекты.Компеллирует заголовочные функции и...

Problems with Code Block 12.11
У меня постоянно выскакивает сообщение в Code Block когда я пытаюсь скомпилировать любую программу: mingw32-gcc.exe -c...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
4
Ответ Создать тему
Новые блоги и статьи
Thinkpad X220 Tablet — это лучший бюджетный ноутбук для учёбы, точка.
Programma_Boinc 23.12.2025
Thinkpad X220 Tablet — это лучший бюджетный ноутбук для учёбы, точка. Рецензия / Мнение Это мой обзор планшета X220 с точки зрения школьника. Недавно я решила попытаться уменьшить свой. . .
PhpStorm 2025.3: WSL Terminal всегда стартует в ~
and_y87 14.12.2025
PhpStorm 2025. 3: WSL Terminal всегда стартует в ~ (home), игнорируя директорию проекта Симптом: После обновления до PhpStorm 2025. 3 встроенный терминал WSL открывается в домашней директории. . .
Как объединить две одинаковые БД Access с разными данными
VikBal 11.12.2025
Помогите пожалуйста !! Как объединить 2 одинаковые БД Access с разными данными.
Новый ноутбук
volvo 07.12.2025
Всем привет. По скидке в "черную пятницу" взял себе новый ноутбук Lenovo ThinkBook 16 G7 на Амазоне: Ryzen 5 7533HS 64 Gb DDR5 1Tb NVMe 16" Full HD Display Win11 Pro
Музыка, написанная Искусственным Интеллектом
volvo 04.12.2025
Всем привет. Некоторое время назад меня заинтересовало, что уже умеет ИИ в плане написания музыки для песен, и, собственно, исполнения этих самых песен. Стихов у нас много, уже вышли 4 книги, еще 3. . .
От async/await к виртуальным потокам в Python
IndentationError 23.11.2025
Армин Ронахер поставил под сомнение async/ await. Создатель Flask заявляет: цветные функции - провал, виртуальные потоки - решение. Не threading-динозавры, а новое поколение лёгких потоков. Откат?. . .
Поиск "дружественных имён" СОМ портов
Argus19 22.11.2025
Поиск "дружественных имён" СОМ портов На странице: https:/ / norseev. ru/ 2018/ 01/ 04/ comportlist_windows/ нашёл схожую тему. Там приведён код на С++, который показывает только имена СОМ портов, типа,. . .
Сколько Государство потратило денег на меня, обеспечивая инсулином.
Programma_Boinc 20.11.2025
Сколько Государство потратило денег на меня, обеспечивая инсулином. Вот решила сделать интересный приблизительный подсчет, сколько государство потратило на меня денег на покупку инсулинов. . . .
Ломающие изменения в C#.NStar Alpha
Etyuhibosecyu 20.11.2025
Уже можно не только тестировать, но и пользоваться C#. NStar - писать оконные приложения, содержащие надписи, кнопки, текстовые поля и даже изображения, например, моя игра "Три в ряд" написана на этом. . .
Мысли в слух
kumehtar 18.11.2025
Кстати, совсем недавно имел разговор на тему медитаций с людьми. И обнаружил, что они вообще не понимают что такое медитация и зачем она нужна. Самые базовые вещи. Для них это - когда просто люди. . .
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2025, CyberForum.ru