fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. class Productos{
  6. public:
  7. Productos();
  8. Productos(int vId, string vNombre, double vPrecio);
  9. void setId(int id);
  10. void setNombre(string nom);
  11. void setPrecio(double prec);
  12. int getId();
  13. string getNombre();
  14. double getPrecio();
  15. void muestraProductos();
  16. private:
  17. int id;
  18. string nombre;
  19. double precio;
  20. };
  21.  
  22. class Tienda{
  23. public:
  24. Tienda();
  25. Tienda(int vId, string vNombre, vector<Productos> vInventario);
  26. void setId(int id);
  27. void setNombre(string nom);
  28. void setInventario(vector<Productos> inv);
  29. int getId();
  30. string getNombre();
  31. vector<Productos> getInventario();
  32. void muestraTienda();
  33. void verProductos();
  34. void agregarProductos();
  35. void borrarProductos();
  36. void modificarProductos();
  37. Productos obtenerProducto(int idT);
  38. private:
  39. int id;
  40. string nombre;
  41. vector<Productos> inventario;
  42. };
  43.  
  44. class Compra{
  45. public:
  46. Compra();
  47. Compra(int vId, Tienda vTienda);
  48. void setId(int id);
  49. void setNumProd(int np);
  50. void setProductos(vector<Productos> carr);
  51. void setTotal(float tot);
  52. int getId();
  53. int getNumProd();
  54. vector<Productos> getProductos();
  55. float getTotal();
  56. void verCarrito();
  57. void comprarProductos();
  58. void verProductos();
  59. void agregarProductos();
  60. void borrarProductos();
  61. private:
  62. int id;
  63. int numProd;
  64. vector<Productos> carrito;
  65. float precioTotal;
  66. Tienda tienda;
  67. };
  68.  
  69. class Cliente{
  70. public:
  71. Cliente();
  72. Cliente(int vId, string vNombre, int vNumTel, string vTipoTarj, int vNumTarj);
  73. void setId(int id);
  74. void setNombre(string nom);
  75. void setNumTel(int nt);
  76. void setTipoTarj(string tt);
  77. void setNumTarj(int ntarj);
  78. int getId();
  79. string getNombre();
  80. int getNumTel();
  81. string getTipoTarj();
  82. int getNumTarj();
  83. void iniciarCompra(Tienda vTienda);
  84. //void muestraCliente();
  85. private:
  86. int id;
  87. string nombre;
  88. int numTel;
  89. string tipoTarj;
  90. int numTarj;
  91. };
  92.  
  93.  
  94. void Productos::setId(int id){
  95. id = id;
  96. }
  97.  
  98. int Productos::getId(){
  99. return id;
  100. }
  101.  
  102. void Productos::setNombre(string nom){
  103. nombre = nom;
  104. }
  105.  
  106. string Productos::getNombre(){
  107. return nombre;
  108. }
  109.  
  110. void Productos::setPrecio(double prec){
  111. precio=prec;
  112. }
  113.  
  114. double Productos::getPrecio(){
  115. return precio;
  116. }
  117.  
  118. void Tienda::setId(int id){
  119. id = id;
  120. }
  121. int Tienda::getId(){
  122. return id;
  123. }
  124.  
  125. void Tienda::setNombre(string nom){
  126. nombre = nom;
  127. }
  128. string Tienda::getNombre(){
  129. return nombre;
  130. }
  131.  
  132. void Tienda::setInventario(vector<Productos> inv){
  133. inventario = inv;
  134. }
  135. vector<Productos> Tienda::getInventario(){
  136. return inventario;
  137. }
  138.  
  139. void Compra::setId(int id){
  140. id = id;
  141. }
  142.  
  143. int Compra::getId(){
  144. return id;
  145. }
  146.  
  147. void Compra::setNumProd(int np){
  148. numProd=np;
  149. }
  150.  
  151. int Compra::getNumProd(){
  152. return numProd;
  153. }
  154.  
  155. void Compra::setProductos(vector<Productos> carr){
  156. carrito = carr;
  157. }
  158.  
  159. vector<Productos> Compra::getProductos(){
  160. return carrito;
  161. }
  162.  
  163. void Compra::setTotal(float tot){
  164. precioTotal = tot;
  165. }
  166.  
  167. float Compra::getTotal(){
  168. return precioTotal;
  169. }
  170.  
  171. void Cliente::setId(int id){
  172. id = id;
  173. }
  174.  
  175. int Cliente::getId(){
  176. return id;
  177. }
  178.  
  179. void Cliente::setNombre(string nom){
  180. nombre = nom;
  181. }
  182.  
  183. string Cliente::getNombre(){
  184. return nombre;
  185. }
  186.  
  187. void Cliente::setNumTel(int nt){
  188. numTel = nt;
  189. }
  190.  
  191. int Cliente::getNumTel(){
  192. return numTel;
  193. }
  194.  
  195. void Cliente::setTipoTarj(string tt){
  196. tipoTarj = tt;
  197. }
  198.  
  199. string Cliente::getTipoTarj(){
  200. return tipoTarj;
  201. }
  202.  
  203. void Cliente::setNumTarj(int ntarj){
  204. numTarj = ntarj;
  205. }
  206.  
  207. int Cliente::getNumTarj(){
  208. return numTarj;
  209. }
  210.  
  211.  
  212.  
  213. void Tienda::muestraTienda() {
  214. cout<<" id ->"<<id<<endl;
  215. cout<<", Nombre ->"<<nombre<<endl;
  216. cout<<", Inventario ->"<<endl;
  217. this->verProductos();
  218. }
  219.  
  220. void Tienda::verProductos(){
  221. for(int i=0; i<inventario.size();i++){
  222. inventario[i].muestraProductos();
  223. }
  224. }
  225.  
  226. Productos Tienda::obtenerProducto(int idT){
  227. return inventario[idT];
  228. }
  229.  
  230. void Productos::muestraProductos(){
  231. cout<<id<<" "<<nombre<<" "<<precio<<endl;
  232. }
  233.  
  234. void Tienda::agregarProductos(){
  235. int idTemp;
  236. string nombreTemp;
  237. double precioTemp;
  238. cout<<"Escribe el nombre: "<<endl;
  239. cin>>nombreTemp;
  240. cout<<"Escribe el precio: "<<endl;
  241. cin>>precioTemp;
  242. Productos productoTemp(inventario.size(), nombreTemp, precioTemp);
  243. inventario.push_back(productoTemp);
  244. }
  245.  
  246. void Tienda::borrarProductos(){
  247. this->verProductos();
  248. int borrar;
  249. cout<<"Escribe el id del producto que quieres eliminar: "<<endl;
  250. cin>>borrar;
  251. inventario.erase(inventario.begin()+borrar);
  252. for(int i=borrar;i<inventario.size();i++){
  253. inventario[i].setId(i);
  254. }
  255. }
  256.  
  257. void Tienda::modificarProductos(){
  258. this->verProductos();
  259. int idTemp;
  260. string nombreTemp;
  261. double precioTemp;
  262. cout<<"Escribe el id del producto que quieres modificar: "<<endl;
  263. cin>>idTemp;
  264. cout<<"Escribe el nuevo nombre: "<<endl;
  265. cin>>nombreTemp;
  266. inventario[idTemp].setNombre(nombreTemp);
  267. cout<<"Escribe el nuevo precio: "<<endl;
  268. cin>>precioTemp;
  269. inventario[idTemp].setPrecio(precioTemp);
  270. cout<<"Ya está modificado."<<endl;
  271. }
  272.  
  273. void Cliente::iniciarCompra(Tienda vTienda){
  274. Compra compra(1, vTienda);
  275. int opcion=0;
  276. while(opcion!=6){
  277. cout<<"Qué quieres hacer hoy? "<<endl;
  278. cout<<"1. Ver Productos. "<<endl;
  279. cout<<"2. Agregar Productos al carrito. "<<endl;
  280. cout<<"3. Borrar Productos del carrito. "<<endl;
  281. cout<<"4. Ver carrito. "<<endl;
  282. cout<<"5. Comprar Productos. "<<endl;
  283. cout<<"6. Salir. "<<endl;
  284. switch(opcion){
  285. case 1: compra.verProductos(); break;
  286. case 2: compra.agregarProductos(); break;
  287. case 3: compra.borrarProductos(); break;
  288. case 4: compra.verCarrito(); break;
  289. case 5: compra.comprarProductos(); break;
  290. case 6: cout<<"Gracias. "<<endl; break;
  291. default: cout<<"Favor de escribir un numero de las opciones. "; break;
  292. }
  293. }
  294.  
  295. }
  296.  
  297. Tienda::Tienda() {
  298. id = 1;
  299. nombre = "Default";
  300. inventario = {};
  301. }
  302.  
  303. Tienda::Tienda(int vId, string vNombre, vector<Productos> vInventario) {
  304. id = vId;
  305. nombre = vNombre;
  306. inventario = vInventario;
  307. }
  308.  
  309. Productos::Productos() {
  310. id = 1;
  311. nombre = "Default";
  312. price: 1.11;
  313. }
  314.  
  315. Productos::Productos(int vId, string vNombre, double vPrecio) {
  316. id = vId;
  317. nombre = vNombre;
  318. precio = vPrecio;
  319. }
  320.  
  321. Cliente::Cliente() {
  322. id = 1;
  323. nombre = "Default";
  324. numTel = 1234567891;
  325. tipoTarj = "Default";
  326. numTarj = 1;
  327.  
  328. }
  329.  
  330. Cliente::Cliente(int vId, string vNombre, int vNumTel, string vTipoTarj, int vNumTarj) {
  331. id = vId;
  332. nombre = vNombre;
  333. numTel = vNumTel;
  334. tipoTarj = vTipoTarj;
  335. numTarj = vNumTarj;
  336. }
  337.  
  338. Compra::Compra() {
  339. id = 1;
  340. }
  341.  
  342. Compra::Compra(int vId, Tienda vTienda) {
  343. id = vId;
  344. tienda = vTienda;
  345. }
  346.  
  347. void Compra::verProductos(){
  348. tienda.verProductos();
  349. }
  350.  
  351. void Compra::agregarProductos(){
  352. int idT;
  353. Productos prodCopia;
  354. cout<<"Qué quieres agregar al carrito? Escribe su id: "<<endl;
  355. cin>>idT;
  356. prodCopia=tienda.obtenerProducto(idT);
  357. carrito.push_back(prodCopia);
  358. }
  359.  
  360. void Compra::borrarProductos(){
  361. int idT;
  362. cout<<"Qué quieres borrar del carrito? Escribe su id: "<<endl;
  363. cin>>idT;
  364. for(int i=0;i<carrito.size();i++){
  365. if(carrito[i].getId()==idT){
  366. carrito.erase(carrito.begin()+i);
  367. break;
  368. }
  369. }
  370. }
  371.  
  372. void Compra::verCarrito(){
  373. double precioTot=0;
  374. for(int i=0;i<carrito.size();i++){
  375. carrito[i].muestraProductos();
  376. precioTot+=carrito[i].getPrecio();
  377. }
  378. cout<<"El precio total es de: "<<endl;
  379. cout<<precioTot<<endl;
  380. }
  381.  
  382. void Compra::comprarProductos(){
  383. double precioTot=0;
  384. for(int i=0;i<carrito.size();i++){
  385. precioTot+=carrito[i].getPrecio();
  386. }
  387. cout<<"El precio total es de: "<<endl;
  388. cout<<precioTot<<endl;
  389. cout<<"Gracias por su compra."<<endl;
  390. }
  391.  
  392.  
  393.  
  394. int main() {
  395. Tienda soriana(2, "Soriana", {});
  396. soriana.agregarProductos();
  397. soriana.verProductos();
  398. return 0;
  399. }
Success #stdin #stdout 0.01s 5360KB
stdin
manzana
20
stdout
Escribe el nombre: 
Escribe el precio: 
0 manzana 20