Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Grupo 21
Challenge 2
Código de fuente
1. #include <iostream>
2. #include <string>
3. #include <array>
4.
5. using namespace std;
6.
7. int printBillNum(int m, int bill) {
8. int n = m / bill;
9. if (n > 0) {
10. cout << " " << n << " " << bill << endl;
11. }
12.
13. return m % bill;
14. }
15.
16. int find(array<string, 5> users, string user) {
17. int res = -1;
18.
19. for (int i = 0; i < users.size(); i++) {
20. if (users[i] == user) {
21. res = i;
22. break;
23. }
24. }
25.
26. return res;
27. }
28.
29. int main()
30. {
31. int opt, opt2, m, user = -1;
32. bool exit = false;
33. array<string, 5> users = { "santiago", "usuario2", "usuario3", "usuario4",
"usuario5" };
34. array<string, 5> pass = { "1234", "2345", "3456", "4567", "5678" };
35. array<array<int, 5>, 2> acc = { 27500000, 2658000, 56840000, 8050000,
1536000, 35000000, 3817000, 48700000, 10295000, 986000 };
36. array<int, 5> reg = { 27500000, 2658000, 56840000, 8050000, 1536000 };
37. array<int, 5> aho = { 35000000, 3817000, 48700000, 10295000, 986000 };
38. array<int, 5> cred = { 0, 0, 0, 0, 0 };
39. array<bool, 5> lend = { true, true, true, true, true };
40.
41.
42. while (!exit) {
43. while (user < 0 || user > users.size()) {
44. system("color e0");
45. cout << (
46. "
###################################################################
###########\n"
47. "# #\n"
48. "# || CAJERO AUTOMATICO || #\n"
49. "# #\n"
50. "# Gracias por usar este servicio #\n"
51. "# #\n"
52. "# Porfavor ingrese su usuario y contrasena #\n"
53. "# #\n"
54. "
###################################################################
###########\n"
55. "\n"
56. " Usuario: "
57. );
58.
59. string userName; cin >> userName;
60. user = find(users, userName);
61.
62. if (user < 0) {
63. cout << "\n Usuario no encontrado\n" << endl;
64. }
65. else {
66. cout << " Contrasena: ";
67. string passTxt; cin >> passTxt;
68.
69. if (pass[user] != passTxt) {
70. cout << "\n Contrasena incorrecta\n" << endl;
71. user = -1;
72. }
73. else {
74. cout << "\n Usuario autenticado\n" << endl;
75. }
76. }
77. system("pause");
78. system("cls");
79. }
80.
81. system("color 0f");
82. cout << (
83. "
###################################################################
###########\n"
84. "# #\n"
85. "# || CAJERO AUTOMATICO || #\n"
86. "# #\n"
87. "# ( 1. ) Consultar Saldo #\n"
88. "# ( 2. ) Consignar #\n"
89. "# ( 3. ) Retirar #\n"
90. "# ( 4. ) Tarjeta de credito #\n"
91. "# ( 5. ) Cerrar sesion #\n"
92. "# ( 6. ) salir #\n"
93. "# #\n"
94. "
###################################################################
###########\n"
95.
96. ) << endl;
97. cout << " Opcion: ";
98. cin >> opt;
99. cout << "\n";
100.
101. switch (opt)
102. {
103. case 1:
104. system("color b0");
105. cout << " Saldo corriente: " << acc[0][user] << endl;
106. cout << " Saldo ahorros: " << acc[1][user] << endl;
107. break;
108.
109. case 2:
110. system("color a0");
111. cout << (
112. " Seleccione cuenta\n"
113. "\n"
114. " ( 1. ) Corriente\n"
115. " ( 2. ) Ahorros\n"
116. "\n"
117. " Cuenta: "
118. );
119. cin >> opt;
120. if (opt < 1 || opt > 2) {
121. cout << "\n Transaccion invalida, debe seleccionar una cuenta
valida\n" << endl;
122. break;
123. }
124.
125. cout << (
126. "\n Cuanto desea consignar?\n"
127. " Monto: "
128. );
129. cin >> m;
130. opt--;
131. if (m % 1000 == 0 && m >= 0) {
132. acc[opt][user] += m;
133. lend[user] = acc[0][user] > 0;
134. }
135. else {
136. cout << "\n Transaccion invalida, el monto debe ser repartible
entre billetes de minimo 1000$ o 0\n" << endl;
137. }
138.
139. cout << "\n Saldo: " << acc[opt][user] << endl;
140. break;
141.
142. case 3:
143. system("color c0");
144. cout << (
145. " Seleccione cuenta\n"
146. "\n"
147. " ( 1. ) Corriente\n"
148. " ( 2. ) Ahorros\n"
149. "\n"
150. " Cuenta: "
151. );
152. cin >> opt;
153. if (opt < 1 || opt > 2) {
154. cout << "\n Transaccion invalida, debe seleccionar una cuenta
valida\n" << endl;
155. }
156. else {
157. cout << (
158. "\n Cuanto desea retirar?\n"
159. " Monto: "
160. );
161. cin >> m;
162. bool valid = true;
163. opt--;
164. if (opt == 1) {
165. valid = (lend[user] && m >= 0);
166. }
167. else {
168. valid = (m <= acc[0][user] && m >= 0);
169. }
170.
171. if (m % 1000 == 0 && valid) {
172.
173. acc[opt][user] -= m;
174. lend[user] = acc[0][user] > 0;
175.
176. cout << "\n Cantidad Valor billete" << endl;
177. m = printBillNum(m, 100000);
178. m = printBillNum(m, 50000);
179. m = printBillNum(m, 20000);
180. m = printBillNum(m, 10000);
181. m = printBillNum(m, 5000);
182. m = printBillNum(m, 2000);
183. m = printBillNum(m, 1000);
184. cout << endl;
185.
186. }
187. else {
188. cout << "\n Transaccion invalida el monto no debe ser mayor al
saldo y repartible entre billetes de minimo 1000$ o 0\n" << endl;
189. }
190.
191. cout << "\n Saldo: " << acc[opt][user] << endl;
192. }
193. break;
194. case 4:
195. system("color d0");
196. cout << " Tiene una deuda de: " << cred[user]
197. << (
198. "\n"
199. "\n"
200. " Que desea realizar?\n"
201. "\n"
202. " ( 1. ) Pagar deuda\n"
203. " ( 2. ) Pedir prestamo\n"
204. "\n"
205. " Opcion: "
206. );
207.
208. cin >> opt2;
209. cout << "\n";
210. if (opt2 < 1 || opt2 > 2) {
211. cout << "\n Transaccion invalida, debe seleccionar una cuenta
valida\n" << endl;
212. break;
213. }
214.
215. if (opt2 == 1) {
216. cout << (
217. " Seleccione cuenta\n"
218. "\n"
219. " ( 1. ) Corriente\n"
220. " ( 2. ) Ahorros\n"
221. "\n"
222. " Cuenta: "
223. );
224. cin >> opt;
225. if (opt < 1 || opt > 2) {
226. cout << "\n Transaccion invalida, debe seleccionar una cuenta
valida\n" << endl;
227. break;
228. }
229.
230. opt--;
231. cout << (
232. "\n Ingrese el monto\n"
233. " Monto: "
234. );
235. cin >> m;
236.
237. if (m < acc[opt][user] && m < 0) {
238. cout << "\n Transaccion invalida el monto debe ser mayor al
saldo y repartible entre billetes de minimo 1000$ o 0" << endl;
239. break;
240. }
241.
242. cred[user] -= m;
243. acc[opt][user] -= m;
244.
245.
246. cout << "\n Deuda: " << cred[user] << "\n"
247. " Saldo: " << acc[opt][user] << "\n" << endl;
248. }
249. else {
250. cout << (
251. "\n Ingrese el monto\n"
252. " Monto: "
253. );
254. cin >> m;
255.
256. if (m < 0) {
257. cout << "\n Transaccion invalida el monto no debe ser repartible
entre billetes de minimo 1000$ o 0" << endl;
258. break;
259. }
260. cred[user] += m;
261. }
262.
263.
264. break;
265. case 5:
266.
267. user = -1;
268. break;
269. case 6:
270.
271. exit = true;
272. break;
273. default:
274.
275. cout << "\n opcion invalida\n" << endl;
276. }
277. cout << "\n" << endl;
278.
279. system("pause");
280. system("cls");
281. }
282. }
Escenarios posibles
1. Usuario
4. Consultar saldo
5. Tipo de cuenta (extra challenge), consignar
8. Caso invalido