-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvectorinventario.h
More file actions
48 lines (42 loc) · 1.26 KB
/
vectorinventario.h
File metadata and controls
48 lines (42 loc) · 1.26 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
#include <iostream>
#include <string>
#include <vector>
using namespace std;
// Definición de la clase vectorinventario
class vectorinventario
{
private:
vector<pair<string, pair<double, int>>> vectorInven; // Vector que almacena pares de nombre, precio, y cantidad
public:
// Constructor que inicializa el vector con un tamaño especificado
vectorinventario(int size) : vectorInven(size) {}
// Método para establecer un elemento en el vector con nombre, número y precio dados
void setelement(int index, const string& name, int numero, double precio)
{
vectorInven[index] = make_pair(name, make_pair(precio, numero));
}
// Método que devuelve el valor total del inventario
double valor_inv() const
{
double inv = 0;
for(const auto& product : vectorInven)
{
inv += product.second.first * product.second.second;
}
return inv;
}
string mas_alto() const
{
string n;
int aux = 0;
for(const auto& product : vectorInven)
{
if(product.second.second > aux)
{
n = product.first;
aux = product.second.second; // Actualizar el valor máximo
}
}
return n;
}
};