-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdogs.cpp
133 lines (111 loc) · 3.43 KB
/
dogs.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
#include <iostream>
#include <string>
using namespace std;
class Kutya {
string nev;
unsigned kor;
public:
const string &get_nev() const {
return nev;
}
unsigned int get_kor() const {
return kor;
}
Kutya(const string &nev, unsigned int kor) : nev(nev), kor(kor) {
cout << "Kutya letrehozva" << endl;
}
public:
/* virtual string pedigre(){
string a = to_string (kor);
return "nev:" + nev+", kor:" + a +" ev";
}*/
virtual string pedigre() const{
string a = to_string (kor);
return "nev:" + nev+", kor:" + a +" ev";
}
virtual string* terel(const string* nyaj, unsigned& nyajhossz) const{
if (nyaj == nullptr || nyajhossz == 0){
nyajhossz = 0;
return nullptr;
}
string* tomb= new string[nyajhossz];
for (int i = 0; i < nyajhossz; ++i) {
tomb[i] = nyaj[i];
}
return tomb;
}
/* const string* terel(const string* nyaj, unsigned& nyajhossz) const{
if (nyaj == nullptr || nyajhossz == 0){
nyajhossz = 0;
return nullptr;
}
string* tomb= new string[nyajhossz];
for (int i = 0; i < nyajhossz; ++i) {
tomb[i] = nyaj[i];
}
return tomb;
}*/
};
class BorderCollie : public Kutya{
unsigned terelo_kapacitas;
public:
unsigned int get_terelo_kapacitas() const {
return terelo_kapacitas;
}
BorderCollie(const string &nev, unsigned int kor, unsigned int tereloKapacitas) : Kutya(nev, kor),
terelo_kapacitas(
tereloKapacitas) {}
virtual string pedigre() const{
string a = to_string (get_kor());
string b = to_string(terelo_kapacitas);
return "nev:" + get_nev()+", kor:" + a +" ev, faj:border collie, terelo kapacitas:"+ b +" db birka";
}
string* terel(const string* nyaj, unsigned& nyajhossz) const override{
if (nyaj == nullptr || nyajhossz == 0) {
nyajhossz = 0;
return nullptr;
}
string* tomb = new string[nyajhossz];
for (int i = 0; i < nyajhossz; ++i) {
tomb[i] = nyaj[i];
}
int terelt = 0;
int i = 0;
int j = 0;
string csere;
while (terelt < terelo_kapacitas && i != nyajhossz) {
if(tomb[i] != ""){
terelt++;
csere = tomb[j];
tomb[j] = tomb[i];
tomb[i] = csere;
j++;
}
i++;
}
int ujhosz = 0;
for (int k = 0; k < nyajhossz; ++k) {
if(tomb[k] == "") {
ujhosz++;
} else {
ujhosz = 0;
}
}
nyajhossz -= ujhosz;
return tomb;
}
};
void print(const Kutya& k){
cout << k.pedigre() << endl;
}
int main() {
std::cout << "Hello, World!" << std::endl;
BorderCollie bc("Jess", 12, 2);
string nyaj[] = {"","","", "Frici", "Julcsa", "gyuri", "margit"};
unsigned hossz = 7;
string* osszeterelt = bc.terel(nyaj, hossz);
for (unsigned i = 0; i < hossz; ++i) {
cout << osszeterelt[i] << 'e' << endl;
}
return 0;
}