-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08_classi_esercitazione2.cpp
More file actions
135 lines (108 loc) · 4.28 KB
/
Copy path08_classi_esercitazione2.cpp
File metadata and controls
135 lines (108 loc) · 4.28 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
129
130
131
132
133
134
135
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
#define FILE_PATH "/home/matteo/Desktop/programmazione2/Laboratorio/08_libretto.txt"
class Materia{
private:
int id;
string nome;
public:
Materia(const int& _id, const string& _nome) :
id(_id), nome(_nome){}
const int& get_id() const {return this->id;}
const string& get_nome() const {return this->nome;}
};
class Esame{
private:
const Materia* materia;
int voto;
// Data, prof...
public:
Esame(const Materia* _materia, const int& _voto) :
materia(_materia), voto(_voto){}
const Materia* get_materia() const {return this->materia;}
const int& get_voto() const {return this->voto;}
};
class Studente{
private:
string cf;
string matricola;
vector<Esame> esami;
public:
Studente(const string& _cf, const string& _matricola) :
cf(_cf), matricola(_matricola){}
const string& get_cf() const {return this->cf;}
const string& get_matricola() const {return this->matricola;}
const vector<Esame>* get_esami() const {return (&esami);}
const vector<Esame>::const_iterator ricerca_esame(const Materia* materia) const {
for(vector<Esame>::const_iterator it = this->esami.begin(); it < this->esami.end(); it++)
if((*it).get_materia()->get_id() == materia->get_id())
return it;
return this->esami.end();
}
bool verifica_esame(const Materia* materia) const {
if(ricerca_esame(materia) == this->esami.end())
return false;
return true;
}
int get_esito(const Materia* materia) const {
const vector<Esame>::const_iterator esito = ricerca_esame(materia);
if(esito == this->esami.end())
return -1;
return esito->get_voto();
}
bool registra_esame(const Materia* materia, const int voto){
if(verifica_esame(materia))
return false;
const Esame esito(materia, voto);
this->esami.push_back(esito);
return true;
}
bool elimina_esame(const Materia* materia){
const vector<Esame>::const_iterator esito = ricerca_esame(materia);
if(esito == this->esami.end())
return false;
this->esami.erase(esito);
return true;
}
void stampa_libretto(const string& file_path){
ofstream output_file;
output_file.open(file_path);
if(output_file.is_open()){
output_file << "LIBRETTO DELLO STUDENTE CF: " << this->get_cf() << " MATRICOLA: " << this->get_matricola() << endl;
for(size_t i = 0; i < this->esami.size(); i++){
output_file << "[" << i
<< "] ID: " << this->esami[i].get_materia()->get_id()
<< " MATERIA: " << this->esami[i].get_materia()->get_nome()
<< " VOTO: " << this->esami[i].get_voto() << endl;
}
output_file.close();
}
}
};
int main(){
Studente st("RSSMRA69T42C351X", "1000069420");
Materia materie[4] = {
Materia(1000,"Algebra"),
Materia(1001,"Architettura"),
Materia(1002,"Programmazione 1"),
Materia(1003,"Strutture Discrete")
};
st.registra_esame(&(materie[0]), 28); // Algebra
st.registra_esame(&(materie[1]), 25); // Architettura
st.registra_esame(&(materie[2]), 30); // Programmazione 1
st.registra_esame(&(materie[3]), 18); // Strutture Discrete
Materia* strutture = &(materie[3]);
cout << "L'esame \"" << (*strutture).get_nome() << "\" ";
if(st.verifica_esame(strutture)){
cout << "e' stato sostenuto" << endl;
cout << "Il voto e' " << st.get_esito(strutture) << endl;
if(st.elimina_esame(strutture))
cout << "L'esame e' stato eliminato dal libretto" << endl;
}
else
cout << "non e' stato sostenuto" << endl;
st.stampa_libretto(FILE_PATH);
return 0;
}