list isn't working

Jan 30, 2020 at 6:20am
Hi, I have problem, code blocks is writing me that in main.cpp "seznam" was not declared in this scope and I don't know what to do with it. I'm really beginner in c++. And if you can look at all program if it makes sense it would be great. Thanks!

main.cpp
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
#include <iostream>
#include <string>
#include <math.h>
#include <fstream>
#include "trida.h"

using namespace std;


int main()
{
    cout << "TOTO JE SEZNAM MYCH NEJOBLIBENEJSICH SERIALU" << endl;

seznam s;

t.inicializaceSeznamu(s);
    t.PridejNaZacatek(s, "Penny Dreadful", 27, 2014);
    t.PridejNaZacatek(s, "The Magicians", 52, 2015);
    t.PridejNaZacatek(s, "Rick and Morty", 36, 2013);
    t.PridejNaZacatek(s, "You're the worst", 62, 2014);
    t.PridejNaZacatek(s, "Dirk Gently's Holistic Detective Agency", 18, 2016);
    t.PridejNaZacatek(s, "Disenchantment", 20, 2018);
    t.PridejNaZacatek(s, "Santa Clarita Diet", 30, 2017);
    t.vypisJmena(s);


int n;

    do {
cout  << endl;
cout << endl;
cout << "Stiskni:" << endl;
cout << "1 - pokud chces seradit seznam podle abecedy" << endl;
cout << "2 - pokud chces vyhledat prvek" << endl;
cout << "3 - pokud chces videt pocet epizod a rok vydani" << endl;
cout << "4 - pokud chces seznam prevest do poznamkoveho bloku" << endl;
cout << "5 - pokud chces program ukoncit" << endl;


        cin >> n;
            if (n==1){t.SerazeniPodleJmena(s);
         t.vypisJmena(s);
         continue;
        }

    if (n==2){
        }

    if (n==3){ t.vypisSeznamu(s);
        cout << endl;
            cout << "Chces serialy seradit podle abecedy" << endl;
            cout << endl;
            cout << "1 - ANO" << endl;
            cout << "2 -NE" << endl;
            int v;
            cin >> v;
            if(v==1){
                t.SerazeniPodleJmena(s);
                t.vypisSeznamu(s);
            }
            if(v==2){
                continue;
            }
            if(v>2);
    }

    if (n==4){

        }

    if(n==5){
        t.smazSeznam(s);
        break;
    }
    if (n>5) {cout << "Zvolil jsi spatne cislo. Zkus to znova" << endl;
    continue;
    }

    } while (n!=5);

cout << "Konec programu" << endl;



    return 0;
}




trida.cpp
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
#include <string>
#include <math.h>
#include <fstream>
#include "trida.h"


void trida::inicializaceSeznamu(seznam &s) {
    s.zacatek = NULL;
    s.konec = NULL;
    s.velikost = 0;
}
//vytvoøení seznamu
bool trida::prazdny(seznam s) {
    return (s.velikost == 0);
}

void trida::vypisJmenaRoku (seznam s){
    if (prazdny(s)){
        cout << "Seznam je prazdny." << endl;
    }
    else {
        prvek *pom = s.zacatek; // *pom je nový pomocný prvek
        while (pom != NULL){
            cout << pom ->JmenoSerialu << ". Vysila se od roku " << pom->RokVysilani<< endl;
            pom = pom -> dalsi;
        }
    }
}

void trida::vypisJmena (seznam s){
    if (prazdny(s)){
        cout << "Seznam je prazdny." << endl;
    }
    else {
        prvek *pom = s.zacatek; // *pom je nový pomocný prvek
        while (pom != NULL){
            cout << pom ->JmenoSerialu << endl;
            pom = pom -> dalsi;
        }
    }
}

void trida::vypisSeznamu (seznam s){
    if (prazdny(s)){
        cout << "Seznam je prazdny." << endl;
    }
    else {
        prvek *pom = s.zacatek; // *pom je nový pomocný prvek
        while (pom != NULL){
            cout << pom ->JmenoSerialu << " ma " << pom->PocetEpizod
            << " epizod. Je vysilan od roku " << pom->RokVysilani << "." << endl;
            pom = pom -> dalsi;
        }
    }
}

void trida::vypisRokVysilani (seznam s){
    if (prazdny(s)){
        cout << "Seznam je prazdny." << endl;
    }
    else {
        cout << "Vypis seznamu." << endl;
        prvek *pom = s.zacatek; // *pom je nový pomocný prvek
        while (pom != NULL){
            cout << pom ->JmenoSerialu << " se vysila od roku: " << pom->RokVysilani << endl;
            pom = pom -> dalsi;
        }
    }
}

void trida::PridejNaZacatek(seznam &s, prvek *p){
    if(prazdny(s)){
        s.zacatek = p;
        s.konec = p;
        s.velikost++; //pocet prvku
        return;
    }
    p->dalsi = s.zacatek;
    s.zacatek = p;
    s.velikost++;
}

void trida::PridejNaZacatek(seznam &s, string JmenoSerialu,
    int pocetEpizod, int RokVysilani) {
  PridejNaZacatek(s, new prvek{JmenoSerialu,pocetEpizod,RokVysilani, NULL});
}

void trida::smazPrvek (seznam &s){
    if (prazdny(s)){
        cout << "Seznam je prazdny" << endl;
        return;
    }
     s.velikost--; //zmensim pocet prvku
    prvek *pom = s.zacatek;
    s.zacatek = s.zacatek->dalsi;
    delete pom;
    if (s.zacatek == NULL) {
        s.konec = NULL;
        }

}

void trida::smazSeznam (seznam s){
    do {smazPrvek(s);
        s.velikost --;
    } while (prazdny(s));
}


bool trida::porovnejJmeno(prvek *c, prvek *d) {
    return (c->JmenoSerialu> d->JmenoSerialu);
}

void trida::prohodJmeno(seznam &s, prvek *c, prvek *d) {
    if (c == s.zacatek) {
        s.zacatek = d;
        c->dalsi = d->dalsi;
        d->dalsi = c;
        return;
    }

    prvek *pom = s.zacatek;
    while (pom->dalsi != c)
        pom = pom->dalsi;
    pom->dalsi = d;
    c->dalsi = d->dalsi;
    d->dalsi = c;
}

void trida::SerazeniPodleJmena (seznam &s)
{
 prvek *zarazka = s.konec;
    while (zarazka != s.zacatek) {
        prvek *pom = s.zacatek;
        while (pom->dalsi != zarazka) {
            if (porovnejJmeno (pom, pom->dalsi)) {
                prohodJmeno(s, pom, pom->dalsi);
            } else {
                pom = pom->dalsi;
            }
        }
        if (pom->dalsi == s.konec) {
            if (porovnejJmeno(pom, pom->dalsi)) {
                prohodJmeno(s, pom, pom->dalsi);
            }
        }
        zarazka = pom;
    }
}


trida.h
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
#ifndef TRIDA_H_INCLUDED
#define TRIDA_H_INCLUDED
#include <iostream>
#include <string>
#include <math.h>
#include <fstream>

using namespace std;

class trida {

public:

struct trida::prvek {
    string JmenoSerialu;
    int PocetEpizod;
    int RokVysilani;
    prvek *dalsi;//ukazatel na dalsi prvek
};
 
struct trida::seznam {
    prvek *zacatek;
    prvek *konec;
    int velikost;
};

struct seznam;
struct prvek;

void inicializaceSeznamu(seznam &s);

bool prazdny(seznam s);

void vypisJmenaRoku (seznam s);

void vypisJmena (seznam s);

void vypisSeznamu (seznam s);

void vypisRokVysilani (seznam s);

void PridejNaZacatek(seznam &s, prvek *p);

void PridejNaZacatek(seznam &s, string JmenoSerialu,
    int pocetEpizod, int RokVysilani);

void smazPrvek (seznam &s);

void smazSeznam (seznam s);

bool porovnejJmeno(prvek *c, prvek *d);

void prohodJmeno(seznam &s, prvek *c, prvek *d);

void SerazeniPodleJmena (seznam &s);
};

#endif // TRIDA_H_INCLUDED 
Jan 30, 2020 at 6:50am
TOTO JE SEZNAM MYCH NEJOBLIBENEJSICH SERIALU
Santa Clarita Diet
Disenchantment
Dirk Gently's Holistic Detective Agency
You're the worst
Rick and Morty
The Magicians
Penny Dreadful


Stiskni:
1 - pokud chces seradit seznam podle abecedy
2 - pokud chces vyhledat prvek
3 - pokud chces videt pocet epizod a rok vydani
4 - pokud chces seznam prevest do poznamkoveho bloku
5 - pokud chces program ukoncit


If you wait for a few seconds I'll tell you how to fix it. There are about 5 or 6 small changes to make :)
Jan 30, 2020 at 6:51am
in main.cpp:

1
2
3
4
5
6
7
8
9
int main()
{
    cout << "TOTO JE SEZNAM MYCH NEJOBLIBENEJSICH SERIALU" << endl;

trida::seznam s;
    
    trida t; // <--

t.inicializaceSeznamu(s);
Jan 30, 2020 at 6:53am
in trida.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class trida {

public:

    struct prvek{//trida::prvek {
    string JmenoSerialu;
    int PocetEpizod;
    int RokVysilani;
    prvek *dalsi;//ukazatel na dalsi prvek
};
 
    struct seznam{  //trida::seznam {
    prvek *zacatek;
    prvek *konec;
    int velikost;
};

//struct seznam;
//struct prvek;

void inicializaceSeznamu(seznam &s);
Jan 30, 2020 at 6:53am
That should be it. Except there is one warning in main.cpp:

1
2
3
4
5
6
7
8
            if(v==1){
                t.SerazeniPodleJmena(s);
                t.vypisSeznamu(s);
            }
            if(v==2){
                continue;
            }
            if(v>2); // <-- SO, WHAT HAPPENS HERE? 
Last edited on Jan 30, 2020 at 6:55am
Jan 30, 2020 at 7:00am
Thank you so much!
Topic archived. No new replies allowed.