Guest User

Untitled

a guest
Mar 6th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. //Jillian Woodard
  2. //COP 3223
  3. //This program is designed to incoorperate 3 files into a database
  4. //that the user can use a menu to retrieve the desired data from
  5. //the 3 files.
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9.  
  10. int MAX_ENTRIES=37;
  11.  
  12. //Declaring the data structures
  13. struct record {
  14. char name[37][20];
  15. int grade;
  16. int age;
  17. };
  18.  
  19.  
  20.  
  21.  
  22. //Intializing Functions
  23. void option1 (struct record table[]);
  24. void option2 (struct record table[]);
  25. void option3 (struct record table[]);
  26. void option4 (struct record table[]);
  27. //void Simple_Sort(struct record table[], int length);
  28. //void Move_Max(struct record table[], int max_index);
  29. //void swap(struct record table[]);
  30. //void Print_Array(int values[], int length);
  31.  
  32. int main()
  33. {
  34.  
  35.  
  36. int choice;
  37. int i=0;
  38.  
  39.  
  40. //Reading Files
  41.  
  42.  
  43. struct record table[MAX_ENTRIES];
  44.  
  45. FILE *fp1,*fp2, *fp3;
  46. fp1= fopen ("name.txt", "r");
  47. fp2= fopen( "grade.txt", "r");
  48. fp3= fopen("age.txt.", "r");
  49.  
  50.  
  51. //Read in Files
  52.  
  53. for (i =0; i<MAX_ENTRIES; i++)
  54. {
  55. fscanf( fp1, "%s", &table[i].name);
  56. fscanf( fp2, "%d", &table[i].grade );
  57. fscanf( fp3, "%d", &table[i].age );
  58.  
  59. // printf ("%s\n", table[i].name);
  60. }
  61. system("pause");
  62.  
  63.  
  64. choice=0;
  65. while (choice !=8)
  66. {
  67. //Menu Options
  68. printf("What would you like to do?\n");
  69. printf("1. List all people above a certain grade\n");
  70. printf("2. List all people above a certain age\n");
  71. printf("3. List all people above a certain age and above a certain grade\n");
  72. printf("4. List all data\n");
  73. printf("5. Sort by age.\n");
  74. printf("6. Sort by Grade\n");
  75. printf("7. Sort by Name.\n");
  76. printf("8. Exit\n");
  77. scanf("%d", &choice);
  78.  
  79. //Reading in Option and Processing Through Functions
  80. if (choice==1)
  81. {
  82. option1 (table);
  83. }
  84.  
  85.  
  86. else if (choice==2)
  87. {
  88. option2 (table);
  89. }
  90.  
  91. else if (choice==3)
  92. {
  93. option3 (table);
  94. }
  95.  
  96. else if (choice==4)
  97. {
  98. option4 (table);
  99. }
  100.  
  101. /* else if (choice==5)
  102. {
  103. Simple_Sort (table, MAX_ENTRIES);
  104. }*/
  105. return 0;
  106.  
  107.  
  108.  
  109. system("pause");
  110. }}
  111.  
  112.  
  113. //Functions
  114.  
  115. // Option 1 Function
  116. void option1 (struct record table[])
  117. {
  118. int i=0, grademin;
  119. printf("Please enter a minimum grade.\n");
  120. scanf("%d", &grademin);
  121.  
  122. for (i=0;i<MAX_ENTRIES;i++)
  123. {
  124. if (table[i].grade>grademin)
  125. {
  126. printf("%s:", table[i].name);
  127. printf("%5d", table[i].grade);
  128. printf("%5d\n", table[i].age);
  129.  
  130. }
  131. }
  132.  
  133. system("pause");
  134.  
  135. }
  136. //Option Two Function
  137.  
  138. void option2 (struct record table[])
  139. {
  140. int i=0, agemin;
  141. printf("Please enter a minimum age.\n");
  142. scanf("%d", &agemin);
  143.  
  144. for (i=0;i<MAX_ENTRIES;i++)
  145. {
  146. if (table[i].age>agemin)
  147. {
  148. printf("%s:", table[i].name);
  149. printf("%5d", table[i].grade);
  150. printf("%5d\n", table[i].age);
  151.  
  152. }
  153. }
  154.  
  155.  
  156. }
  157.  
  158. //Option 3 Function
  159. void option3 (struct record table[])
  160. {
  161. int i=0, agemin, grademin;
  162. printf("Please enter a minimum age.\n");
  163. scanf("%d", &agemin);
  164. printf("Please enter minimum grade.\n");
  165. scanf("%d", &grademin);
  166.  
  167. for (i=0;i<MAX_ENTRIES;i++)
  168. {
  169. if ((table[i].age>agemin) && (table[i].grade>grademin))
  170. {
  171. printf("%15s\t:", table[i].name);
  172. printf("%5d\t", table[i].grade);
  173. printf("%5d\n", table[i].age);
  174.  
  175. }
  176. }
  177.  
  178. system("pause");
  179. }
  180.  
  181. //Option Four Function
  182. void option4 (struct record table[])
  183. {
  184. int i=0;
  185.  
  186. for (i=0; i<MAX_ENTRIES ; i++)
  187. {
  188. printf("%s:", table[i].name);
  189. printf("%5d", table[i].grade);
  190. printf("%5d\n", table[i].age);
  191. }
  192. system("pause");
  193. }
Add Comment
Please, Sign In to add comment