#include <iostream>
#include <iomanip>
#include <limits>
using namespace std;
const int CAPACIDAD = 5;
typedef struct {
char nombre[CAPACIDAD];
int precio;
} Producto;
void ingresar(Producto* ptr, int cap);
void mostrar(Producto* ptr, int cap);
int main() {
Producto* ptr = nullptr;
int n = 0;
cout << "ingrese la cantidad de items a ingresar\t:\t"; cin >> n; cin.get();
ptr = new Producto[n];
ingresar(ptr, n);
mostrar(ptr, n);
delete[] ptr; ptr = nullptr;
}
void ingresar(Producto* ptr, int cap) {
for (int j = 0; j < cap; ++j) {
ptr[j].precio = 3 + rand()%4;
cout << "nombre del producto\t:\t";
cin.getline(ptr[j].nombre, CAPACIDAD);
if (cin.fail()) {
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
}
}
void mostrar(Producto* ptr, int cap) {
cout << "\t\t\t" << setw(CAPACIDAD) << "Nombre" << "\tPrecio\n";
for (int j = 0; j < cap; ++j) {
cout << "Item " << j << "\t:\t" << setw(CAPACIDAD) << ptr[j].nombre << "\t\t" << ptr[j].precio << endl;
}
}