Método set calcular precio total de una lista de productos de un vector
int total_price(vector<producto> l){
int total = 0;
for (auto p : l) total += p.price;
return total;
}
All generations.
int total_price(vector<producto> l){
int total = 0;
for (auto p : l) total += p.price;
return total;
}
int calculoPrecioTotal(int listaProductos[],int n)
{
int i;
int precioTotal=0;
for(i=0;i<n;i++){
precioTotal=precioTotal+listaProductos[i];
}
return precioTotal;
}
vector<vector<string>> productos = {
{ "001", "iPhone X", "0" },
{ "002", "Laptop Dell", "500" },
{ "003", "Monitor Samsung", "30" }
};
#include <stdio.h>
#include <stdlib.h>
struct Producto{
char id[15];
float precio;
};
struct Producto productos[5];
float calcular_total(void){
float total = 0;
for (int i = 0; i < 5; i++) {
total += productos[i].precio;
}
return total;
}
int main(int argc, char *argv[]) {
for (int i = 0; i < 5; i++) {
productos[i].precio = (i + 1) * 10;
}
printf("Total: %.2f\n", calcular_total());
return 0;
}
int add(int a, int b) {
return a + b;
}
#include <iostream>
using namespace std;
int main()
{
int Total;
int precio = 0;
int cantidad = 0;
int preciofinal = 0;
cout << "Ingrese cantidad de productos" << endl;
cin >> cantidad;
int productos[cantidad][2];
for (int i = 0; i < cantidad; i++){
cout << "Ingrese precio y cantidad del producto " << i << endl;
cin >> precio >> cantidad;
productos[i][0] = precio;
productos[i][1] = cantidad;
}
for (int i = 0; i < cantidad; i++){
preciofinal += productos[i][0]*productos[i][1];
}
cout << "Total a pagar" << preciofinal;
}
// variables
- String name
- String lastname
- String dni
- String address
- String phone
- String email
// methods
- void addClient()
- void addProduct()
- void addUser()
---
### **Hints:**
</details>
### **4.**
<details>
<summary>Click me to see the solution</summary>
<p>
**Code:**
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
class persona
{
public:
int edad;
string nombre;
string apellidos;
public:
persona(){};
~persona(){};
void leerDatos(){
cout<<"Ingrese el nombre: ";
cin>>nombre;
cout<<"Ingrese los apellidos: ";
cin>>apellidos;
cout<<"Ingrese la edad: ";
cin>>edad;
}
void mostrarDatos(){
cout<<"\nNombre: "<<nombre;
cout<<"\nApellidos: "<<apellidos;
cout<<"\nEdad: "<<edad;
cout<<endl<<endl
Generate
More than just a code generator. A tool that helps you with a wide range of tasks. All in one place.
Function from Description
Text Description to SQL Command
Translate Languages
Generate HTML from Description
Code to Explanation
Fix invalid Code
Get Test for Code
Class from Description
Regex from Description
Regex to Explanation
Git Command from Description
Linux Command
Function from Docstring
Add typing to code
Get Language from Code
Time complexity
CSS from Description
Meta Tags from Description