-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProblema_1040.cpp
75 lines (63 loc) · 1.55 KB
/
Problema_1040.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
/*
@autor: Victor E. B. Rodrigues;
@data: 23/06/2021;
@nome: Média 3;
*/
#include <bits/stdc++.h>
#include <map>
#include <iomanip>
using namespace std;
double calculaMediaPonderada(multimap<double, int> ¬aPeso){
multimap<double,int>::iterator it = notaPeso.begin();
double media = 0; int somaPesos= 0;
do{
media+= (it->first) * (it->second);
somaPesos+= it->second;
it++;
}while(it != notaPeso.end());
media/=somaPesos;
return media;
}
bool estaAprovado(double &media){
if(media >= 7)
return true;
return false;
}
double fazExame(double &media){
double notaExame;
cin >> notaExame;
cout << "Nota do exame: " << notaExame << endl;
return (media+notaExame)/2.0;
}
void printaSituacao(double &media){
if(estaAprovado(media))
cout << "Aluno aprovado." << endl;
else if(media >= 5){
cout << "Aluno em exame." << endl;
media = fazExame(media);
if(media>=5){
cout << "Aluno aprovado." << endl;
} else{
cout << "Aluno reprovado." << endl;
}
cout << "Media final: " << media << endl;
} else
cout << "Aluno reprovado." << endl;
}
int main() {
cin.tie(NULL);
cout.tie(NULL);
ios::sync_with_stdio(0);
multimap<double, int> notaPeso;
double n1,n2,n3,n4;
cin >> n1 >> n2 >> n3 >> n4;
notaPeso.insert(pair <double,int> (n1,2) );
notaPeso.insert(pair <double,int> (n2,3) );
notaPeso.insert(pair <double,int> (n3,4) );
notaPeso.insert(pair <double,int> (n4,1) );
cout << setprecision(1) << fixed;
double media = calculaMediaPonderada(notaPeso);
cout << "Media: " << media << endl;
printaSituacao(media);
return 0;
}