Advertisement
Guest User

Untitled

a guest
May 11th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.70 KB | None | 0 0
  1. // Include Libraries
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <conio.h>
  6.  
  7. // Color Constants
  8. #define RED "\x1B[31m"
  9. #define GREEN "\x1B[32m"
  10. #define YELLOW "\x1B[33m"
  11. #define BLUE "\x1B[34m"
  12. #define MAGENTA "\x1B[35m"
  13. #define CYAN "\x1B[36m"
  14. #define WHITE "\x1B[37m"
  15. #define RESET "\x1B[0m"
  16.  
  17. // Data Structure
  18. typedef struct Entries {
  19. char
  20. /*1*/ name[20], // Firstname Lastname
  21. /*2*/ connection[15], // Broadband, WiFi, 2G, 3G, 4G
  22. /*3*/ usage[20], // Social, News, Entertainment, Work, Academic
  23. /*4*/ area[10]; // Bashundhara, Mirpur, Uttara, Dhanmondi, Gulshan, Banani, Motijheel, Cantonment, Others
  24. /*5*/ int age; // 34
  25. /*6*/ float hours; // 5.5
  26. } Entries;
  27.  
  28. // File IO Functions
  29. int readNumOfEntriesFromFile(); // - Nz
  30. Entries* readFromFile(); // - Nz
  31. void appendToFile(Entries Entry); // - Nz
  32. void writeToFile(Entries EntriesArr[], int entriesNo); // - Nz
  33.  
  34. // Menu Functions
  35. void mainMenu(); // Show The Menu
  36. void adminMenuAuth(); // Admin Menu Authenication - Tashfi
  37. void pageTitle(char title[]); // Show Title of the App, Page and call fflush() - Nz
  38. void adminMenu(); // Show Admin Panel - Tashfiha
  39.  
  40. // Feature Functions
  41. void askSurvey(); // Ask Questions & Save Them - Tafi
  42. void modifyAnEntry(); // Edit an Entry and ReWrite Whole File - Tashfi
  43. void deleteAnEntry(); // Delete an Entry and ReWrite Whole File - Tashfi
  44. void listAll(); // Show All Entries - Tafi
  45. void searchByName(); // Show Entry Matching Name - Tashfi
  46. void searchByArea(); // Show Entry/Entries Matching Area - Tafi
  47. void searchByAge(); // Show Entry/Entries Matching Age Interval - Tafi
  48. void compareUsageByArea(); // Compare All Areas Usage by Average of Users From Each Area - Tafi
  49. void barChartAgeVsHours(); // Show Age vs Hours Barchart - Nz
  50. void pyramidConnection(); // Pyramid of Internet Connection Usage from Low to High - Nz
  51.  
  52. // Test Function
  53. void Test();
  54. void Test(){
  55.  
  56. // Single Entry
  57. Entries Entry;
  58. printf("%s\n",Entry.name);
  59. printf("%s\n", Entry.connection);
  60. printf("%s\n", Entry.usage);
  61. printf("%s\n", Entry.area);
  62. printf("%d\n", Entry.age);
  63. printf("%.1f\n", Entry.hours);
  64. }
  65.  
  66. // Main
  67. int main(){
  68. mainMenu();
  69. modifyAnEntry();
  70. return 0;
  71. }
  72. // Read From File & Return Number of Entries
  73. // Params: void
  74. // Return:int entriesNum
  75. int readNumOfEntriesFromFile(){
  76. FILE *entriesFile;
  77. entriesFile = fopen("database/entries.txt", "r");
  78.  
  79. int lines = 0;
  80. for(char c=getc(entriesFile); c!=EOF; c=getc(entriesFile)){
  81. if(c=='\n'){
  82. lines++;
  83. }
  84. }
  85. fclose(entriesFile);
  86.  
  87. int entriesNum = lines/6;
  88.  
  89. return entriesNum;
  90. }
  91. // Read From File
  92. // Params: void
  93. // Return: struct EntriesArr[]
  94. Entries* readFromFile(){
  95. readNumOfEntriesFromFile();
  96. static Entries EntriesArr[3];
  97.  
  98. FILE *entriesFile;
  99. entriesFile = fopen("database/entries.txt", "r");
  100.  
  101. if(entriesFile == NULL){
  102. printf("Ooops! No Entries Found :/\n");
  103. }
  104.  
  105. for(int i=0; i<readNumOfEntriesFromFile(); i++){
  106. fscanf (entriesFile, "%[^\n]s",EntriesArr[i].name);
  107. fscanf (entriesFile, "%s",EntriesArr[i].usage);
  108. fscanf (entriesFile, "%s",EntriesArr[i].connection);
  109. fscanf (entriesFile, "%s",EntriesArr[i].area);
  110. fscanf (entriesFile, "%d ",&EntriesArr[i].age);
  111. fscanf (entriesFile, "%f ",&EntriesArr[i].hours);
  112. }
  113.  
  114. fclose(entriesFile);
  115.  
  116. return EntriesArr;
  117. }
  118. // Append To File
  119. // Params: struct Entries Entry
  120. // Return: void
  121. void appendToFile(Entries Entry){
  122.  
  123.  
  124.  
  125. FILE *entriesFile;
  126. entriesFile = fopen("database/entries.txt", "a");
  127.  
  128. fprintf(entriesFile, "%s\n",Entry.name);
  129. fprintf(entriesFile, "%s\n",Entry.usage);
  130. fprintf(entriesFile, "%s\n",Entry.connection);
  131. fprintf(entriesFile, "%s\n",Entry.area);
  132. fprintf(entriesFile, "%d\n", Entry.age);
  133. fprintf(entriesFile, "%.1f\n", Entry.hours);
  134.  
  135. fclose(entriesFile);
  136. }
  137. // Write To File
  138. // Params: struct Entries[]
  139. // Return: void
  140. void writeToFile(Entries *EntriesArr, int entriesNo){
  141. FILE *entriesFile;
  142. entriesFile = fopen("database/entries.txt", "w");
  143.  
  144. for(int i=0; i<entriesNo; i++){
  145. fprintf(entriesFile, "%s\n",EntriesArr[i].name);
  146. fprintf(entriesFile, "%s\n",EntriesArr[i].usage);
  147. fprintf(entriesFile, "%s\n",EntriesArr[i].connection);
  148. fprintf(entriesFile, "%s\n",EntriesArr[i].area);
  149. fprintf(entriesFile, "%d\n", EntriesArr[i].age);
  150. fprintf(entriesFile, "%.1f\n", EntriesArr[i].hours);
  151. }
  152.  
  153. fclose(entriesFile);
  154. }
  155.  
  156.  
  157.  
  158. // Title of The App, Page, fflush(stdin)
  159. void pageTitle(char title[]){
  160. system("cls");
  161. puts(CYAN "------------------------------------------------------");
  162. puts(" Survey Entry and Analyser - Internet Usage ");
  163. puts("------------------------------------------------------");
  164. printf(" %s\n", title);
  165. puts("------------------------------------------------------");
  166. puts(RESET);
  167.  
  168. fflush(stdin);
  169. }
  170.  
  171.  
  172.  
  173. // Menu To Choose Survey/Admin
  174. void mainMenu(){
  175. pageTitle("Main Menu");
  176.  
  177. int chc;
  178. puts("\n1. Enter the survey. \n");
  179. puts("\n2. Enter Admin Panel. \n");
  180. puts("\n0. Exit App. ");
  181.  
  182. puts("\n\nEnter your choice:");
  183. scanf("%d", &chc);
  184.  
  185. switch (chc) {
  186. case 1: askSurvey();
  187. break;
  188. case 2: adminMenuAuth();
  189. break;
  190. default: pageTitle("Dhonnobaad. Abar Ashben. :3"); exit(0);
  191. }
  192. }
  193. // Admin Authenication
  194. void adminMenuAuth(){
  195. pageTitle("Login to Admin Panel");
  196.  
  197. char user[15], pass[15];
  198. int matched = 0;
  199.  
  200. while(!matched){
  201. puts("Enter Admin Username: [Hint: admin] ");
  202. gets(user);
  203. puts("Enter Admin Password: [Hint: pass] ");
  204. gets(pass);
  205.  
  206. if(strcmp(user, "admin") == 0 && strcmp(pass, "password")){
  207. adminMenu();
  208. break;
  209. } else {
  210. printf(RED "\n\nIncorrect Username/Password :(\n\n\n" RESET);
  211. }
  212. }
  213. }
  214. // The Admin Panel
  215. void adminMenu(){
  216. pageTitle("Admin Panel");
  217. int chc;
  218.  
  219. puts("1. List All Entries. ");
  220. puts("\n2. Modify An Entry. ");
  221. puts("\n3. Delete An Entry. \n");
  222.  
  223. puts("\n4. Search Entry By Name. ");
  224. puts("\n5. Search Entries By Area. ");
  225. puts("\n6. Search Entries By Age Interval. ");
  226. puts("\n7. Compare Usage Among Areas. ");
  227. puts("\n8 Visualize BarChart of Age vs Hours. ");
  228. puts("\n9. Visualize Pyramid of Internet Connection Types. ");
  229.  
  230. puts("\n\n10. Back To Main Menu. ");
  231. puts("\n0. Exit Application. ");
  232.  
  233. puts("\n\nEnter your choice:");
  234. scanf("%d", &chc);
  235.  
  236. switch (chc) {
  237. case 1: listAll();
  238. break;
  239. case 2: modifyAnEntry();
  240. break;
  241. case 3: deleteAnEntry();
  242. break;
  243. case 4: searchByName();
  244. break;
  245. case 5: searchByArea();
  246. break;
  247. case 6: searchByAge();
  248. break;
  249. case 7: compareUsageByArea();
  250. break;
  251. case 8: barChartAgeVsHours();
  252. break;
  253. case 9: pyramidConnection();
  254. break;
  255. case 0: mainMenu();
  256. break;
  257. default: pageTitle("Dhonnobaad. Abar Ashben. :3"); exit(0);
  258. }
  259. }
  260.  
  261.  
  262. // Ask Questions and then Save
  263. void askSurvey(){
  264. pageTitle("Survey Data Entry");
  265.  
  266. Entries Entry;
  267.  
  268. // 1
  269. puts("Your Name? (One Word)");
  270. gets(Entry.name);
  271. fflush(stdin);
  272.  
  273. // 2
  274. puts("\nConnection You Use? (One Word)");
  275. puts("a. Broadband \tb. WiFi \tc. 3G \td. 4G \te. others");
  276. gets(Entry.connection);
  277. fflush(stdin);
  278. if(strcmp(Entry.connection, "a") == 0){
  279. strcpy(Entry.connection, "Broadband");
  280. } else if(strcmp(Entry.connection, "b") == 0){
  281. strcpy(Entry.connection, "WiFi");
  282. } if(strcmp(Entry.connection, "c") == 0){
  283. strcpy(Entry.connection, "3G");
  284. } if(strcmp(Entry.connection, "d") == 0){
  285. strcpy(Entry.connection, "4G");
  286. } if(strcmp(Entry.connection, "e") == 0){
  287. strcpy(Entry.connection, "Others");
  288. }
  289.  
  290. // 3
  291. puts("\nWhat do you Internet mostly for? (One Word)");
  292. puts("a. Social \tb. News \tc. Entertainment \td. Work \te. Academic \tf. Others");
  293. gets(Entry.usage);
  294. fflush(stdin);
  295. if(strcmp(Entry.usage, "a") == 0){
  296. strcpy(Entry.usage, "Social");
  297. } else if(strcmp(Entry.usage, "b") == 0){
  298. strcpy(Entry.usage, "News");
  299. } if(strcmp(Entry.usage, "c") == 0){
  300. strcpy(Entry.usage, "Entertainment");
  301. } if(strcmp(Entry.usage, "d") == 0){
  302. strcpy(Entry.usage, "Work");
  303. } if(strcmp(Entry.usage, "e") == 0){
  304. strcpy(Entry.usage, "Academic");
  305. } if(strcmp(Entry.usage, "f") == 0){
  306. strcpy(Entry.usage, "Others");
  307. }
  308.  
  309. // 4
  310. puts("\nYour Area?");
  311. puts("a. Bashundhara b. Mirpur c. Uttara e. Banani f. Others");
  312. gets(Entry.area);
  313. fflush(stdin);
  314. if(strcmp(Entry.area, "a") == 0){
  315. strcpy(Entry.area, "Bashundhara");
  316. } else if(strcmp(Entry.area, "b") == 0){
  317. strcpy(Entry.area, "Mirpur");
  318. } if(strcmp(Entry.area, "c") == 0){
  319. strcpy(Entry.area, "Uttara");
  320. } if(strcmp(Entry.area, "d") == 0){
  321. strcpy(Entry.area, "Dhanmondi");
  322. } if(strcmp(Entry.area, "e") == 0){
  323. strcpy(Entry.area, "Banani");
  324. } if(strcmp(Entry.area, "f") == 0){
  325. strcpy(Entry.area, "Others");
  326. }
  327.  
  328. // 5
  329. puts("\nYour Age?");
  330. scanf("%d", &Entry.age);
  331. fflush(stdin);
  332.  
  333. // 6
  334. puts("\nHow many hours do you spend on the Internet everyday?");
  335. scanf("%f",&Entry.hours);
  336.  
  337. appendToFile(Entry);
  338.  
  339. puts(CYAN "\n\n\nPress any key to go back to Main Menu");
  340. getch();
  341. mainMenu();
  342. }
  343.  
  344.  
  345.  
  346. // Show All Entries
  347. void listAll(){
  348. pageTitle("All Entries");
  349. Entries *EntriesArr = readFromFile();
  350. int entriesNum = readNumOfEntriesFromFile();
  351.  
  352. for(int i=0; i<entriesNum; i++){
  353. printf("\n\nEntry No.:%d ", i+1);
  354. puts("\n---------------------------------");
  355. printf("Name: %s",EntriesArr[i].name);
  356. puts("");
  357. printf("Usage: %s",EntriesArr[i].usage);
  358. puts("");
  359. printf("Connection: %s",EntriesArr[i].connection);
  360. puts("");
  361. printf("Area: %s",EntriesArr[i].area);
  362. puts("");
  363. printf("Age: %d ", EntriesArr[i].age);
  364. puts("");
  365. printf("Hours: %.1f ", EntriesArr[i].hours);
  366. }
  367.  
  368. puts(CYAN "\n\n\nPress any key to go back to Admin Panel" RESET);
  369. getch();
  370. adminMenu();
  371. }
  372. // Read Whole File -> Search Matching Entry -> Edit -> Write Whole File
  373. void modifyAnEntry(){
  374. pageTitle("Modify An Entry");
  375.  
  376. Entries *EntriesArr = readFromFile();
  377.  
  378. // Write code here to filter out an entry and modify it
  379. char name[20];
  380. int EntriesNum = readNumOfEntriesFromFile();
  381. puts("Enter 'Name' of the Entry to Modify");
  382. gets(name);
  383. char oldName[20];
  384.  
  385. for(int i=0; i<EntriesNum; i++){
  386. strcpy(oldName, EntriesArr[i].name);
  387.  
  388. if(strcmp(strupr(oldName), strupr(name)) == 0){
  389. if(strcmp(strupr(EntriesArr[i].name), strupr(name)) == 0){
  390. printf("\nMatch Found!\n\nPlease Enter New Info For This Entry.\n\n");
  391. strcpy(name, "found");
  392.  
  393. // 1
  394. puts("Your Name? (One Word)");
  395. gets(EntriesArr[i].name);
  396. fflush(stdin);
  397.  
  398. // 2
  399. puts("\nConnection You Use? (One Word)");
  400. puts("a. Broadband \tb. WiFi \tc. 3G \td. 4G \te. others");
  401. gets(EntriesArr[i].connection);
  402. fflush(stdin);
  403. if(strcmp(EntriesArr[i].connection, "a") == 0){
  404. strcpy(EntriesArr[i].connection, "Broadband");
  405. } else if(strcmp(EntriesArr[i].connection, "b") == 0){
  406. strcpy(EntriesArr[i].connection, "WiFi");
  407. } if(strcmp(EntriesArr[i].connection, "c") == 0){
  408. strcpy(EntriesArr[i].connection, "3G");
  409. } if(strcmp(EntriesArr[i].connection, "d") == 0){
  410. strcpy(EntriesArr[i].connection, "4G");
  411. } if(strcmp(EntriesArr[i].connection, "e") == 0){
  412. strcpy(EntriesArr[i].connection, "Others");
  413. }
  414.  
  415. // 3
  416. puts("\nWhat do you Internet mostly for? (One Word)");
  417. puts("a. Social \tb. News \tc. Entertainment \td. Work \te. Academic \tf. Others");
  418. gets(EntriesArr[i].usage);
  419. fflush(stdin);
  420. if(strcmp(EntriesArr[i].usage, "a") == 0){
  421. strcpy(EntriesArr[i].usage, "Social");
  422. } else if(strcmp(EntriesArr[i].usage, "b") == 0){
  423. strcpy(EntriesArr[i].usage, "News");
  424. } if(strcmp(EntriesArr[i].usage, "c") == 0){
  425. strcpy(EntriesArr[i].usage, "Entertainment");
  426. } if(strcmp(EntriesArr[i].usage, "d") == 0){
  427. strcpy(EntriesArr[i].usage, "Work");
  428. } if(strcmp(EntriesArr[i].usage, "e") == 0){
  429. strcpy(EntriesArr[i].usage, "Academic");
  430. } if(strcmp(EntriesArr[i].usage, "f") == 0){
  431. strcpy(EntriesArr[i].usage, "Others");
  432. }
  433.  
  434. // 4
  435. puts("\nYour Area?");
  436. puts("a. Bashundhara b. Mirpur c. Uttara e. Banani f. Others");
  437. gets(EntriesArr[i].area);
  438. fflush(stdin);
  439. if(strcmp(EntriesArr[i].area, "a") == 0){
  440. strcpy(EntriesArr[i].area, "Bashundhara");
  441. } else if(strcmp(EntriesArr[i].area, "b") == 0){
  442. strcpy(EntriesArr[i].area, "Mirpur");
  443. } if(strcmp(
  444. EntriesArr[i].area, "c") == 0){
  445. strcpy(EntriesArr[i].area, "Uttara");
  446. } if(strcmp(EntriesArr[i].area, "d") == 0){
  447. strcpy(EntriesArr[i].area, "Dhanmondi");
  448. } if(strcmp(EntriesArr[i].area, "e") == 0){
  449. strcpy(
  450. EntriesArr[i].area, "Banani");
  451. } if(strcmp(EntriesArr[i].area, "f") == 0){
  452. strcpy(EntriesArr[i].area, "Others");
  453. }
  454.  
  455. // 5
  456. puts("\nYour Age?");
  457. scanf("%d", &EntriesArr[i].age);
  458. fflush(stdin);
  459.  
  460. // 6
  461. puts("\nHow many hours do you spend on the Internet everyday?");
  462. scanf("%f",&EntriesArr[i].hours);
  463.  
  464. writeToFile(EntriesArr, EntriesNum);
  465. }
  466. }
  467. }
  468.  
  469. if(!strcmp(name, "found") == 0){
  470. printf("\nEntry Not Found :\(");
  471. }
  472.  
  473.  
  474. puts(CYAN "\n\n\nPress any key to go back to Admin Panel" RESET);
  475. getch();
  476. adminMenu();
  477. }
  478. // Read Whole File -> Search Matching Entry -> Delete -> Write Whole File
  479. void deleteAnEntry(){
  480. pageTitle("Delete An Entry");
  481.  
  482. Entries *EntriesArr = readFromFile();
  483.  
  484. // Write code here to filter out an entry and modify it
  485. char name[20];
  486. int EntriesNum = readNumOfEntriesFromFile();
  487. puts("Enter 'Name' of the Entry to Delete.");
  488. gets(name);
  489. char oldName[20];
  490.  
  491. for(int i=0; i<EntriesNum; i++){
  492. strcpy(oldName, EntriesArr[i].name);
  493.  
  494. if(strcmp(strupr(oldName), strupr(name)) == 0){
  495. printf("\nMatch Found!\n\nSelected Entry Successfully Deleted! \n\n");
  496. strcpy(name, "found");
  497.  
  498. for(int j=i; j<EntriesNum; j++){
  499. strcpy(EntriesArr[j].name, EntriesArr[j+1].name);
  500. strcpy(EntriesArr[j].usage, EntriesArr[j+1].usage);
  501. strcpy(EntriesArr[j].connection, EntriesArr[j+1].connection);
  502. strcpy(EntriesArr[j].area, EntriesArr[j+1].area);
  503. EntriesArr[j].age = EntriesArr[j+1].age;
  504. EntriesArr[j].hours = EntriesArr[j+1].hours;
  505. }
  506.  
  507. writeToFile(EntriesArr, EntriesNum-1);
  508. }
  509. }
  510.  
  511. if(!strcmp(name, "found") == 0){
  512. printf("\nEntry Not Found :\(");
  513. }
  514.  
  515. puts(CYAN "\n\n\nPress any key to go back to Admin Panel" RESET);
  516. getch();
  517. adminMenu();
  518. }
  519.  
  520.  
  521. // Show Entry Matching Name
  522. void searchByName(){
  523. pageTitle("Search By Name");
  524.  
  525. // Write code Here
  526. Entries *EntriesArr = readFromFile();
  527.  
  528. char name[20];
  529. int EntriesNum = readNumOfEntriesFromFile();
  530. puts("Enter 'Name' of the Entry to Search.");
  531. gets(name);
  532. char oldName[20];
  533.  
  534. for(int i=0; i<EntriesNum; i++){
  535. strcpy(oldName, EntriesArr[i].name);
  536.  
  537. if(strcmp(strupr(oldName), strupr(name)) == 0){
  538. printf("\nMatch Found!\n\n");
  539. strcpy(name, "FOUND");
  540.  
  541. puts("\n---------------------------------");
  542. printf("Name: %s",EntriesArr[i].name);
  543. puts("");
  544. printf("Usage: %s",EntriesArr[i].usage);
  545. puts("");
  546. printf("Connection: %s",EntriesArr[i].connection);
  547. puts("");
  548. printf("Area: %s",EntriesArr[i].area);
  549. puts("");
  550. printf("Age: %d ", EntriesArr[i].age);
  551. puts("");
  552. printf("Hours: %.1f ", EntriesArr[i].hours);
  553. puts("\n---------------------------------");
  554. }
  555. }
  556.  
  557. if(!strcmp(name, "FOUND") == 0){
  558. printf("\nEntry Not Found :\(");
  559. }
  560.  
  561. puts(CYAN "\n\n\nPress any key to go back to Admin Panel" RESET);
  562. getch();
  563. adminMenu();
  564. }
  565. // Show Entry/Entries Matching Area
  566. void searchByArea(){
  567. pageTitle("Search By Area");
  568.  
  569. // Write code Here
  570. Entries *EntriesArr = readFromFile();
  571.  
  572. char area[20];
  573. int EntriesNum = readNumOfEntriesFromFile();
  574. puts("Enter 'Area' of the Entries to Search.");
  575. gets(area);
  576. char oldArea[20];
  577. int count = 0;
  578.  
  579. for(int i=0; i<EntriesNum; i++){
  580. strcpy(oldArea, EntriesArr[i].area);
  581.  
  582. if(strcmp(strupr(oldArea), strupr(area)) == 0){
  583. puts("\n---------------------------------");
  584. printf("Name: %s",EntriesArr[i].name);
  585. puts("");
  586. printf("Usage: %s",EntriesArr[i].usage);
  587. puts("");
  588. printf("Connection: %s",EntriesArr[i].connection);
  589. puts("");
  590. printf("Area: %s",EntriesArr[i].area);
  591. puts("");
  592. printf("Age: %d ", EntriesArr[i].age);
  593. puts("");
  594. printf("Hours: %.1f ", EntriesArr[i].hours);
  595. puts("\n---------------------------------");
  596. } else count++;
  597. }
  598.  
  599. if(count == EntriesNum){
  600. printf("\nNo Entries From This Area :\(");
  601. }
  602.  
  603. puts(CYAN "\n\n\nPress any key to go back to Admin Panel" RESET);
  604. getch();
  605. adminMenu();
  606. }
  607. // Show Entry/Entries Matching Age Interval
  608. void searchByAge(){
  609. pageTitle("Search By Age Interval");
  610.  
  611. // Write code Here
  612. Entries *EntriesArr = readFromFile();
  613.  
  614. int min, max;
  615. int EntriesNum = readNumOfEntriesFromFile();
  616. puts("Enter Minimum Age");
  617. scanf("%d", &min);
  618. puts("Enter Maximum Age");
  619. scanf("%d", &max);
  620. int count = 0;
  621.  
  622. for(int i=0; i<EntriesNum; i++){
  623. if(min < EntriesArr[i].age && EntriesArr[i].age < max){
  624. puts("\n---------------------------------");
  625. printf("Name: %s",EntriesArr[i].name);
  626. puts("");
  627. printf("Usage: %s",EntriesArr[i].usage);
  628. puts("");
  629. printf("Connection: %s",EntriesArr[i].connection);
  630. puts("");
  631. printf("Area: %s",EntriesArr[i].area);
  632. puts("");
  633. printf("Age: %d ", EntriesArr[i].age);
  634. puts("");
  635. printf("Hours: %.1f ", EntriesArr[i].hours);
  636. puts("\n---------------------------------");
  637. } else count++;
  638. }
  639.  
  640. if(count == EntriesNum){
  641. printf("\nNo Entries From This Age Interval:\(");
  642. }
  643.  
  644. puts(CYAN "\n\n\nPress any key to go back to Admin Panel" RESET);
  645. getch();
  646. adminMenu();
  647. }
  648. // Compare All Areas Usage by Average of Users From Each Area
  649. void compareUsageByArea(){
  650. pageTitle("Comparison of Usage By Area on Average");
  651.  
  652. // Write code Here
  653.  
  654. float Bashundhara = 0, Mirpur = 0, Uttara = 0, Dhanmondi = 0, Banani = 0, Others = 0;
  655.  
  656. int BashundharaC = 0, MirpurC = 0, UttaraC = 0, DhanmondiC = 0, BananiC = 0, OthersC = 0;
  657.  
  658.  
  659. Entries *EntriesArr = readFromFile();
  660.  
  661. for(int i=0; i<readNumOfEntriesFromFile(); i++){
  662. if(strcmp(EntriesArr[i].area, "Bashundhara") == 0){
  663. BashundharaC++;
  664. Bashundhara += EntriesArr[i].hours;
  665. }
  666. if(strcmp(EntriesArr[i].area, "Mirpur") == 0){
  667. MirpurC++;
  668. Mirpur += EntriesArr[i].hours;
  669. }
  670. if(strcmp(EntriesArr[i].area, "Uttara") == 0){
  671. UttaraC++;
  672. Uttara += EntriesArr[i].hours;
  673. }if(strcmp(EntriesArr[i].area, "Dhanmondi") == 0){
  674. DhanmondiC++;
  675. Dhanmondi += EntriesArr[i].hours;
  676. }if(strcmp(EntriesArr[i].area, "Banani") == 0){
  677. BananiC++;
  678. Banani += EntriesArr[i].hours;
  679. }if(strcmp(EntriesArr[i].area, "Others") == 0){
  680. OthersC++;
  681. Others += EntriesArr[i].hours;
  682. }
  683. }
  684.  
  685. if(BashundharaC > 0) Bashundhara = Bashundhara/BashundharaC;
  686. if(MirpurC > 0) Mirpur = Mirpur/MirpurC;
  687. if(UttaraC > 0) Uttara = Uttara/UttaraC;
  688. if(DhanmondiC > 0) Dhanmondi = Dhanmondi/DhanmondiC;
  689. if(BananiC > 0) Banani = Banani/BananiC;
  690. if(OthersC > 0) Others = Others/OthersC;
  691.  
  692. puts("Bashundhara Mirpur Uttara Dhanmondi Banani Others");
  693. printf("%.1f Hours \t%.1f Hours \t%.1f Hours \t%.1f Hours \t%.1f Hours \t%.1f Hours \t", Bashundhara, Mirpur, Uttara, Dhanmondi, Banani, Others);
  694.  
  695. puts(CYAN "\n\n\nPress any key to go back to Admin Panel" RESET);
  696. getch();
  697. adminMenu();
  698. }
  699. // Show Age vs Hours Barchart
  700. void barChartAgeVsHours(){
  701. pageTitle("Bar Chart Age vs Hours");
  702.  
  703. // Write code Here
  704. Entries *EntriesArr = readFromFile();
  705. int EntriesNum = readNumOfEntriesFromFile();
  706. float ageHoursArr[5] = {0, 0, 0, 0, 0};
  707. int ageCountArr[5] = {0, 0, 0, 0, 0};
  708.  
  709. for(int i=0; i<EntriesNum; i++){
  710. if(EntriesArr[i].age >= 0 && EntriesArr[i].age <=10) { ageHoursArr[0]+=EntriesArr[i].hours; ageCountArr[0]++; }
  711. if(EntriesArr[i].age >= 11 && EntriesArr[i].age <=15) { ageHoursArr[1]+=EntriesArr[i].hours; ageCountArr[1]++; }
  712. if(EntriesArr[i].age >= 16 && EntriesArr[i].age <=20) { ageHoursArr[2]+=EntriesArr[i].hours; ageCountArr[2]++; }
  713. if(EntriesArr[i].age >= 21 && EntriesArr[i].age <=30) { ageHoursArr[3]+=EntriesArr[i].hours; ageCountArr[3]++; }
  714. if(EntriesArr[i].age >= 30 && EntriesArr[i].age <=100) { ageHoursArr[4]+=EntriesArr[i].hours; ageCountArr[4]++; }
  715. }
  716.  
  717. for(int i=0; i<5; i++){
  718. ageHoursArr[i] = (float)ageHoursArr[i]/ageCountArr[i]/24*100;
  719. }
  720.  
  721.  
  722.  
  723. printf(" AGE \n");
  724. printf(RESET "-------------------------------------------------------------------------------------------------------------\n");
  725. for(int i=0; i<5; i++){
  726. printf(RESET "");
  727. switch(i){
  728. case 0: printf("1 to 10 ");
  729. break;
  730. case 1: printf("11 to 15 ");
  731. break;
  732. case 2: printf("16 to 20 ");
  733. break;
  734. case 3: printf("20 to 30 ");
  735. break;
  736. case 4: printf("30+ ");
  737. break;
  738. }
  739.  
  740. if(i == 0) printf(RED);
  741. if(i == 1) printf(YELLOW);
  742. if(i == 2) printf(MAGENTA);
  743. if(i == 3) printf(BLUE);
  744. if(i == 4) printf(GREEN);
  745.  
  746.  
  747. for(int j=0; j<ageHoursArr[i]; j++){
  748. printf("*");
  749. }
  750. puts("");
  751. for(int j=0; j<100+9; j++){
  752. printf(RESET"-");
  753. }
  754. printf("\n");
  755. }
  756. printf("HOURS -> |00||01||02||03||04||05||06||07||08||09||10||11||12||13||14||15||16||17||18||18||20||21||22||23||24|\n");
  757. printf("PER DAY\n");
  758.  
  759. puts(CYAN "\n\n\nPress any key to go back to Admin Panel" RESET);
  760. getch();
  761. adminMenu();
  762. }
  763. // Pyramid of Internet Connection Usage from Low to High
  764. void pyramidConnection(){
  765. pageTitle("Pyramid of Connection");
  766.  
  767. // Write code
  768. char conArr[5][20] = {"Broadband", "WiFI", "3G", "4G", "Others"};
  769. int conCountsArr[5] = {0, 0, 0, 0, 0};
  770.  
  771. Entries *EntriesArr = readFromFile();
  772.  
  773. for(int i=0; i<readNumOfEntriesFromFile(); i++){
  774. if(strcmp(EntriesArr[i].connection, "Broadband") == 0){
  775. conCountsArr[0]++;
  776. }
  777. if(strcmp(EntriesArr[i].connection, "WiFi") == 0){
  778. conCountsArr[1]++;
  779. }
  780. if(strcmp(EntriesArr[i].connection, "3G") == 0){
  781. conCountsArr[2]++;
  782. }
  783. if(strcmp(EntriesArr[i].connection, "4G") == 0){
  784. conCountsArr[3]++;
  785. }
  786. if(strcmp(EntriesArr[i].connection, "Others") == 0){
  787. conCountsArr[4]++;
  788. }
  789. }
  790.  
  791. int i, j, a;
  792. char aa[20];
  793. for (i = 0; i < 5; ++i){
  794. for (j = i + 1; j < 5; ++j){
  795. if (conCountsArr[i] < conCountsArr[j]){
  796. a = conCountsArr[i];
  797. strcpy(aa, conArr[i]);
  798.  
  799. conCountsArr[i] = conCountsArr[j];
  800. strcpy(conArr[i], conArr[j]);
  801.  
  802. conCountsArr[j] = a;
  803. strcpy(conArr[j], aa);
  804. }
  805. }
  806. }
  807.  
  808. int space, rows = 15, k=0;
  809. for(i=1; i<=rows; i++){
  810. k=0;
  811. for(space=1; space<=rows-i; space++){
  812. printf(" ");
  813. }
  814. while(k != 2*i-1){
  815. if(i>0) printf(RED);
  816. if(i>3) printf(YELLOW);
  817. if(i>6) printf(MAGENTA);
  818. if(i>9) printf(BLUE);
  819. if(i>12) printf(GREEN);
  820. printf("* ");
  821. printf(RESET);
  822. k++;
  823. }
  824. k=0;
  825. for(space=1; space<=rows-i; space++){
  826. printf(" ");
  827. }
  828. printf(" ");
  829. if(i==2) printf(RED "%s", conArr[0]);
  830. if(i==5) printf(YELLOW "%s", conArr[1]);
  831. if(i==8) printf(MAGENTA "%s", conArr[2]);
  832. if(i==11) printf(BLUE "%s", conArr[3]);
  833. if(i==14) printf(GREEN "%s", conArr[4]);
  834. printf("\n");
  835. }
  836.  
  837. puts(CYAN "\n\n\nPress any key to go back to Admin Panel" RESET);
  838. getch();
  839. adminMenu();
  840. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement