Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <string>
- using namespace std;
- struct PlayerInfo {
- string FName;
- string LName;
- string position;
- int touchdowns;
- int catches;
- int passingYards;
- int rushingYards;
- int recYards;
- };
- void showMenu(); //
- void InputData(PlayerInfo players[]); //
- void SaveData(PlayerInfo players[]); //
- void printPlayerData(PlayerInfo players[], int i); //
- void printData(PlayerInfo players[]); //
- int searchArray(PlayerInfo players[], string lName, string fname); //
- void updateRecYards(PlayerInfo p[], int r, int playerIndex); //
- void updateTouchDowns(PlayerInfo p[], int td, int playerIndex); //
- void updateCatches(PlayerInfo p[], int catches, int playerIndex); //
- void updatePassingYards(PlayerInfo p[], int passingYards, int playerIndex); //
- void updateRushingYards(PlayerInfo p[], int rushingYards, int playerIndex); //
- int main()
- {
- PlayerInfo players[11];
- int playerIndex;
- string LName, FName;
- int choice;
- int numOfTouchDowns, catches, numOfPassingYards, numOfRecYards, numOfRushingYards;
- InputData(players);
- do {
- cout << endl;
- showMenu();
- cin >> choice;
- cout << endl;
- switch (choice) {
- case 1:
- cout << endl
- << "Enter player's last name to search for: ";
- cin >> LName;
- cout << endl
- << "Enter player's first name to search for: ";
- cin >> FName;
- playerIndex = searchArray(players, LName, FName);
- if (playerIndex == 99) {
- cout << "No such player found";
- }
- else
- printPlayerData(players, playerIndex);
- break;
- case 2:
- printData(players);
- break;
- case 3:
- cout << endl
- << "Enter player's last name to search for: ";
- cin >> LName;
- cout << endl
- << "Enter player's first name to search for: ";
- cin >> FName;
- playerIndex = searchArray(players, LName, FName);
- cout << "Enter number of touchdowns to be added: ";
- cin >> numOfTouchDowns;
- if (playerIndex == 99) {
- cout << "No such player found";
- }
- else
- updateTouchDowns(players, numOfTouchDowns, playerIndex);
- break;
- case 4:
- cout << endl
- << "Enter player's last name to search for: ";
- cin >> LName;
- cout << endl
- << "Enter player's first name to search for: ";
- cin >> FName;
- playerIndex = searchArray(players, LName, FName);
- cout << "Enter number of catches to be added: ";
- cin >> catches;
- if (playerIndex == 99) {
- cout << "No such player found";
- }
- else
- updateCatches(players, catches, playerIndex);
- break;
- case 5:
- cout << endl
- << "Enter player's last name to search for: ";
- cin >> LName;
- cout << endl
- << "Enter player's first name to search for: ";
- cin >> FName;
- playerIndex = searchArray(players, LName, FName);
- cout << "Enter number of passing yards to be added: ";
- cin >> numOfPassingYards;
- if (playerIndex == 99) {
- cout << "No such player found";
- }
- else
- updatePassingYards(players, numOfPassingYards, playerIndex);
- break;
- case 6:
- cout << endl
- << "Enter player's last name to search for: ";
- cin >> LName;
- cout << endl
- << "Enter player's first name to search for: ";
- cin >> FName;
- playerIndex = searchArray(players, LName, FName);
- cout << "Enter number of rushing yards to be added: ";
- cin >> numOfRushingYards;
- if (playerIndex == 99) {
- cout << "No such player found";
- }
- else
- updateRushingYards(players, numOfRushingYards, playerIndex);
- break;
- case 7:
- cout << endl
- << "Enter player's last name to search for: ";
- cin >> LName;
- cout << endl
- << "Enter player's first name to search for: ";
- cin >> FName;
- playerIndex = searchArray(players, LName, FName);
- cout << "Enter number of receiving yards to be added: ";
- cin >> numOfRecYards;
- if (playerIndex == 99) {
- cout << "No such player found";
- }
- else
- updateRecYards(players, numOfRecYards, playerIndex);
- break;
- case 99:
- break;
- default:
- cout << "Invalid selection." << endl;
- }
- } while (choice != 99);
- char response;
- cout << "Would you like to save data: (y,Y/n,N) ";
- cin >> response;
- cout << endl;
- if (response == 'y' || response == 'Y') {
- SaveData(players);
- }
- return 0;
- }
- void showMenu()
- {
- cout << "\nSelect one of the following options: " << endl
- << "1: To print a player's data" << endl
- << "2: To print the entire data" << endl
- << "3: To update a player's touchdowns" << endl
- << "4: To update a player's number of catches" << endl
- << "5: To update a player's passing yards" << endl
- << "6: To update a player's rushing yards" << endl
- << "7: To update a player's receiving yards" << endl
- << "99: To quit the program" << endl
- << endl;
- };
- int searchArray(PlayerInfo players[], string LName, string FName)
- {
- for (int i = 0; i < 11; i++) {
- if (LName == players[i].LName) {
- if (FName == players[i].FName) {
- return i;
- }
- }
- }
- return 99;
- };
- void updateTouchDowns(PlayerInfo p[], int td, int playerIndex)
- {
- p[playerIndex].touchdowns = p[playerIndex].touchdowns + td;
- };
- void updateRecYards(PlayerInfo p[], int recYards, int playerIndex)
- {
- p[playerIndex].recYards = p[playerIndex].recYards + recYards;
- };
- void updateCatches(PlayerInfo p[], int catches, int playerIndex)
- {
- p[playerIndex].catches = p[playerIndex].catches + catches;
- };
- void updatePassingYards(PlayerInfo p[], int passingYards, int playerIndex)
- {
- p[playerIndex].passingYards = p[playerIndex].passingYards + passingYards;
- };
- void updateRushingYards(PlayerInfo p[], int rushingYards, int playerIndex)
- {
- p[playerIndex].rushingYards = p[playerIndex].rushingYards + rushingYards;
- };
- void printData(PlayerInfo players[])
- {
- for (int i = 0; i < 11; i++) {
- cout << players[i].FName << ' '
- << players[i].LName << ' '
- << players[i].position << ' '
- << players[i].touchdowns << ' '
- << players[i].catches << ' '
- << players[i].passingYards << ' '
- << players[i].rushingYards << ' '
- << players[i].recYards << ' '
- << endl;
- }
- };
- void printPlayerData(PlayerInfo players[], int i)
- {
- cout << players[i].FName << ' '
- << players[i].LName << ' '
- << players[i].position << ' '
- << players[i].touchdowns << ' '
- << players[i].catches << ' '
- << players[i].passingYards << ' '
- << players[i].rushingYards << ' '
- << players[i].recYards << ' '
- << endl;
- };
- void InputData(PlayerInfo players[])
- {
- ifstream infile;
- infile.open("footballdatafile.txt");
- for (int i = 0; i < 11; i++) {
- infile >> players[i].FName
- >> players[i].LName
- >> players[i].position
- >> players[i].touchdowns
- >> players[i].catches
- >> players[i].passingYards
- >> players[i].rushingYards
- >> players[i].recYards;
- }
- infile.close();
- };
- void SaveData(PlayerInfo players[])
- {
- ofstream outfile;
- outfile.open("footballdatafile.txt");
- for (int i = 0; i < 11; i++) {
- outfile << players[i].FName << ' '
- << players[i].LName << ' '
- << players[i].position << ' '
- << players[i].touchdowns << ' '
- << players[i].catches << ' '
- << players[i].passingYards << ' '
- << players[i].rushingYards << ' '
- << players[i].recYards << endl;
- }
- outfile.close();
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement