Advertisement
Guest User

Untitled

a guest
Jan 10th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | None | 0 0
  1. #ifndef PERSO_H
  2. #define PERSO_H
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7. // Atributos
  8. class perso {
  9. private:
  10. string nombre, apellido, telefono;
  11. public:
  12. string cedula;
  13. void regis_perso (string nom, string ape, string ced, string tel); //Registra los datos de la clase.
  14. };
  15. #endif /* PERSO_H */
  16.  
  17. #include "perso.h"
  18.  
  19. using namespace std;
  20.  
  21. void perso::regis_perso(string nom, string ape, string ced, string tel)
  22. {
  23. nombre = nom;
  24. apellido = ape;
  25. cedula = ced;
  26. telefono = tel;
  27. }
  28.  
  29. #ifndef USER_H
  30. #define USER_H
  31. #include <iostream>
  32. #include <string>
  33. #include "perso.h"
  34.  
  35. using namespace std;
  36. //Atributos
  37. class user: public perso{
  38. public:
  39. string iduser;
  40. void regis_user (string nom, string ape, string ced, string tel, string idu, string fec, string pas, string sex); //Registra los datos de la clase.
  41. private:
  42. string fechana, pass, sexo;
  43. };
  44.  
  45. #endif /* USER_H */
  46.  
  47. #include "user.h"
  48.  
  49. void user::regis_user (string nom, string ape, string ced, string tel, string idu, string fec, string pas, string sex)
  50. {
  51. regis_perso (nom, ced, ape, tel);
  52. iduser = idu;
  53. fechana = fec;
  54. pass = pas;
  55. sexo = sex;
  56. }
  57.  
  58. //Clase arreglo de objeto (de user).
  59. #ifndef USERS_H
  60. #define USERS_H
  61. #include <iostream>
  62. #include <fstream>
  63. #include <string>
  64. #include "user.h"
  65. #include "modulos.h"
  66. //Atributos de la clase.
  67. using namespace std;
  68.  
  69. class users {
  70. public:
  71. bool exis_user (string ced, string idu); //Función que verifica si existe un usuario (verdadero si falso no).
  72. int pos_vacia_users (); //Función que devuelve la posición vació del arreglo "usuarios".
  73. int pos_user (string ced, string idu); //Función que devuelve la posición del "usuario".
  74. void insta_users (); //Inicializa cada posición del arreglo "usuarios".
  75. void regis_users (); //Modulo que registra los datos de los usuario.
  76. user usuarios [10];
  77. };
  78.  
  79. #endif /* USERS_H */
  80.  
  81. #include "users.h"
  82.  
  83. bool users::exis_user (string ced, string idu)
  84. {
  85. bool enc;
  86. enc = false;
  87. for (int i = 0; i <= 9; i++)
  88. {
  89. if ((usuarios[i].cedula == ced) and (usuarios[i].iduser == idu))
  90. {
  91. enc = true;
  92. }
  93. }
  94. return (enc);
  95. }
  96. void users::insta_users ()
  97. {
  98. for (int i = 0; i <= 9; i++)
  99. {
  100. usuarios[i].inici_user ();
  101. }
  102. }
  103. int users::pos_vacia_users ()
  104. {
  105. int pos, i;
  106. i = 0;
  107. pos = 2016;
  108. while ((pos == 2016) and (i <= 9))
  109. {
  110. if ((usuarios[i].cedula == "VACIO") and (usuarios[i].iduser == "VACIO"))
  111. {
  112. pos = i;
  113. }
  114. i = i + 1;
  115. }
  116. return (pos);
  117. }
  118. int users::pos_user (string ced, string idu)
  119. {
  120. int pos, i;
  121. i = 0;
  122. pos = 2016;
  123. while ((pos == 2016) and (i <= 9))
  124. {
  125. if ((usuarios[i].cedula == ced) and (usuarios[i].iduser == idu))
  126. {
  127. pos = i;
  128. }
  129. i = i + 1;
  130. }
  131. return (pos);
  132. }
  133. void users::regis_users ()
  134. {
  135. string nombre, apellido, cedula, telefono, fechana, pass, sexo, iduser;
  136. ofstream escriuser;
  137. escriuser.open ("usuarios.txt", ios::out | ios::app);
  138. bool aux;
  139. int pos, resp;
  140. resp = 0;
  141. aux = false;
  142. resp = 0;
  143. if (escriuser.is_open())
  144. {
  145. while (resp == 0)
  146. {
  147. nombre = "";
  148. apellido = "";
  149. cedula = "";
  150. telefono = "";
  151. fechana = "";
  152. pass = "";
  153. sexo = "";
  154. iduser = "";
  155. pos = 0;
  156. pos = pos_vacia_users ();
  157. if (pos == 2016)
  158. {
  159. cout << "No se pueden registrar mas usuarios (registro lleno)." << endl;
  160. press_key ();
  161. resp = 1;
  162. }
  163. else
  164. {
  165. cout << "REGISTRO DE USUARIO NRO: " <<pos<< endl;
  166. cout << "Introduzca los siguientes datos:" << endl;
  167. cout << "Cedula:" << endl; //Se pueden verificar los datos independientemente
  168. cin >> cedula;
  169. cout << "Nombre de usuario (ID user):" << endl;
  170. cin >> iduser;
  171. aux = exis_user(cedula, iduser);
  172. while (aux == true)
  173. {
  174. cedula = "";
  175. iduser = "";
  176. cout << "Error!!! Los datos introducidos pertenecen a un usuario ya existente." << endl;
  177. press_key ();
  178. cout << "Intentelo nuevamente..." << endl;
  179. cout << "Cedula:" << endl;
  180. cin >> cedula;
  181. cout << "Nombre de usuario:" << endl;
  182. cin >> iduser;
  183. aux = exis_user(cedula, iduser);
  184. }
  185. cout << "Nombre:" << endl;
  186. cin >> nombre;
  187. cout << "Apellido:" << endl;
  188. cin >> apellido;
  189. cout << "Telefono:" << endl;
  190. cin >> telefono;
  191. cout << "Fecha de nacimiento:" << endl;
  192. cin >> fechana;
  193. cout << "Contrase;a:" << endl;
  194. cin >> pass;
  195. cout << "Sexo:" << endl;
  196. cin >> sexo;
  197. usuarios[pos].regis_user(nombre, apellido, cedula, telefono, iduser, fechana, pass, sexo);
  198. escriuser<<nombre<<" "<<apellido<<" "<<cedula<<" "<<telefono<<" "<<iduser<<" "<<fechana<<" "<<pass<<" "<<sexo<<endl;
  199. cout << "¿Desea registrar otro usuario?" << endl;
  200. cout << "(0./ SI, 1./NO)" << endl;
  201. cin >> resp;
  202. while ((resp != 1) and (resp != 2))
  203. {
  204. cout << "Error!!! Respuesta invalida." << endl;
  205. press_key ();
  206. cout << "Intentelo nuevamente." << endl;
  207. cin >> resp;
  208. }
  209. }
  210. }
  211. }
  212. else
  213. {
  214. cout << "Error!!! el archivo no pudo ser abierto." << endl;
  215. }
  216. escriuser.close ();
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement