Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct Player
- {
- char name[100];
- int age;
- char playerRole[100];
- int match;
- int totalRuns;
- int highestRun;
- };
- void addPlayer(FILE *file, struct Player *playerList, int n)
- {
- char newline;
- for (int i = 0; i < n; i++)
- {
- fscanf(file, "%c", &newline);
- fscanf(file, "%c", &newline);
- fgets(playerList[i].name, 100, file);
- fscanf(file, "%d", &playerList[i].age);
- fscanf(file, "%c", &newline);
- fgets(playerList[i].playerRole, 100, file);
- fscanf(file, "%d", &playerList[i].match);
- fscanf(file, "%d", &playerList[i].totalRuns);
- fscanf(file, "%d", &playerList[i].highestRun);
- }
- }
- void printPlayer(struct Player player)
- {
- printf("Full Name: %s", player.name);
- printf("Age: %d \n", player.age);
- printf("Player Role: %s", player.playerRole);
- printf("ODI Match: %d \n", player.match);
- printf("Total Runs: %d \n", player.totalRuns);
- printf("Highest Run: %d \n\n", player.highestRun);
- }
- void playerInfo(struct Player playerList[], char name[], int n)
- {
- int index;
- for (int i = 0; i < n; i++)
- {
- index = i;
- int j = -1;
- while (playerList[i].name[j] != '\0')
- {
- if (playerList[i].name != name[j])
- {
- index = -1;
- break;
- }
- {
- }
- j++;
- }
- if (index != -1)
- {
- break;
- }
- }
- printPlayer(playerList[index]);
- }
- void showAllPlayer(struct Player playerList[], int n)
- {
- printf("All player: \n\n");
- for (int i = 0; i < n; i++)
- {
- printf("\n--------Player %d--------\n", i + 1);
- printPlayer(playerList[i]);
- };
- }
- void mep(struct Player playerList[], int n)
- {
- printf("MOST Experienced Player: \n\n");
- int index = -1;
- int maxMatch = -1;
- for (int i = 0; i < n; i++)
- {
- if (playerList[i].match > maxMatch)
- {
- maxMatch = playerList[i].match;
- index = i;
- }
- }
- printPlayer(playerList[index]);
- }
- void ncp(struct Player playerList[], int n)
- {
- printf("New Commer Player: \n\n");
- int index = -1;
- int age = 999999;
- for (int i = 0; i < n; i++)
- {
- if (playerList[i].age < age)
- {
- age = playerList[i].age;
- index = i;
- }
- }
- printPlayer(playerList[index]);
- }
- void tsp(struct Player playerList[], int n)
- {
- printf("Top Scorer Player: \n\n");
- int index = -1;
- int totalRuns = -1;
- for (int i = 0; i < n; i++)
- {
- if (playerList[i].totalRuns > totalRuns)
- {
- totalRuns = playerList[i].totalRuns;
- index = i;
- }
- }
- printPlayer(playerList[index]);
- }
- void hhp(struct Player playerList[], int n)
- {
- printf("Hard Hitter Player: \n\n");
- int index = -1;
- int avgRun = -1;
- for (int i = 0; i < n; i++)
- {
- int temp = playerList[i].totalRuns / playerList[i].match;
- if (temp > avgRun)
- {
- avgRun = playerList[i].totalRuns;
- index = i;
- }
- }
- printPlayer(playerList[index]);
- }
- void hrtp(struct Player playerList[], int n)
- {
- printf("Highest Run Taker PlayerL \n\n");
- int index = -1;
- int highestRun = -1;
- for (int i = 0; i < n; i++)
- {
- if (playerList[i].highestRun > highestRun)
- {
- highestRun = playerList[i].highestRun;
- index = i;
- }
- }
- printPlayer(playerList[index]);
- }
- void mvp(struct Player playerList[], int n)
- {
- printf("MOST Valuable Player: \n\n");
- int index = -1;
- int value = -1;
- for (int i = 0; i < n; i++)
- {
- int age = playerList[i].age;
- int match = playerList[i].match;
- int totalRuns = playerList[i].totalRuns;
- int highestRun = playerList[i].highestRun;
- int j = 0;
- char playerRoll[100] = {'A', 'l', 'l', 'r', 'o', 'u', 'n', 'd', 'e', 'r'};
- int allRounderValue = 50;
- while (playerList[i].playerRole[j] != '\n')
- {
- if (playerRoll[j] != playerList[i].playerRole[j])
- {
- allRounderValue = 0;
- break;
- }
- j++;
- }
- int temp = age + match + totalRuns + highestRun + (totalRuns / match) + (highestRun / age) + allRounderValue;
- if (temp > value)
- {
- value = temp;
- index = i;
- }
- }
- printPlayer(playerList[index]);
- }
- void allRounder(struct Player playerList[], int n)
- {
- printf("Allrounders: \n\n");
- for (int i = 0; i < n; i++)
- {
- int j = 0;
- int index = i;
- char playerRoll[100] = {'A', 'l', 'l', 'r', 'o', 'u', 'n', 'd', 'e', 'r'};
- while (playerList[i].playerRole[j] != '\n')
- {
- if (playerRoll[j] != playerList[i].playerRole[j])
- {
- index = -1;
- break;
- }
- j++;
- }
- if (index != -1)
- {
- printPlayer(playerList[index]);
- }
- }
- }
- int main()
- {
- char fileName[100];
- printf("Enter File Name: ");
- scanf("%s", fileName);
- FILE *file;
- file = fopen(fileName, "r");
- int n;
- char name[100];
- struct Player playerList[100];
- fscanf(file, "%d", &n);
- addPlayer(file, playerList, n);
- int menu = 1;
- while (menu)
- {
- printf("1. All Players\n");
- printf("2. Show A Particular player information (Provide Player Name)\n");
- printf("3. Show the MOST Experienced Player(MEP) \n");
- printf("4. Show the New Commer Player(NCP)\n");
- printf("5. Show the Top Scorer Player(TSP)\n");
- printf("6. Show the Hard Hitter Player(HHP)\n");
- printf("7. Show the Highest Run Taker Player(HRTP)\n");
- printf("8. Show the MOST Valuable Player(MVP)\n");
- printf("9. Show the Allrounders\n");
- printf("10.Exit/Quit\n");
- scanf("%d", &menu);
- if (menu == 1)
- {
- showAllPlayer(playerList, n);
- }
- if (menu == 2)
- {
- playerInfo(playerList, name, n);
- }
- if (menu == 3)
- {
- mep(playerList, n);
- }
- if (menu == 4)
- {
- ncp(playerList, n);
- }
- if (menu == 5)
- {
- tsp(playerList, n);
- }
- if (menu == 6)
- {
- hhp(playerList, n);
- }
- if (menu == 7)
- {
- hrtp(playerList, n);
- }
- if (menu == 8)
- {
- mvp(playerList, n);
- }
- if (menu == 9)
- {
- allRounder(playerList, n);
- }
- if (menu == 10)
- {
- menu = 0;
- break;
- }
- }
- fclose(file);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement