Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Jillian Woodard
- //COP 3223
- //This program is designed to incoorperate 3 files into a database
- //that the user can use a menu to retrieve the desired data from
- //the 3 files.
- #include <stdio.h>
- #include <stdlib.h>
- int MAX_ENTRIES=37;
- //Declaring the data structures
- struct record {
- char name[37][20];
- int grade;
- int age;
- };
- //Intializing Functions
- void option1 (struct record table[]);
- void option2 (struct record table[]);
- void option3 (struct record table[]);
- void option4 (struct record table[]);
- //void Simple_Sort(struct record table[], int length);
- //void Move_Max(struct record table[], int max_index);
- //void swap(struct record table[]);
- //void Print_Array(int values[], int length);
- int main()
- {
- int choice;
- int i=0;
- //Reading Files
- struct record table[MAX_ENTRIES];
- FILE *fp1,*fp2, *fp3;
- fp1= fopen ("name.txt", "r");
- fp2= fopen( "grade.txt", "r");
- fp3= fopen("age.txt.", "r");
- //Read in Files
- for (i =0; i<MAX_ENTRIES; i++)
- {
- fscanf( fp1, "%s", &table[i].name);
- fscanf( fp2, "%d", &table[i].grade );
- fscanf( fp3, "%d", &table[i].age );
- // printf ("%s\n", table[i].name);
- }
- system("pause");
- choice=0;
- while (choice !=8)
- {
- //Menu Options
- printf("What would you like to do?\n");
- printf("1. List all people above a certain grade\n");
- printf("2. List all people above a certain age\n");
- printf("3. List all people above a certain age and above a certain grade\n");
- printf("4. List all data\n");
- printf("5. Sort by age.\n");
- printf("6. Sort by Grade\n");
- printf("7. Sort by Name.\n");
- printf("8. Exit\n");
- scanf("%d", &choice);
- //Reading in Option and Processing Through Functions
- if (choice==1)
- {
- option1 (table);
- }
- else if (choice==2)
- {
- option2 (table);
- }
- else if (choice==3)
- {
- option3 (table);
- }
- else if (choice==4)
- {
- option4 (table);
- }
- /* else if (choice==5)
- {
- Simple_Sort (table, MAX_ENTRIES);
- }*/
- return 0;
- system("pause");
- }}
- //Functions
- // Option 1 Function
- void option1 (struct record table[])
- {
- int i=0, grademin;
- printf("Please enter a minimum grade.\n");
- scanf("%d", &grademin);
- for (i=0;i<MAX_ENTRIES;i++)
- {
- if (table[i].grade>grademin)
- {
- printf("%s:", table[i].name);
- printf("%5d", table[i].grade);
- printf("%5d\n", table[i].age);
- }
- }
- system("pause");
- }
- //Option Two Function
- void option2 (struct record table[])
- {
- int i=0, agemin;
- printf("Please enter a minimum age.\n");
- scanf("%d", &agemin);
- for (i=0;i<MAX_ENTRIES;i++)
- {
- if (table[i].age>agemin)
- {
- printf("%s:", table[i].name);
- printf("%5d", table[i].grade);
- printf("%5d\n", table[i].age);
- }
- }
- }
- //Option 3 Function
- void option3 (struct record table[])
- {
- int i=0, agemin, grademin;
- printf("Please enter a minimum age.\n");
- scanf("%d", &agemin);
- printf("Please enter minimum grade.\n");
- scanf("%d", &grademin);
- for (i=0;i<MAX_ENTRIES;i++)
- {
- if ((table[i].age>agemin) && (table[i].grade>grademin))
- {
- printf("%15s\t:", table[i].name);
- printf("%5d\t", table[i].grade);
- printf("%5d\n", table[i].age);
- }
- }
- system("pause");
- }
- //Option Four Function
- void option4 (struct record table[])
- {
- int i=0;
- for (i=0; i<MAX_ENTRIES ; i++)
- {
- printf("%s:", table[i].name);
- printf("%5d", table[i].grade);
- printf("%5d\n", table[i].age);
- }
- system("pause");
- }
Add Comment
Please, Sign In to add comment