-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass2.cpp
More file actions
128 lines (86 loc) · 2.81 KB
/
Copy pathclass2.cpp
File metadata and controls
128 lines (86 loc) · 2.81 KB
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
#include <iostream>
using namespace std;
class Persona{
private:
// attributi
string nome;
string cognome;
string cf;
public:
static int counter;
// costruttore
Persona(string nome, string cognome) : nome(nome), cognome(cognome), cf(""){
//cf
counter++;
}
Persona(string nome, string cognome, string cf) : nome(nome), cognome(cognome), cf(cf){
//cf
counter++;
}
~Persona(){
cout << "persona eleiminata" << endl;
}
const string& get_nome() {
return this->nome;
}
const string& get_cognome() {
return this->cognome;
}
const string& get_cf() {
return this->cf;
}
//setter
//DTO data transfer object
void set_nome(string& nome) {
this->nome = nome;
}
void set_cognome(string& cognome) {
this->nome = cognome;
}
void set_cf(string& cf) {
this->cf = cf;
}
void print() const {
cout << this->nome << " " << this->cognome<< " " << this->cf << endl;
}
};
int Persona::counter = 0;
class UtenteGomp
{
private:
int id_gomp;
public:
UtenteGomp(int id_gomp) : id_gomp(id_gomp) {}
const int& get_id_gomp() const { return id_gomp; }
void set_id_gomp(const int& id_gomp) { this->id_gomp = id_gomp;}
inline void print() const { cout << get_id_gomp() << " "; } // con inline il compilatore dove e possibile alloca il metodo all oggetto non alla classe
};
class MembroUniversitario : public Persona, UtenteGomp{ // MU eredita da persona in questo caso lascia inalterato la parte pubblica
// se invece indico rpivate vuo dire che tutto cio che eredito da persona rimane privato in MU
private:
string num_matricola;
public:
MembroUniversitario(string nome, string cognome, string cf, int id_gomp, string num_matricola)
: Persona(nome, cognome, cf), UtenteGomp(id_gomp), num_matricola(num_matricola) { // richiamo il costruttore di perosna
}
const string& get_num_matricola() { return this->num_matricola; }
void set_num_matricola(const int& num_matricola) { this->num_matricola = num_matricola; }
void print() const
{
Persona::print();
UtenteGomp::print();
cout << num_matricola << endl;
}
};
int main(){
Persona p("mario", "rossi", "MR920B350");
string cognome = "bianchi"; // !!!!!!
p.set_cognome(cognome);
cout << p.get_nome() << " " << p.get_cognome() << " " << p.get_cf() << endl;
MembroUniversitario mu1("franscesco", "gialli", "FG123", 12, "1900");
//cout << mu1.get_nome() << endl;
mu1.print();
cout << "numero di volte che e stata chiamata Persona" << endl;
cout << p.counter << endl;
return 0;
}