was not declared in this scope

Jan 30, 2020 at 12:46am
Hi, I have problem, code blocks is writing me that "seznam" was not declared in this scope and I don't know what to do with it. I'm really beginner in c++.

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
151
152
153
154
155
156
157
158
159
160
161
162
163
#include <string>
#include <math.h>
#include <fstream>
#include "trida.h"


struct trida::prvek {
    string JmenoSerialu;
    int PocetEpizod;
    int RokVysilani;
    prvek *dalsi;//ukazatel na dalsi prvek
};
//šablona na tvoření prvkù
struct trida::seznam {
    prvek *zacatek;
    prvek *konec;
    int velikost;
};
//struktura seznamu
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
#ifndef TRIDA_H_INCLUDED
#define TRIDA_H_INCLUDED
#include <iostream>
#include <string>
#include <math.h>
#include <fstream>

using namespace std;

class trida {

public:

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 12:53am
1
2
3
4
5
struct trida::seznam {
    prvek *zacatek;
    prvek *konec;
    int velikost;
};
Define this (without the trida:: part) within your trida class in your .h (header) file.
Last edited on Jan 30, 2020 at 12:54am
Jan 30, 2020 at 12:54am
It looks like you need to move this stuff from trida.cpp to trida.h:

1
2
3
4
5
6
7
8
9
10
11
12
struct trida::prvek {
    string JmenoSerialu;
    int PocetEpizod;
    int RokVysilani;
    prvek *dalsi;//ukazatel na dalsi prvek
};
//šablona na tvoření prvkù
struct trida::seznam {
    prvek *zacatek;
    prvek *konec;
    int velikost;
};

Jan 30, 2020 at 6:03am
I've tried this, but code blocks is still writing that it was not declared in this scope
Jan 30, 2020 at 7:22am
This was double posted and by going on post times is solved.

http://www.cplusplus.com/forum/beginner/267694/
Last edited on Jan 30, 2020 at 12:50pm
Topic archived. No new replies allowed.