Advertisement
Guest User

Untitled

a guest
May 25th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.63 KB | None | 0 0
  1. #include<iostream>
  2. #include<windows.h>
  3. #include<stdio.h>
  4. #include<conio.h>
  5. #include<fstream>
  6. #include<stdlib.h>
  7. #include<stdio.h>
  8. using namespace std;
  9.  
  10. class productossolicitados
  11. {
  12. private:
  13. struct prosol
  14. {
  15. int CodigoProSol;
  16. int CantidadProSol;
  17. char NombreProSol[100];
  18. char NombresProSol[100];
  19. }datProSol[100];
  20.  
  21. bool encontradoprosol;
  22. int num_ProSol, iProSol;
  23. FILE*prosol;
  24. FILE*faux;
  25.  
  26. public:
  27. void menu_gen();
  28. void menu_prosol();
  29. void ingresarprosol();
  30. void mostrarprosol();
  31. void actualizarprosol();
  32. void eliminarprosol();
  33.  
  34. }ob_es;
  35. int main(){
  36.  
  37. system("color b");
  38. ob_es.menu_gen();
  39. return 0;
  40. }
  41.  
  42. void productossolicitados::menu_gen()
  43. {
  44. int opcion3;
  45. system("cls");
  46. do{
  47. cout<<"\n\n"<<"\t\t\t\t\t\t"<<"MENU GENERAL"<<"\n"<<endl;
  48. cout<<"\t\t\t\t"<<"1 = Productos Solicitados"<<endl;
  49. //cout<<"2 = Productos recien ingresados a empresa"<<endl;
  50. //cout<<"3 = Productos vendidos"<<endl;
  51. //cout<<"4 = Productos solicitados por clientes"<<endl;
  52. cout<<"\t\t\t\t"<<"2 = Salir"<<endl;
  53. cout<<"\t\t\t\t"<<"Indique el numero de la opcion que desea: ";
  54. cin>>opcion3;
  55. switch(opcion3)
  56. {
  57. case 1:
  58. ob_es.menu_prosol();
  59. break;
  60. }
  61. }while(opcion3 !=2);
  62. }
  63.  
  64. void productossolicitados::menu_prosol()
  65. {
  66. int opcion;
  67. system("cls");
  68. do{
  69. cout<<"\n\n"<<"\t\t\t\t\t\t"<<"MENU PRODUCTOS SOLICITADOS"<<"\n"<<endl;
  70. cout<<"\t\t\t\t"<<"1 = Ingreso de Producto(s) Solicitado(s)"<<endl;
  71. cout<<"\t\t\t\t"<<"2 = Mostrar Producto(s) Solicitado(s)"<<endl;
  72. cout<<"\t\t\t\t"<<"3 = Modificar Producto(s) Solicitado (s)"<<endl;
  73. cout<<"\t\t\t\t"<<"4 = Eliminar Producto(s) Solicitado(s)"<<endl;
  74. cout<<"\t\t\t\t"<<"5 = Ir al Menu Principal"<<endl;
  75. cout<<"\t\t\t\t"<<"Indique el numero de la opcion que desea: ";
  76. cin>>opcion;
  77. switch(opcion)
  78. {
  79. case 1:
  80. ob_es.ingresarprosol();
  81. break;
  82. case 2:
  83. ob_es.mostrarprosol();
  84. break;
  85. case 3:
  86. ob_es.actualizarprosol();
  87. break;
  88. case 4:
  89. ob_es.eliminarprosol();
  90. break;
  91. case 5:
  92. ob_es.menu_gen();
  93. break;
  94. }
  95. }while( opcion !=5);
  96. }
  97.  
  98. void productossolicitados::ingresarprosol()
  99. {
  100.  
  101. ofstream fprosol;
  102. fprosol.open("C:/P/fprosol.txt",ios::out|ios::app);
  103. system("cls");
  104. cout<<"INGRESO DE DATOS: ";
  105. if(fprosol.is_open())
  106. {
  107. system("cls");
  108. cout<<"Ingresar Codigo de Producto Solicitado: "<<endl;
  109. cin>>datProSol[iProSol].CodigoProSol;
  110. cout<<"Ingresar Nombre de Producto Solicitado: "<<endl;
  111. cin>>datProSol[iProSol].NombreProSol;
  112. cout<<"Ingresar Nombre de Solicitante "<<endl;
  113. cin>>datProSol[iProSol].NombresProSol;
  114. cout<<"Ingresar Cantidad de Producto Solicitado "<<endl;
  115. cin>>datProSol[iProSol].CantidadProSol;
  116. cout<<"________________________________________"<<endl;
  117. fprosol<<datProSol[iProSol].CodigoProSol<<"\n"<<datProSol[iProSol].NombreProSol<<"\n"<<datProSol[iProSol].NombresProSol<<"\n"<<datProSol[iProSol].CantidadProSol<<"\n\n"<<endl;
  118. }
  119. else
  120. {
  121. system("cls");
  122. cout<<"No se ha podido crear el archivo"<<endl;
  123. getch();
  124. }
  125.  
  126. fprosol.close();
  127. getch();
  128. }
  129.  
  130. void productossolicitados::mostrarprosol()
  131. {
  132. int opcion2;
  133. system("cls");
  134. ifstream fprosol;
  135. fprosol.open("C:/P/fprosol.txt");
  136. if(fprosol.is_open())
  137. {
  138. fprosol>>datProSol[iProSol].CodigoProSol;
  139. for(iProSol=0; iProSol<25;iProSol++)
  140.  
  141. {
  142. while(!fprosol.eof())
  143. {
  144. fprosol>>datProSol[iProSol].NombreProSol>>datProSol[iProSol].NombresProSol>>datProSol[iProSol].CantidadProSol;
  145. system("cls");
  146. cout<<"\t\t\t\t"<<"____________________________________________________"<<endl;
  147. cout<<"\t\t\t\t"<<"Codigo de Producto Solicitado: "<<datProSol[iProSol].CodigoProSol<<"\n"<<endl;
  148. cout<<"\t\t\t\t"<<"Nombre de Producto Solicitado: "<<datProSol[iProSol].NombreProSol<<"\n"<<endl;
  149. cout<<"\t\t\t\t"<<"Nombre de Solicitante: "<<datProSol[iProSol].NombresProSol<<"\n"<<endl;
  150. cout<<"\t\t\t\t"<<"Cantidad de Producto Solicitado "<<datProSol[iProSol].CantidadProSol<<"\n"<<endl;
  151. cout<<"\t\t\t\t"<<"____________________________________________________"<<endl;
  152. fprosol>>datProSol[iProSol].CodigoProSol;
  153. getch();
  154. }
  155. }
  156.  
  157. }
  158. else
  159. {
  160. system("cls");
  161. cout<<"ERROR! No se ha podido abrir el archivo o no se encontraron registros!";
  162. getch();
  163. }
  164. fprosol.close();
  165. getch();
  166. }
  167.  
  168. void productossolicitados::actualizarprosol()
  169. {
  170. ofstream faux;
  171. ifstream fprosol;
  172. int codprosol_aux, cantidadprosol_aux;
  173. encontradoprosol=false;
  174. char nombprosol_aux,nombrsprosol_aux;
  175. faux.open("C:/P/fprosol_auxiliar.txt",ios::in);
  176. fprosol.open("C:/P/fprosol.txt");
  177. if(faux.is_open() && fprosol.is_open())
  178. {
  179. cout<<"Ingresar codigo de Producto Solicitado que desea actualizar: "<<endl;
  180. cin>>codprosol_aux;
  181. fprosol>>codprosol_aux;
  182. fprosol>>datProSol[iProSol].CodigoProSol;
  183. while(!fprosol.eof())
  184. {
  185. fprosol>>datProSol[iProSol].NombreProSol>>datProSol[iProSol].NombresProSol>>datProSol[iProSol].CantidadProSol;
  186. if(codprosol_aux==datProSol[iProSol].CodigoProSol)
  187. {
  188. encontradoprosol=true;
  189. cout<<"Codigo de Producto Solicitado: "<<datProSol[iProSol].CodigoProSol<<"\n"<<endl;
  190. cout<<"Nombre de Producto Solicitado: "<<datProSol[iProSol].NombreProSol<<"\n"<<endl;
  191. cout<<"Nombre Solicitante: "<<datProSol[iProSol].NombresProSol<<"\n"<<endl;
  192. cout<<"Cantidad de Producto Solicitado: "<<datProSol[iProSol].CantidadProSol<<"\n"<<endl;
  193. cout<<"________________________________________"<<endl;
  194. cout<<"Ingresar nuevo Nombre de Producto Solicitado: "<<endl;
  195. cin>>nombprosol_aux;
  196. cout<<"Ingresar nuevo Nombre de Solicitante: "<<endl;
  197. cin>>nombrsprosol_aux;
  198. cout<<"Ingresar nueva Cantidad de Producto: "<<endl;
  199. cin>>cantidadprosol_aux;
  200. getch();
  201. faux<<datProSol[iProSol].CodigoProSol<<"\n"<<nombprosol_aux<<"\n"<<nombrsprosol_aux<<"\n"<<cantidadprosol_aux<<"\n"<<endl;
  202. cout<<"Se ha completado la actualizacion de los datos con exito!"<<endl;
  203. }
  204. else{
  205. faux<<datProSol[iProSol].CodigoProSol<<" "<<datProSol[iProSol].NombreProSol<<" "<<datProSol[iProSol].NombresProSol<<" "<<datProSol[iProSol].CantidadProSol<<" "<<endl;
  206. }
  207.  
  208. }
  209. }
  210.  
  211. fprosol.close();
  212. faux.close();
  213. remove("C:/P/fprosol.txt");
  214. rename("C:/P/fprosol_auxiliar.txt","C:/P/fprosol.txt");
  215.  
  216. }
  217. void productossolicitados::eliminarprosol()
  218. {
  219. ifstream fprosol;
  220. ofstream faux;
  221. int codprosol_aux2;
  222.  
  223. fprosol.open("C:/P/fprosol.txt",ios::in);
  224. faux.open("C:/P/fprosol_auxiliar.txt",ios::out);
  225. if(faux.is_open() && fprosol.is_open())
  226. {
  227. cout<<"______________________________________________________"<<endl;
  228. cout<<"Ingresar codigo de Producto Solicitado que desea eliminar: "<<endl;
  229. cin>>codprosol_aux2;
  230.  
  231. fprosol>>datProSol[iProSol].CodigoProSol;
  232. while(!fprosol.eof())
  233. {
  234. fprosol>>datProSol[iProSol].NombreProSol>>datProSol[iProSol].NombresProSol>>datProSol[iProSol].CantidadProSol;
  235. if(codprosol_aux2==datProSol[iProSol].CodigoProSol)
  236. {
  237.  
  238. cout<<"Se ha completado la eliminacion de los datos con exito!"<<endl;
  239. }
  240. else{
  241. faux<<datProSol[iProSol].CodigoProSol<<"\n"<<datProSol[iProSol].NombreProSol<<"\n"<<datProSol[iProSol].NombresProSol<<"\n"<<datProSol[iProSol].CantidadProSol<<"\n"<<endl;
  242. }
  243. }
  244. }
  245. fprosol.close();
  246. faux.close();
  247. remove("C:/P/fprosol.txt");
  248. rename("C:/P/fprosol_auxiliar.txt","C:/P/fprosol.txt");
  249. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement