Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.58 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <conio.h>
  5. #include <time.h>
  6. using namespace std;
  7.  
  8. struct USER
  9. {
  10. char name[13];
  11. char passwd[11];
  12. double cash;
  13. int login_count;
  14. int sim_datei;
  15. int hold[5];
  16. };
  17.  
  18. struct STOCK
  19. {
  20. char name[10];
  21. int count;
  22. int *date;
  23. double *open, *high, *low, *close, *adj;
  24. int *vol;
  25. };
  26.  
  27. STOCK read_stock(char name[])
  28. {
  29. STOCK s;
  30. strcpy_s(s.name, name);
  31. char filename[20];
  32. strcpy_s(filename, name);
  33. strcat_s(filename, ".csv");
  34. ifstream fin;
  35. fin.open(filename);
  36. s.count = 0;
  37. char temp[1000];
  38. while (!fin.eof())
  39. {
  40. fin.getline(temp, 1000);
  41. s.count++;
  42. }
  43. fin.close();
  44. s.date = new int[s.count];
  45. s.open = new double[s.count];
  46. s.high = new double[s.count];
  47. s.low = new double[s.count];
  48. s.close = new double[s.count];
  49. s.adj = new double[s.count];
  50. s.vol = new int[s.count];
  51. int i;
  52. char tmp;
  53. fin.open(filename);
  54. for (i = 0; i < s.count; i++)
  55. {
  56. fin >> s.date[i];
  57. fin >> tmp;
  58. fin >> s.open[i];
  59. fin >> tmp;
  60. fin >> s.high[i];
  61. fin >> tmp;
  62. fin >> s.low[i];
  63. fin >> tmp;
  64. fin >> s.close[i];
  65. fin >> tmp;
  66. fin >> s.adj[i];
  67. fin >> tmp;
  68. fin >> s.vol[i];
  69. }
  70. fin.close();
  71. return s;
  72. }
  73.  
  74. void delete_stock(STOCK s)
  75. {
  76. delete[] s.vol;
  77. delete[] s.adj;
  78. delete[] s.close;
  79. delete[] s.low;
  80. delete[] s.high;
  81. delete[] s.open;
  82. delete[] s.date;
  83. }
  84.  
  85. void inputName(char name[],int j)
  86. {
  87. char x;
  88. int c = 0, i;
  89. do {
  90. system("cls");
  91. if(j==1)
  92. cout << "Username: ";
  93. else if (j == 0)
  94. cout << "Password: ";
  95. if (j == 1)
  96. {
  97. for (i = 0; i < c; i++)
  98. cout << name[i];
  99. }
  100. else if (j==0)
  101. {
  102. for (i = 0; i < c; i++)
  103. cout << "*";
  104. }
  105. x = _getwch();
  106. if (isalnum(x))
  107. {
  108. if (c == 12 && j == 1)
  109. c--;
  110.  
  111. else if (c == 10 && j == 0)
  112. c--;
  113. name[c] = x;
  114. c++;
  115. }
  116. if (x == 8 && c > 0)//8是後退
  117. c--;
  118. } while (x != 13 || c == 0);
  119. name[c] = '\0';
  120. }
  121.  
  122.  
  123. USER login()
  124. {
  125. char name1[13];
  126. char passwd1[11];
  127. USER userlist[1000];
  128. int userno, i, j;
  129. ifstream fin;
  130. fin.open("userlist.txt");
  131. fin >> userno;
  132. for (i = 0; i < userno; i++)
  133. {
  134. fin >> userlist[i].name;
  135. fin >> userlist[i].passwd;
  136. fin >> userlist[i].cash;
  137. fin >> userlist[i].login_count;
  138. fin >> userlist[i].sim_datei;
  139. for (j = 0; j < 5; j++)
  140. fin >> userlist[i].hold[j];
  141. }
  142. fin.close();
  143. do {
  144. system("cls");
  145. inputName(name1, 1);
  146. inputName(passwd1, 0);
  147. for (i = 0; i < userno; i++)
  148. {
  149. if (strcmp(userlist[i].name, name1) == 0)
  150. {
  151. if (strcmp(userlist[i].passwd, passwd1) == 0)
  152. {
  153. userlist[i].login_count++;
  154. return userlist[i];
  155. }
  156. else
  157. {
  158. cout << "Incorrect password!!!!!!" << endl;
  159. cout << "Press any key" << endl;
  160. _getwch();
  161. break;
  162. }
  163. }
  164. }
  165. if (i == userno)
  166. {
  167. char passwd2[11];
  168. cout << "Confirm your password: ";
  169. cin >> passwd2;
  170. if (strcmp(passwd1, passwd2) == 0)
  171. {
  172. strcpy_s(userlist[userno].name, name1);
  173. strcpy_s(userlist[userno].passwd, passwd1);
  174. userlist[userno].login_count = 1;
  175. userlist[userno].cash = 10000;
  176. userlist[userno].sim_datei = 2;
  177. userlist[userno].hold[0] = 0;
  178. userlist[userno].hold[1] = 0;
  179. userlist[userno].hold[2] = 0;
  180. userlist[userno].hold[3] = 0;
  181. userlist[userno].hold[4] = 0;
  182. ofstream fout;
  183. fout.open("userlist.txt");
  184. fout << userno + 1 << endl;
  185. for (j = 0; j <= userno; j++)
  186. {
  187. fout << userlist[j].name << endl;
  188. fout << userlist[j].passwd << endl;
  189. fout << userlist[j].cash << endl;
  190. fout << userlist[j].login_count << endl;
  191. fout << userlist[j].sim_datei << endl;
  192. fout << userlist[j].hold[0] << " " << userlist[j].hold[1] << " " << userlist[j].hold[2] << " " << userlist[j].hold[3] << " " << userlist[j].hold[4] << endl;
  193. }
  194. fout.close();
  195. return userlist[userno];
  196. }
  197. }
  198. } while (true);
  199. }
  200.  
  201. void mainUI(int select, USER one, STOCK s[])
  202. {
  203. char left[7];
  204. char right[7];
  205. int i;
  206. for (i = 0; i < 7; i++)
  207. {
  208. left[i] = ' ';
  209. right[i] = ' ';
  210. }
  211. left[select] = '[';
  212. right[select] = ']';
  213. system("cls");
  214. cout << endl << endl << endl;
  215. cout << " ╔ ═ ╗ ╔ ╗ ╔ ╗ ╔ ═ ═ ═ ╗" << endl;
  216. cout << " ║ █ ║ ╔ ◢◣ ◢◣ ╗ ║ ███ ║" << endl;
  217. cout << " ║ █ ║ ║ █ ◥◤ █ ║ ║ █ ═ ╣" << endl;
  218. cout << " ║ █ ║ ║ █ ╔ ╗ █ ║ ║ ███ ║" << endl;
  219. cout << " ║ █ ║ ║ █ ║ ║ █ ║ ║ █╔ ═ ╝" << endl;
  220. cout << " ╚ ═ ╝ ╚ ═ ╝ ╚ ═ ╝ ╚ ═ ╝" << endl << endl << endl << endl;
  221. cout << " " << one.name << " 您好,今日日期為 " << s[0].date[one.sim_datei] << endl;
  222. cout << " 你目前現金有 " << one.cash << " 元,總資產為 " << one.cash + s[0].close[one.sim_datei] * one.hold[0] + s[1].close[one.sim_datei] * one.hold[1] + s[2].close[one.sim_datei] * one.hold[2] + s[3].close[one.sim_datei] * one.hold[3] + s[4].close[one.sim_datei] * one.hold[4] << " 元" << endl;
  223. cout << "=============================================================================" << endl;
  224. cout << " " << left[1] << "1" << right[1] << " 投資決策" << endl;
  225. cout << " " << left[2] << "2" << right[2] << " 數獨遊戲" << endl;
  226. cout << " " << left[3] << "3" << right[3] << " 寂寞聊天室" << endl;
  227. cout << " " << left[4] << "4" << right[4] << " 猜數字" << endl;
  228. cout << " " << left[5] << "5" << right[5] << " 富爸爸" << endl;
  229. cout << " " << left[6] << "6" << right[6] << " 變更密碼" << endl;
  230. cout << " " << left[0] << "0" << right[0] << " 離開系統" << endl;
  231. cout << "=============================================================================" << endl << endl;
  232. }
  233.  
  234. void print(int M[9][9])
  235. {
  236. int r, c;
  237. for (r = 0; r < 9; r++)
  238. {
  239. for (c = 0; c < 9; c++)
  240. {
  241. if (M[r][c] > 0)
  242. cout << M[r][c] << " ";
  243. else
  244. cout << " ";
  245. }
  246. cout << endl;
  247. }
  248. }
  249.  
  250. void updateZ(int Z[9][9][10], int r, int c, int num)
  251. {
  252. int x, y;
  253. for (x = 0; x < 9; x++)
  254. Z[r][x][num] = 0;
  255. for (y = 0; y < 9; y++)
  256. Z[y][c][num] = 0;
  257. for (y = r / 3 * 3; y <= r / 3 * 3 + 2; y++)
  258. {
  259. for (x = c / 3 * 3; x <= c / 3 * 3 + 2; x++)
  260. {
  261. Z[y][x][num] = 0;
  262. }
  263. }
  264. Z[r][c][num] = 1;
  265. }
  266.  
  267. int findZ(int Z[9][9][10], int r, int c)
  268. {
  269. int i, count, num;
  270. count = 0;
  271. for (i = 1; i <= 9; i++)
  272. {
  273. if (Z[r][c][i] == 1)
  274. {
  275. count++;
  276. num = i;
  277. }
  278. }
  279. if (count == 1)
  280. return num;
  281. else
  282. return 0;
  283. }
  284.  
  285. void solve(int Q[9][9], int A[9][9])
  286. {
  287. int Z[9][9][10];
  288. int r, c, i;
  289. for (r = 0; r < 9; r++)
  290. {
  291. for (c = 0; c < 9; c++)
  292. {
  293. if (Q[r][c] > 0)
  294. {
  295. A[r][c] = Q[r][c];
  296. for (i = 1; i <= 9; i++)
  297. Z[r][c][i] = 0;
  298. Z[r][c][Q[r][c]] = 1;
  299. }
  300. else
  301. {
  302. A[r][c] = 0;
  303. for (i = 1; i <= 9; i++)
  304. Z[r][c][i] = 1;
  305. }
  306. }
  307. }
  308. for (r = 0; r < 9; r++)
  309. {
  310. for (c = 0; c < 9; c++)
  311. {
  312. if (Q[r][c] > 0)
  313. {
  314. updateZ(Z, r, c, Q[r][c]);
  315. }
  316. }
  317. }
  318. int flag = 1, num;
  319. while (flag == 1)
  320. {
  321. flag = 0;
  322. for (r = 0; r < 9; r++)
  323. {
  324. for (c = 0; c < 9; c++)
  325. {
  326. if (A[r][c] == 0)
  327. {
  328. num = findZ(Z, r, c);
  329. if (num > 0)
  330. {
  331. flag = 1;
  332. A[r][c] = num;
  333. updateZ(Z, r, c, num);
  334. }
  335. }
  336. }
  337. }
  338. }
  339. }
  340. void printUI(int M[9][9], int r, int c)
  341. {
  342. int i, j;
  343. char L[9][9];
  344. char R[9][9];
  345. for (i = 0; i < 9; i++)
  346. {
  347. for (j = 0; j < 9; j++)
  348. {
  349. L[i][j] = ' ';
  350. R[i][j] = ' ';
  351. L[r][c] = '[';
  352. R[r][c] = ']';
  353. if (M[i][j] > 0)
  354. cout << L[i][j] << M[i][j] << R[i][j];
  355. else
  356. cout << L[i][j] << " " << R[i][j];
  357.  
  358. }
  359. cout << endl;
  360. }
  361. }
  362.  
  363. bool compare(int M[9][9], int M1[9][9])
  364. {
  365. int r, c, count = 0;
  366. for (r = 0; r < 9; r++)
  367. {
  368. for (c = 0; c < 9; c++)
  369. {
  370. if (M[r][c] > 0)
  371. {
  372. if (M[r][c] == M1[r][c])
  373. count++;
  374. }
  375.  
  376. }
  377. }
  378. if (count == 81)
  379. return true;
  380. else
  381. return false;
  382. }
  383.  
  384. int Sudoku_main()
  385. {
  386. int Q[9][9], a, b;
  387. srand(time(NULL));
  388. ifstream fin;
  389. char filename[] = "Q1.txt";
  390. filename[1] = '1' + rand() % 3;
  391. fin.open(filename);
  392. for (a = 0; a < 9; a++)
  393. {
  394. for (b = 0; b < 9; b++)
  395. fin >> Q[a][b];
  396. }
  397. fin.close();
  398. int A[9][9], A1[9][9];
  399. int r = 0, c = 0;
  400. char x, y;
  401. int i, j;
  402. for (i = 0; i < 9; i++)
  403. {
  404. for (j = 0; j < 9; j++)
  405. {
  406. A[i][j] = Q[i][j];
  407. }
  408. }
  409.  
  410. do {
  411. system("cls");
  412. printUI(A, r, c);
  413. x = _getch();
  414. if (x >= '0'&&x <= '9')
  415. {
  416. if (Q[r][c] == 0)
  417. A[r][c] = x - '0';
  418. }
  419. if (x == -32)
  420. {
  421. y = _getch();
  422. switch (y)
  423. {
  424. case 72:
  425. r = (r + 8) % 9;
  426. break;
  427. case 75:
  428. c = (c + 8) % 9;
  429. break;
  430. case 77:
  431. c = (c + 10) % 9;
  432.  
  433. break;
  434. case 80:
  435. r = (r + 10) % 9;
  436. break;
  437. }
  438. }
  439. } while (x != 13);
  440. solve(Q, A1);
  441. if (compare(A, A1))
  442. {
  443. cout << "Correct" << endl;
  444. _getwch();
  445. return 1;
  446. }
  447. else
  448. {
  449. cout << "Try again" << endl;
  450. _getwch();
  451. return 0;
  452. }
  453. }
  454.  
  455. void Chat_main(USER one)
  456. {
  457. ifstream fin;
  458. ofstream fout;
  459. char str[1000];
  460. char name[21];
  461. do {
  462. system("cls");
  463. fin.open("msg.txt");
  464. while (!fin.eof())
  465. {
  466. fin.getline(str, 1000);
  467. cout << str << endl;
  468. }
  469. fin.close();
  470. cout << "===================================" << endl;
  471. cin.getline(str, 1000);
  472. if (strcmp(str, "EXIT") != 0 && strlen(str) != 0)
  473. {
  474. fout.open("msg.txt", std::ofstream::app);
  475. fout << one.name << ":" << str << endl;
  476. fout.close();
  477. }
  478. } while (strcmp(str, "EXIT") != 0);
  479. }
  480.  
  481. void split(int n, int A[])
  482. {
  483. A[0] = n / 1000;
  484. n %= 1000;
  485. A[1] = n / 100;
  486. n %= 100;
  487. A[2] = n / 10;
  488. A[3] = n % 10;
  489. }
  490.  
  491. int legal(int A[])
  492. {
  493. int out = 1;
  494. int i, j;
  495. if (A[0] >= 10)
  496. return 0;
  497. for (i = 0; i < 3; i++)
  498. {
  499. for (j = i + 1; j < 4; j++)
  500. {
  501. if (A[i] == A[j])
  502. out = 0;
  503. }
  504. }
  505. return out;
  506. }
  507.  
  508. void generate(int A[])
  509. {
  510. //method 1
  511. A[0] = rand() % 10;
  512. do {
  513. A[1] = rand() % 10;
  514. } while (A[1] == A[0]);
  515. do {
  516. A[2] = rand() % 10;
  517. } while (A[2] == A[0] || A[2] == A[1]);
  518. do {
  519. A[3] = rand() % 10;
  520. } while (A[3] == A[0] || A[3] == A[1] || A[3] == A[2]);
  521. //mtehod 2
  522. int card[10];
  523. int i, j, k, tmp;
  524. for (i = 0; i < 10; i++)
  525. card[i] = i;
  526. for (i = 0; i < 100000; i++)
  527. {
  528. j = rand() % 10;
  529. k = rand() % 10;
  530. tmp = card[j];
  531. card[j] = card[k];
  532. card[k] = tmp;
  533. }
  534. for (i = 0; i < 4; i++)
  535. A[i] = card[i];
  536. //method 3
  537. do {
  538. split(rand() % 10000, A);
  539. } while (legal(A) == 0);
  540. }
  541.  
  542. void input(int G[], int tag)
  543. {
  544. int n;
  545. do {
  546. if (tag == 0)
  547. cout << "Please input your answer:";
  548. else
  549. cout << "Please Guess a number:";
  550.  
  551. cin >> n;
  552. split(n, G);
  553. } while (legal(G) == 0);
  554. }
  555.  
  556. void compare(int G[], int A[], int AB[])
  557. {
  558. int i, j;
  559. AB[0] = 0;
  560. for (i = 0; i < 4; i++)
  561. {
  562. if (G[i] == A[i])
  563. AB[0]++;
  564. }
  565. AB[1] = 0;
  566. for (i = 0; i < 4; i++)
  567. {
  568. for (j = 0; j < 4; j++)
  569. {
  570. if (G[i] == A[j])
  571. AB[1]++;
  572. }
  573. }
  574. AB[1] -= AB[0];
  575. }
  576.  
  577. int XAXB_main()
  578. {
  579. int cA[4], hA[4], cG[4], hG[4], cAB[2], hAB[2], tA[4], tAB[2];
  580. int AP[10000], i;
  581. int count = 0;
  582. srand(time(NULL));
  583. generate(cA);
  584. input(hA, 0); // human input hA
  585. for (i = 0; i < 10000; i++)
  586. {
  587. split(i, tA);
  588. if (legal(tA) == 1)
  589. AP[i] = 1;
  590. else
  591. AP[i] = 0;
  592. }
  593. do
  594. {
  595. input(hG, 1);
  596. compare(hG, cA, hAB); //AB[0]->A AB[1]->B
  597. count++;
  598. cout << "(H)" << count << ":" << hAB[0] << "A" << hAB[1] << "B" << endl;
  599. // computer guess -> cG
  600. for (i = 0; i < 10000; i++)
  601. {
  602. if (AP[i] == 1)
  603. {
  604. split(i, cG);
  605. cout << "computer guess:" << cG[0] << cG[1] << cG[2] << cG[3] << endl;
  606. break;
  607. }
  608. }
  609. compare(cG, hA, cAB);
  610. cout << "(C)" << count << ":" << cAB[0] << "A" << cAB[1] << "B" << endl;
  611. //update AP
  612. for (i = 0; i < 10000; i++)
  613. {
  614. if (AP[i] == 1)
  615. {
  616. split(i, tA);
  617. compare(cG, tA, tAB);
  618. if (tAB[0] != cAB[0] || tAB[1] != cAB[1])
  619. AP[i] = 0;
  620. }
  621. }
  622. } while (hAB[0] != 4 && cAB[0] != 4);
  623. if (hAB[0] == 4 && cAB[0] == 4)
  624. {
  625. cout << "平手" << endl;
  626. _getwch();
  627. return 2;
  628. }
  629. else if (hAB[0] == 4)
  630. {
  631. cout << "電腦輸了" << endl;
  632. _getwch();
  633. return 1;
  634. }
  635. else
  636. {
  637. cout << "電腦贏了" << endl;
  638. _getwch();
  639. return 0;
  640. }
  641. }
  642.  
  643. USER Change_password(USER one)
  644. {
  645. char x, oldname[11], newname[11], confirmname[11];
  646. int c = 0, i;
  647. do {
  648. system("cls");
  649. cout << "Old password: ";
  650. for (i = 0; i < c; i++)
  651. cout << "*";
  652. x = _getwch();
  653. if (isalnum(x))
  654. {
  655. if (c == 10)
  656. c--;
  657. oldname[c] = x;
  658. c++;
  659. }
  660. if (x == 8 && c != 0)
  661. c--;
  662. } while (x != 13 || c == 0);
  663. oldname[c] = '\0';
  664. c = 0;
  665. if (strcmp(one.passwd, oldname) == 0)
  666. {
  667. do {
  668. system("cls");
  669. cout << "New password: ";
  670. for (i = 0; i < c; i++)
  671. cout << "*";
  672. x = _getwch();
  673. if (isalnum(x))
  674. {
  675. if (c == 10)
  676. c--;
  677. newname[c] = x;
  678. c++;
  679. }
  680. if (x == 8 && c != 0)
  681. c--;
  682. } while (x != 13 || c == 0);
  683. newname[c] = '\0';
  684. c = 0;
  685. do {
  686. system("cls");
  687. cout << "Confirm new password: ";
  688. for (i = 0; i < c; i++)
  689. cout << "*";
  690. x = _getwch();
  691. if (isalnum(x))
  692. {
  693. if (c == 10)
  694. c--;
  695. confirmname[c] = x;
  696. c++;
  697. }
  698. if (x == 8 && c != 0)
  699. c--;
  700. } while (x != 13 || c == 0);
  701. confirmname[c] = '\0';
  702. if (strcmp(newname, confirmname) == 0)
  703. {
  704. strcpy_s(one.passwd, confirmname);
  705. cout << endl;
  706. cout << "success" << endl;
  707. _getwch();
  708. }
  709. else
  710. {
  711. cout << endl;
  712. cout << "failed" << endl;
  713. _getwch();
  714. }
  715. }
  716. return one;
  717. }
  718.  
  719. void SaveUser(USER one)
  720. {
  721. USER userlist[1000];
  722. int userno, i, j;
  723. ifstream fin;
  724. //讀取userlist.txt放入userlist[]中
  725. fin.open("userlist.txt");
  726. fin >> userno;
  727. for (i = 0; i < userno; i++)
  728. {
  729. fin >> userlist[i].name;
  730. fin >> userlist[i].passwd;
  731. fin >> userlist[i].cash;
  732. fin >> userlist[i].login_count;
  733. fin >> userlist[i].sim_datei;
  734. for (j = 0; j < 5; j++)
  735. fin >> userlist[i].hold[j];
  736. if (strcmp(userlist[i].name, one.name) == 0) //讀到目前login的使用者,覆蓋他的資料
  737. {
  738. strcpy_s(userlist[i].passwd, one.passwd);
  739. userlist[i].cash = one.cash;
  740. userlist[i].login_count = one.login_count;
  741. for (j = 0; j < 5; j++)
  742. userlist[i].hold[j] = one.hold[j];
  743. }
  744. }
  745. fin.close();
  746. //更新完後寫回userlist.txt
  747. ofstream fout;
  748. fout.open("userlist.txt");
  749. fout << userno << endl;
  750. for (i = 0; i < userno; i++)
  751. {
  752. fout << userlist[i].name << endl;
  753. fout << userlist[i].passwd << endl;
  754. fout << userlist[i].cash << endl;
  755. fout << userlist[i].login_count << endl;
  756. fout << userlist[i].sim_datei << endl;
  757. fout << userlist[i].hold[0] << " " << userlist[i].hold[1] << " " << userlist[i].hold[2] << " " << userlist[i].hold[3] << " " << userlist[i].hold[4] << endl;
  758. }
  759. fout.close();
  760. }
  761.  
  762. USER investment(USER one, STOCK s[])
  763. {
  764. int i, j;
  765. system("cls");
  766. cout << "Your Cash:" << one.cash << endl;
  767. for (i = 0; i < 5; i++)
  768. {
  769. cout << s[i].name << " ";
  770. for (j = -2; j <= 0; j++)
  771. {
  772. cout << s[i].date[one.sim_datei + j] << " ";
  773. cout << s[i].close[one.sim_datei + j] << " ";
  774. }
  775. cout << "Hold: " << one.hold[i] << endl;
  776. }
  777. char company[10];
  778. do {
  779. cout << "Please tell me which company do you want to invest:" << endl;
  780. cin >> company;
  781. if (strcmp(company, "EXIT") == 0)
  782. break;
  783. else
  784. {
  785. bool ok = true;//是否輸入正確股票名稱
  786. for (i = 0; i < 5; i++)
  787. {
  788. if (strcmp(s[i].name, company) == 0)
  789. {
  790. ok = false;
  791. char x, y;
  792. do {
  793. system("cls");
  794. cout << "Your Cash:" << one.cash << endl;
  795. cout << "Hold: " << one.hold[i] << endl;
  796. cout << "Please press 右鍵 or 左鍵 to change the hold or enter to exit" << endl;
  797. x = _getwch();
  798. if (x == -32)
  799. {
  800. y = _getwch();
  801. switch (y)
  802. {
  803. case 77://右
  804.  
  805. if (one.cash >= s[i].close[one.sim_datei])
  806. {
  807. one.hold[i]++;
  808. one.cash -= s[i].close[one.sim_datei];
  809. }
  810. break;
  811. case 75://左
  812. if (one.hold[i] > 0)
  813. {
  814. one.hold[i]--;
  815. one.cash += s[i].close[one.sim_datei];
  816. }
  817. break;
  818. }
  819. }
  820. } while (x != 13);
  821. }
  822. }
  823. if (ok)
  824. cout << "!!!!!!!!!! Wrong !!!!!!!!!!" << endl;
  825.  
  826. }
  827. } while (true);
  828. //_getwch();
  829. return one;
  830. }
  831.  
  832. int main()
  833. {
  834. USER one;
  835. STOCK s[5];
  836. s[0] = read_stock("AAPL");
  837. s[1] = read_stock("AMZN");
  838. s[2] = read_stock("FB");
  839. s[3] = read_stock("GOOGL");
  840. s[4] = read_stock("MSFT");
  841. one = login();
  842. int select = 1;
  843. char c1, c2;
  844. do
  845. {
  846. mainUI(select, one, s);
  847. c1 = _getwch();
  848. if (c1 == -32)
  849. {
  850. c2 = _getwch();
  851. if (c2 == 72)//上
  852. select = (select + 6) % 7;
  853. if (c2 == 80)//下
  854. select = (select + 1) % 7;
  855. if (c2 == 77)//右=enter直接進入
  856. c1 = 13;
  857. if (c2 == 81)
  858. one.sim_datei++;
  859. }
  860. if (c1 >= '0'&&c1 <= '6')
  861. select = c1 - '0';
  862. if (c1 == 13)
  863. {
  864. if (select == 1) //投資決策
  865. {
  866. one = investment(one, s);
  867. }
  868. else if (select == 2) //數獨
  869. {
  870. int win = Sudoku_main();
  871. if (win == 1)
  872. one.cash += 5000;
  873. else
  874. one.cash -= 5000;
  875. }
  876. else if (select == 3) //聊天室
  877. {
  878. Chat_main(one);
  879. }
  880. else if (select == 4) //猜數字
  881. {
  882. int win = XAXB_main();
  883. if (win == 1)
  884. one.cash += 5000;
  885. else if (win == 0)
  886. one.cash += 1000;
  887. else
  888. one.cash -= 100;
  889. }
  890. else if (select == 5) //富爸爸
  891. {
  892. one.cash += 1000;
  893. }
  894. else if (select == 6) //變更密碼
  895. {
  896. one = Change_password(one);
  897. }
  898. else // select == 0
  899. {
  900. break;
  901. }
  902. }
  903. } while (true);
  904. SaveUser(one); //把user狀態存回userlist.txt
  905. delete_stock(s[0]);
  906. delete_stock(s[1]);
  907. delete_stock(s[2]);
  908. delete_stock(s[3]);
  909. delete_stock(s[4]);
  910. return 0;
  911. }
  912.  
  913. // 執行程式: Ctrl + F5 或 [偵錯] > [啟動但不偵錯] 功能表
  914. // 偵錯程式: F5 或 [偵錯] > [啟動偵錯] 功能表
  915.  
  916. // 開始使用的秘訣:
  917. // 1. 使用 [方案總管] 視窗,新增/管理檔案
  918. // 2. 使用 [Team Explorer] 視窗,連線到原始檔控制
  919. // 3. 使用 [輸出] 視窗,參閱組建輸出與其他訊息
  920. // 4. 使用 [錯誤清單] 視窗,檢視錯誤
  921. // 5. 前往 [專案] > [新增項目],建立新的程式碼檔案,或是前往 [專案] > [新增現有項目],將現有程式碼檔案新增至專案
  922. // 6. 之後要再次開啟此專案時,請前往 [檔案] > [開啟] > [專案],然後選取 .sln 檔案
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement