-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvectorestudiantes.h
More file actions
119 lines (98 loc) · 2.97 KB
/
vectorestudiantes.h
File metadata and controls
119 lines (98 loc) · 2.97 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
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
template <typename T>
class VectorEstudiantes
{
private:
vector<T> data;
public:
VectorEstudiantes() {}
// Agregar un elemento al vector
void push_back(const T &element)
{
data.push_back(element);
}
// Obtener el tamaño del vector
int size() const
{
return data.size();
}
// Obtener el elemento en una posición dada
T &operator[](int index)
{
return data[index];
}
// Obtener el elemento en una posición dada (versión constante)
const T &operator[](int index) const
{
return data[index];
}
// Iterador de inicio (begin)
typename vector<T>::iterator begin()
{
return data.begin();
}
// Iterador de fin (end)
typename vector<T>::iterator end()
{
return data.end();
}
// Iterador de inicio (begin) constante
typename vector<T>::const_iterator begin() const
{
return data.begin();
}
// Iterador de fin (end) constante
typename vector<T>::const_iterator end() const
{
return data.end();
}
};
// Función para calcular el promedio de calificaciones por asignatura
double calcularPromedioAsignatura(const VectorEstudiantes<pair<string, pair<string, double>>> &vectEstudiantes, const string &asignatura)
{
double sumaCalificaciones = 0.0;
int cantidadEstudiantes = 0;
for (const auto &estudiante : vectEstudiantes)
{
if (estudiante.second.first == asignatura)
{
sumaCalificaciones += estudiante.second.second;
cantidadEstudiantes++;
}
}
return cantidadEstudiantes > 0 ? sumaCalificaciones / cantidadEstudiantes : 0.0;
}
// Función para encontrar al estudiante con el mejor desempeño
pair<string, double> encontrarMejorEstudiante(const VectorEstudiantes<pair<string, pair<string, double>>> &vectEstudiantes)
{
pair<string, double> mejorEstudiante = {"", 0.0};
for (const auto &estudiante : vectEstudiantes)
{
if (estudiante.second.second > mejorEstudiante.second)
{
mejorEstudiante = {estudiante.first, estudiante.second.second};
}
}
return mejorEstudiante;
}
// Función para encontrar la asignatura con la mayor dispersión de calificaciones
string encontrarAsignaturaMayorDispersion(const VectorEstudiantes<pair<string, pair<string, double>>> &vectEstudiantes)
{
string asignaturaMayorDispersion = "";
double mayorDispersion = 0.0;
for (const auto &estudiante : vectEstudiantes)
{
double promedioAsignatura = calcularPromedioAsignatura(vectEstudiantes, estudiante.second.first);
double dispersion = abs(estudiante.second.second - promedioAsignatura);
if (dispersion > mayorDispersion)
{
mayorDispersion = dispersion;
asignaturaMayorDispersion = estudiante.second.first;
}
}
return asignaturaMayorDispersion;
}