Advertisement
Guest User

Untitled

a guest
Jun 19th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.31 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5. const int Max = 100;
  6.  
  7. FILE *team;
  8. int i = 0;
  9. int score[Max];
  10. int numberofplaying[Max];
  11. char nama[Max][40];
  12. int jumlah;
  13.  
  14. void menu()
  15. {
  16. for (int i = 0; i < 16; i++)
  17. {
  18. printf("n");
  19. }
  20. printf("Score Record Dota2 Playern");
  21. printf("========================n");
  22. printf("1.View Recordn");
  23. printf("2.Add Player Recordn");
  24. printf("3.Add New Playern");
  25. printf("4.Delete Playern");
  26. printf("5.Save and Exitn");
  27. printf("nInput your choice[1..5]: ");
  28. }
  29.  
  30. void bacaData()
  31. {
  32. int i = 0;
  33.  
  34. team = fopen("Dota2.txt", "r");
  35. if (team == NULL)
  36. {
  37. printf("<<EMPTY RECORD>>");
  38. }
  39. else{
  40. while (fscanf(team, "%s %d %d", nama[i], &score[i], &numberofplaying[i]) != EOF)
  41. {
  42. i++;
  43. }
  44. jumlah = i;
  45. }
  46. fclose(team);
  47. }
  48.  
  49. void writeData()
  50. {
  51. printf(" Player Name | Average Score | Number of Playingn");
  52. for (int i = 0; i < 49; i++)
  53. {
  54. printf("=");
  55. }
  56. for (int i = 0; i < jumlah; i++)
  57. {
  58. printf("n%s | %d | %d", nama[i], score[i], numberofplaying[i]);
  59. }
  60.  
  61.  
  62. printf("nnPress Enter to continue.....");
  63. }
  64.  
  65. void addData()
  66. {
  67. printf("Input player name[1..%d] : ", jumlah);
  68. scanf("%s", nama[jumlah]);
  69. fflush(stdin);
  70. }
  71.  
  72. void insertData()
  73. {
  74. int i;
  75. team = fopen("Dota2.txt", "w");
  76. for (i = 0; i < jumlah; i++)
  77. {
  78. fprintf(team, "%s %d %dn", nama[i], score[i], numberofplaying[i]);
  79. }
  80. fclose(team);
  81. }
  82.  
  83. void insertDataScore()
  84. {
  85. int i;
  86. team = fopen("Dota2.txt", "w");
  87. for (i = 0; i < jumlah; i++)
  88. {
  89. fprintf(team, "%dn", score[i]);
  90. }
  91. fclose(team);
  92. }
  93.  
  94. void deleteData()
  95. {
  96. team = fopen("Dota2.txt", "w");
  97. for (int j = strlen(nama[jumlah]); j < jumlah; j++)
  98. {
  99. strcpy(nama[i], nama[i - 1]);
  100. score[i] = score[i - 1];
  101. numberofplaying[i] = numberofplaying[i - 1];
  102. }
  103.  
  104. fclose(team);
  105. }
  106.  
  107. int main()
  108. {
  109. int choice = 0;
  110. do
  111. {
  112. bacaData();
  113. do
  114. {
  115. menu();
  116. scanf("%d", &choice);
  117. fflush(stdin);
  118. } while (choice < 1 || choice > 5);
  119. switch (choice)
  120. {
  121. case 1:
  122. system("cls");
  123. for (int i = 0; i < 16; i++)
  124. {
  125. printf("n");
  126. }
  127. writeData();
  128. getchar();
  129. break;
  130. case 2:
  131. printf("n");
  132. addData();
  133. printf("Input player score[0..100] : ");
  134. scanf("%d", &score[jumlah]);
  135. score[jumlah]++;
  136. insertDataScore();
  137. printf("Score successfully updated^^");
  138. printf("nnPress Enter to continue.....");
  139. insertData();
  140. getchar();
  141. break;
  142. case 3:
  143. printf("n");
  144. addData();
  145. jumlah++;
  146. printf("nData successfully added..");
  147. printf("nnPress Enter to continue.....");
  148. insertData();
  149. getchar();
  150. break;
  151. case 4:
  152. printf("n");
  153. addData();
  154. deleteData();
  155. printf("n%s successfully deleted..", nama[jumlah]);
  156. jumlah--;
  157. printf("nnPress Enter to continue.....");
  158. getchar();
  159. break;
  160. }
  161. } while (choice != 5);
  162. return 0;
  163. }
  164.  
  165. #include<stdio.h>
  166. #include<stdlib.h>
  167. #include<string.h>
  168.  
  169. const int Max = 100;
  170.  
  171. FILE *team;
  172. int i = 0;
  173. int score[Max];
  174. int numberofplaying[Max];
  175. char nama[Max][40];
  176. int jumlah;
  177.  
  178. void menu()
  179. {
  180. for (int i = 0; i < 16; i++)
  181. {
  182. printf("n");
  183. }
  184. printf("Score Record Dota2 Playern");
  185. printf("========================n");
  186. printf("1.View Recordn");
  187. printf("2.Add Player Recordn");
  188. printf("3.Add New Playern");
  189. printf("4.Delete Playern");
  190. printf("5.Save and Exitn");
  191. printf("nInput your choice[1..5]: ");
  192. }
  193.  
  194. void bacaData()
  195. {
  196. int i = 0;
  197.  
  198. team = fopen("Dota2.txt", "r");
  199. if (team == NULL)
  200. {
  201. printf("<<EMPTY RECORD>>");
  202. }
  203. else{
  204. while (fscanf(team, "%s %d %d", nama[i], &score[i], &numberofplaying[i]) != EOF)
  205. {
  206. i++;
  207. }
  208. jumlah = i;
  209. }
  210. fclose(team);
  211. }
  212.  
  213. void writeData()
  214. {
  215. printf(" Player Name | Average Score | Number of Playingn");
  216. for (int i = 0; i < 49; i++)
  217. {
  218. printf("=");
  219. }
  220. for (int i = 0; i < jumlah; i++)
  221. {
  222. printf("n%s | %d | %d", nama[i], score[i], numberofplaying[i]);
  223. }
  224.  
  225.  
  226. printf("nnPress Enter to continue.....");
  227. }
  228.  
  229. void addData()
  230. {
  231. printf("Input player name[1..%d] : ", jumlah);
  232. scanf("%s", nama[jumlah]);
  233. fflush(stdin);
  234. }
  235.  
  236. void insertData()
  237. {
  238. int i;
  239. team = fopen("Dota2.txt", "w");
  240. for (i = 0; i < jumlah; i++)
  241. {
  242. fprintf(team, "%s %d %dn", nama[i], score[i], numberofplaying[i]);
  243. }
  244. fclose(team);
  245. }
  246.  
  247. void insertDataScore()
  248. {
  249. int i;
  250. team = fopen("Dota2.txt", "w");
  251. for (i = 0; i < jumlah; i++)
  252. {
  253. fprintf(team, "%dn", score[i]);
  254. }
  255. fclose(team);
  256. }
  257.  
  258. void deleteData()
  259. {
  260. team = fopen("Dota2.txt", "w");
  261. for (int j = strlen(nama[jumlah]); j < jumlah; j++)
  262. {
  263. strcpy(nama[i], nama[i - 1]);
  264. score[i] = score[i - 1];
  265. numberofplaying[i] = numberofplaying[i - 1];
  266. }
  267.  
  268. fclose(team);
  269. }
  270.  
  271. int main()
  272. {
  273. int choice = 0;
  274. do
  275. {
  276. bacaData();
  277. do
  278. {
  279. menu();
  280. scanf("%d", &choice);
  281. fflush(stdin);
  282. } while (choice < 1 || choice > 5);
  283. switch (choice)
  284. {
  285. case 1:
  286. system("cls");
  287. for (int i = 0; i < 16; i++)
  288. {
  289. printf("n");
  290. }
  291. writeData();
  292. getchar();
  293. break;
  294. case 2:
  295. printf("n");
  296. addData();
  297. printf("Input player score[0..100] : ");
  298. scanf("%d", &score[jumlah]);
  299. score[jumlah]++;
  300. insertDataScore();
  301. printf("Score successfully updated^^");
  302. printf("nnPress Enter to continue.....");
  303. insertData();
  304. getchar();
  305. break;
  306. case 3:
  307. printf("n");
  308. addData();
  309. jumlah++;
  310. printf("nData successfully added..");
  311. printf("nnPress Enter to continue.....");
  312. insertData();
  313. getchar();
  314. break;
  315. case 4:
  316. printf("n");
  317. addData();
  318. deleteData();
  319. printf("n%s successfully deleted..", nama[jumlah]);
  320. jumlah--;
  321. printf("nnPress Enter to continue.....");
  322. getchar();
  323. break;
  324. }
  325. } while (choice != 5);
  326. return 0;
  327. }
  328.  
  329. #include<stdio.h>
  330. #include<stdlib.h>
  331. #include<string.h>
  332.  
  333. const int Max = 100;
  334.  
  335. FILE *team;
  336. int i = 0;
  337. int score[Max];
  338. int numberofplaying[Max];
  339. char nama[Max][40];
  340. int jumlah;
  341.  
  342. void menu()
  343. {
  344. for (int i = 0; i < 16; i++)
  345. {
  346. printf("n");
  347. }
  348. printf("Score Record Dota2 Playern");
  349. printf("========================n");
  350. printf("1.View Recordn");
  351. printf("2.Add Player Recordn");
  352. printf("3.Add New Playern");
  353. printf("4.Delete Playern");
  354. printf("5.Save and Exitn");
  355. printf("nInput your choice[1..5]: ");
  356. }
  357.  
  358. void bacaData()
  359. {
  360. int i = 0;
  361.  
  362. team = fopen("Dota2.txt", "r");
  363. if (team == NULL)
  364. {
  365. printf("<<EMPTY RECORD>>");
  366. }
  367. else{
  368. while (fscanf(team, "%s %d %d", nama[i], &score[i], &numberofplaying[i]) != EOF)
  369. {
  370. i++;
  371. }
  372. jumlah = i;
  373. }
  374. fclose(team);
  375. }
  376.  
  377. void writeData()
  378. {
  379. printf(" Player Name | Average Score | Number of Playingn");
  380. for (int i = 0; i < 49; i++)
  381. {
  382. printf("=");
  383. }
  384. for (int i = 0; i < jumlah; i++)
  385. {
  386. printf("n%s | %d | %d", nama[i], score[i], numberofplaying[i]);
  387. }
  388.  
  389.  
  390. printf("nnPress Enter to continue.....");
  391. }
  392.  
  393. void addData()
  394. {
  395. printf("Input player name[1..%d] : ", jumlah);
  396. scanf("%s", nama[jumlah]);
  397. fflush(stdin);
  398. }
  399.  
  400. void insertData()
  401. {
  402. int i;
  403. team = fopen("Dota2.txt", "w");
  404. for (i = 0; i < jumlah; i++)
  405. {
  406. fprintf(team, "%s %d %dn", nama[i], score[i], numberofplaying[i]);
  407. }
  408. fclose(team);
  409. }
  410.  
  411. void insertDataScore()
  412. {
  413. int i;
  414. team = fopen("Dota2.txt", "w");
  415. for (i = 0; i < jumlah; i++)
  416. {
  417. fprintf(team, "%dn", score[i]);
  418. }
  419. fclose(team);
  420. }
  421.  
  422. void deleteData()
  423. {
  424. team = fopen("Dota2.txt", "w");
  425. for (int j = strlen(nama[jumlah]); j < jumlah; j++)
  426. {
  427. strcpy(nama[i], nama[i - 1]);
  428. score[i] = score[i - 1];
  429. numberofplaying[i] = numberofplaying[i - 1];
  430. }
  431.  
  432. fclose(team);
  433. }
  434.  
  435. int main()
  436. {
  437. int choice = 0;
  438. do
  439. {
  440. bacaData();
  441. do
  442. {
  443. menu();
  444. scanf("%d", &choice);
  445. fflush(stdin);
  446. } while (choice < 1 || choice > 5);
  447. switch (choice)
  448. {
  449. case 1:
  450. system("cls");
  451. for (int i = 0; i < 16; i++)
  452. {
  453. printf("n");
  454. }
  455. writeData();
  456. getchar();
  457. break;
  458. case 2:
  459. printf("n");
  460. addData();
  461. printf("Input player score[0..100] : ");
  462. scanf("%d", &score[jumlah]);
  463. score[jumlah]++;
  464. insertDataScore();
  465. printf("Score successfully updated^^");
  466. printf("nnPress Enter to continue.....");
  467. insertData();
  468. getchar();
  469. break;
  470. case 3:
  471. printf("n");
  472. addData();
  473. jumlah++;
  474. printf("nData successfully added..");
  475. printf("nnPress Enter to continue.....");
  476. insertData();
  477. getchar();
  478. break;
  479. case 4:
  480. printf("n");
  481. addData();
  482. deleteData();
  483. printf("n%s successfully deleted..", nama[jumlah]);
  484. jumlah--;
  485. printf("nnPress Enter to continue.....");
  486. getchar();
  487. break;
  488. }
  489. } while (choice != 5);
  490. return 0;
  491. }
  492.  
  493. #include<stdio.h>
  494. #include<stdlib.h>
  495. #include<string.h>
  496.  
  497. const int Max = 100;
  498.  
  499. FILE *team;
  500. int i = 0;
  501. int score[Max];
  502. int numberofplaying[Max];
  503. char nama[Max][40];
  504. int jumlah;
  505.  
  506. void menu()
  507. {
  508. for (int i = 0; i < 16; i++)
  509. {
  510. printf("n");
  511. }
  512. printf("Score Record Dota2 Playern");
  513. printf("========================n");
  514. printf("1.View Recordn");
  515. printf("2.Add Player Recordn");
  516. printf("3.Add New Playern");
  517. printf("4.Delete Playern");
  518. printf("5.Save and Exitn");
  519. printf("nInput your choice[1..5]: ");
  520. }
  521.  
  522. void bacaData()
  523. {
  524. int i = 0;
  525.  
  526. team = fopen("Dota2.txt", "r");
  527. if (team == NULL)
  528. {
  529. printf("<<EMPTY RECORD>>");
  530. }
  531. else{
  532. while (fscanf(team, "%s %d %d", nama[i], &score[i], &numberofplaying[i]) != EOF)
  533. {
  534. i++;
  535. }
  536. jumlah = i;
  537. }
  538. fclose(team);
  539. }
  540.  
  541. void writeData()
  542. {
  543. printf(" Player Name | Average Score | Number of Playingn");
  544. for (int i = 0; i < 49; i++)
  545. {
  546. printf("=");
  547. }
  548. for (int i = 0; i < jumlah; i++)
  549. {
  550. printf("n%s | %d | %d", nama[i], score[i], numberofplaying[i]);
  551. }
  552.  
  553.  
  554. printf("nnPress Enter to continue.....");
  555. }
  556.  
  557. void addData()
  558. {
  559. printf("Input player name[1..%d] : ", jumlah);
  560. scanf("%s", nama[jumlah]);
  561. fflush(stdin);
  562. }
  563.  
  564. void insertData()
  565. {
  566. int i;
  567. team = fopen("Dota2.txt", "w");
  568. for (i = 0; i < jumlah; i++)
  569. {
  570. fprintf(team, "%s %d %dn", nama[i], score[i], numberofplaying[i]);
  571. }
  572. fclose(team);
  573. }
  574.  
  575. void insertDataScore()
  576. {
  577. int i;
  578. team = fopen("Dota2.txt", "w");
  579. for (i = 0; i < jumlah; i++)
  580. {
  581. fprintf(team, "%dn", score[i]);
  582. }
  583. fclose(team);
  584. }
  585.  
  586. void deleteData()
  587. {
  588. team = fopen("Dota2.txt", "w");
  589. for (int j = strlen(nama[jumlah]); j < jumlah; j++)
  590. {
  591. strcpy(nama[i], nama[i - 1]);
  592. score[i] = score[i - 1];
  593. numberofplaying[i] = numberofplaying[i - 1];
  594. }
  595.  
  596. fclose(team);
  597. }
  598.  
  599. int main()
  600. {
  601. int choice = 0;
  602. do
  603. {
  604. bacaData();
  605. do
  606. {
  607. menu();
  608. scanf("%d", &choice);
  609. fflush(stdin);
  610. } while (choice < 1 || choice > 5);
  611. switch (choice)
  612. {
  613. case 1:
  614. system("cls");
  615. for (int i = 0; i < 16; i++)
  616. {
  617. printf("n");
  618. }
  619. writeData();
  620. getchar();
  621. break;
  622. case 2:
  623. printf("n");
  624. addData();
  625. printf("Input player score[0..100] : ");
  626. scanf("%d", &score[jumlah]);
  627. score[jumlah]++;
  628. insertDataScore();
  629. printf("Score successfully updated^^");
  630. printf("nnPress Enter to continue.....");
  631. insertData();
  632. getchar();
  633. break;
  634. case 3:
  635. printf("n");
  636. addData();
  637. jumlah++;
  638. printf("nData successfully added..");
  639. printf("nnPress Enter to continue.....");
  640. insertData();
  641. getchar();
  642. break;
  643. case 4:
  644. printf("n");
  645. addData();
  646. deleteData();
  647. printf("n%s successfully deleted..", nama[jumlah]);
  648. jumlah--;
  649. printf("nnPress Enter to continue.....");
  650. getchar();
  651. break;
  652. }
  653. } while (choice != 5);
  654. return 0;
  655. }
  656.  
  657. int findIndexPlayer(const char* name)
  658. {
  659. for (int i = 0; i != jumlah; ++i) {
  660. if (strcmp(name, nama[i]) == 0) {
  661. return i;
  662. }
  663. }
  664. return -1; // Not found
  665. }
  666.  
  667. void askPlayerName(char* name)
  668. {
  669. printf("Input player name[1..40 kar]");
  670. scanf("%s", name);
  671. fflush(stdin);
  672. }
  673.  
  674. void deletePlayer(const char* name)
  675. {
  676. const int indexPlayer = findIndexPlayer(name);
  677.  
  678. if (indexPlayer == -1) {
  679. // You may display error message.
  680. return; // Player not found in record
  681. }
  682. for (int i = indexPlayer; i + 1 < jumlah; i++)
  683. {
  684. strcpy(nama[i], nama[i + 1]);
  685. score[i] = score[i + 1];
  686. numberofplaying[i] = numberofplaying[i + 1];
  687. }
  688. --jumlah;
  689. }
  690.  
  691. case 4: {
  692. char playerName[40];
  693. printf("n");
  694. askPlayerName(playerName);
  695. deletePlayer(playerName);
  696. printf("n%s successfully deleted..", playerName);
  697. printf("nnPress Enter to continue.....");
  698. getchar();
  699. break;
  700. }
  701.  
  702. FILE *team;
  703. int i = 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement