-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
128 lines (121 loc) · 4.43 KB
/
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
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 "media.h"
static unsigned short keep_running;
using namespace std;
int main(){
int voti[MAX_ESAMI];
int cfu[MAX_ESAMI];
int index = 0;
int select;
keep_running = 1;
int ctrl,l;
double media_p, media_A, media_a, media_P;
int cfu_prev, resto;
bool leng;
while(1) {
cout<<"Choose language"<<endl;
cout<<"1) English\n2) Italiano"<<endl;
cin>>l;
if(l == 1) {
leng = false;
break;
}
else if(l == 2) {
leng = true;
break;
} else {
cout<<"Invalid option..."<<endl;
}
}
system("clear");
if(leng)
cout<<"[MAIN] Calcolo della media ponderata dei voti...\n";
else
cout<<"[MAIN] Calculation of the weighted average of the marks...\n";
while(keep_running){
if(leng) {
cout<<"\nScegliere un operazione\n1) Aggiungi esami\n2) Calcolo media ponderata\n3) Stampa lista\n4) Cancella voto\n5) Previsioni media\n6) Massima media raggiungibile\n7) Minima media raggiungibile\n0) Exit\n";
cout<<"\nNumero esami: "<<index<<endl;
cout<<">> ";
} else {
cout<<"\nChoose an operation\n1) Add exams\n2) Calculation of the weighted average\n3) Print the list\n4) Remove grade\n5) Average forecasts\n6) Maximum achievable average\n7) Minimum achievable average\n0) Exit\n";
cout<<"\nNumber of exams: "<<index<<endl;
cout<<">> ";
}
cin>>select;
system("clear");
cout<<endl;
switch(select){
case 1:
resto = insertVoto(voti,cfu,index,leng) - index;
index += resto;
break;
case 2:
if(leng)
cout<<"Calcolo media..."<<endl;
else
cout<<"Average calculation..."<<endl;
usleep(500000);
media_p = mediaPonderata(voti,cfu,index);
media_P = (media_p * 110) / 30;
media_a = mediaAritmetica(voti,index);
media_A = (media_a * 110) / 30;
if(leng) {
cout<<"\nNumero esami: "<<index<<"\nMedia aritmetica su 30: "<<media_a<<"\nMedia ponderata su 30: "<<media_p<<"\nMedia aritmetica su 110: "<<media_A<<"\nMedia ponderata su 110: "<<media_P<<endl;
} else {
cout<<"\nNumber of exams: "<<index<<"\nArithmetic average over 30: "<<media_a<<"\nWeighted average over 30: "<<media_p<<"\nArithmetic average over 110: "<<media_A<<"\nWeighted average over 110: "<<media_P<<endl;
}
break;
case 3:
if(index != 0){
stampaLista(voti,cfu,index,leng);
}else{
if(leng)
cout<<"\nNon ci sono voti registrati al momento..."<<endl;
else
cout<<"There are no votes registered at the moment..."<<endl;
}
break;
case 4:
ctrl = cancellaVoto(voti,cfu,index,leng);
if(ctrl == 1){
index = index - 1;
}else{
if(leng)
cout<<"\nVOTO NON TROVATO"<<endl;
else
cout<<"\nNOT FOUND"<<endl;
usleep(500000);
}
break;
case 5:
if(leng)
cout<<"\nInserire il numero di cfu del prossimo esame: ";
else
cout<<"\nEnter the number of credits for the next exam: ";
cin>>cfu_prev;
cout<<endl;
previsioniMedia(voti,cfu,index,cfu_prev,leng);
break;
case 6:
maxMedia(voti,cfu,index,leng);
break;
case 7:
minMedia(voti,cfu,index,leng);
break;
case 0:
if(leng)
cout<<"\nUscita in corso...\n";
else
cout<<"\nExit in progress...\n";
keep_running = 0;
break;
default:
if(leng)
cout<<"\n[ERROR] Opzione non valida\n";
else
cout<<"\n[ERROR] Invalid option\n";
break;
}
}
return 0;
}