forked from zamfiroiu/POO2018
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1045_seminar03.cpp
84 lines (67 loc) · 1.27 KB
/
1045_seminar03.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
#include<iostream>
#include<string>
using namespace std;
class Erou {
public:
string nume;
int nivel;
float viata;
void cresteNivel() {
this->nivel++;
}
void afisare() {
cout << "Eroul " << nume << " are " << viata
<< " puncte viata si este nivelul: " << nivel << endl;
}
};
void afisare(Erou e) {
cout << e.nume << " este nivelul " << e.nivel
<< " si are " << e.viata << " viata." << endl;
}
void main() {
Erou e;
Erou e2;
e.nivel = 2;
e.nume = "EroulMeu";
e.viata = 89;
Erou* pe;
pe = new Erou();
(*pe).nivel = 3;
pe->nume = "Harap-Alb";
pe->viata = 95;
afisare(e);
afisare(*pe);
Erou*pe2 = pe;
Erou * pe3 = &e;
e.afisare();
pe->afisare();
e.cresteNivel();
e.afisare();
Erou* ve;
int n = 3;
ve = new Erou[n];
for (int i = 0; i < n; i++) {
ve[i].nivel = i + 1;
ve[i].nume = "Praslea";
ve[i].viata = i + 45;
}
for (int i = 0; i< n; i++) {
ve[i].afisare();
}
Erou* *vpe;
vpe = new Erou*[n];
for (int i = 0; i < n; i++) {
vpe[i] = new Erou();
}
for (int i = 0; i < n; i++) {
vpe[i]->nivel = i;
vpe[i]->nume = "Batman";
vpe[i]->viata = 99;
}
for (int i = 0; i < n; i++) {
delete vpe[i];
}
delete[]vpe;
delete[]ve;
delete pe3;
}