Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
8.6 kB
7
Indexable
Never
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

struct footballPlayer 
    {
        string player_name;
        int position;
        int touch_down;
        int number_of_catches;
        int passing_yards;
        int receiving_yards;
        int rushing_yards;
    };

footballPlayer createPlayer
(string name, int pos, int td, int catches, 
int passing_yds, int rec_yards, int rush_yards)
{
    

//Process

footballPlayer player;
player.player_name = name;
player.position = pos;
player.touch_down = td;
player.number_of_catches = catches;
player.passing_yards = passing_yds;
player.receiving_yards = rec_yards;
player.rushing_yards = rush_yards;

return player;
}

footballPlayer inputData() {
    
footballPlayer player;
cout << "Enter football player name: "; cout << endl;
cin >> player.player_name; cout << endl;
cout << "Position: "; 
cin >> player.position; cout<<endl;  
cout << "Number of touchdowns: "; 
cin >> player.touch_down; cout << endl;  
cout << "Number of catches" ; 
cin >> player.number_of_catches; cout << endl;  
cout << "Number of passing yards"; 
cin >> player.passing_yards; cout << endl;  
cout << "Number of receiving yards"; 
cin >> player.receiving_yards; cout << endl;  
cout << "Number of rushing yards"; 
cin >> player.rushing_yards; cout << endl;     

return player;
}

void outputData(footballPlayer player) {
    
cout << "Enter football player name: " << player.player_name << endl;
cout << "Position: " << player.position << endl;
cout << "Number of touchdowns: " << player.touch_down << endl;
cout << "Number of catches" << player.number_of_catches << endl;
cout << "Number of passing yards" << player.passing_yards << endl;
cout << "Number of receiving yards" << player.receiving_yards << endl;
cout << "Number of rushing yards" << player.rushing_yards << endl;
}

int main() {

//creating an array that can hold 10 football players 
footballPlayer players[10] = {}; 


ifstream inFile("Ch9_Ex7Data.txt", ios::in);
if (!inFile){
    cout << "Invalid file";
    exit(1);
}

string player_name;
int position;
int touch_down;
int number_of_catches;
int passing_yards;
int receiving_yards;
int rushing_yards;

int option = 0;
while (option!=0){
cout << "Select one of the following options:";
cout << endl;                               
cout << "1: To print a player's data";
cout << endl;                                         
cout << "2: To print the entire data";
cout << endl;                                          
cout << "3: To update a player's touch downs";
cout << endl;
cout << "4: To update a player's number of catches";
cout << endl;                            
cout << "5: To update a player's passing yards"; 
cout << endl;                              
cout << "6: To update a player's receiving yards";  
cout << endl;                            
cout << "7: To update a player's rushing yards";  
cout << endl;                              
cout << "99: To quit the program";    
cout << endl;
cin >> option;         
}


                                
////////////////////////////
/////MENU OPTION CHOICES////
////////////////////////////

string name;

switch (option){

/////////////////////////////
/////Display player data/////
/////////////////////////////
    case 1:
    cout << "Enter a player's name: ";
    cin >> name;
    for (int i =0; i < 10; i++){
        if(name == footballPlayer[i].player_name)
        {
        cout << "Name: " << footballPlayer[i].player_name; 
        << " Position: " << footballPlayer[i].position; 
        << " Touch Downs: " << footballPlayer[i].touch_down; 
        << " Number of Catches: " << footballPlayer[i].number_of_catches; 
        << " Passing Yards: " << footballPlayer[i].passing_yards;
        << "Receiving Yards: " << footballPlayer[i].receiving_yards; 
        << " Rushing Yards: " << footballPlayer[i].rushing_yards;
        cout << endl;
        }
        }
        break;


/////////////////////////////
/////Display entire data/////
/////////////////////////////
    case 2:
 cout << "Enter a player's name: ";
    cin >> name;
    for (int i =0; i < 10; i++){
        if(name == footballPlayer[i].player_name)
        {
        cout << "Name: " << footballPlayer[i].player_name; 
        << " Position: " << footballPlayer[i].position; 
        << " Touch Downs: " << footballPlayer[i].touch_down; 
        << " Number of Catches: " << footballPlayer[i].number_of_catches; 
        << " Passing Yards: " << footballPlayer[i].passing_yards;
        << "Receiving Yards: " << footballPlayer[i].receiving_yards; 
        << " Rushing Yards: " << footballPlayer[i].rushing_yards;
        cout << endl;
        }
        }
        break;



////////////////////////////////
//Update players touch down/////
////////////////////////////////
     case 3:
    cout << "Enter a player's name: ";
    cin >> name;
     for (int i =0; i < 10; i++) {
        if(position == footballPlayer[i].position){
        cout << "Name: " << footballPlayer[i].player_name 
        << " Position: " << footballPlayer[i].position 
        << " Touch Downs: " << footballPlayer[i].touch_down 
        << " Number of Catches: " << footballPlayer[i].number_of_catches 
        << " Passing Yards: " << footballPlayer[i].passing_yards
        << "Receiving Yards: " << footballPlayer[i].receiving_yards 
        << " Rushing Yards: " << footballPlayer[i].rushing_yards;
        cout << endl;
        }
     }
     break;

/////////////////////////////
// Update number of Catches//
/////////////////////////////
case 4:
     for (int i =0; i < 10; i++) {
        if(number_of_catches == footballPlayer[i].number_of_catches)
        {
        cout << "Name: " << footballPlayer[i].player_name 
        << " Position: " << footballPlayer[i].position 
        << " Touch Downs: " << footballPlayer[i].touch_down 
        << " Number of Catches: " << footballPlayer[i].number_of_catches 
        << " Passing Yards: " << footballPlayer[i].passing_yards
        << "Receiving Yards: " << footballPlayer[i].receiving_yards 
        << " Rushing Yards: " << footballPlayer[i].rushing_yards;
        cout << endl;
        }
     }
     break;

/////////////////////////////
///Update passing yards//////
/////////////////////////////
    case 5:
     for (int i =0; i < 10; i++) {
     {
        if(passing_yards == footballPlayer[i].passing_yards)
        cout << "Name: " << footballPlayer[i].player_name 
        << " Position: " << footballPlayer[i].position 
        << " Touch Downs: " << footballPlayer[i].touch_down 
        << " Number of Catches: " << footballPlayer[i].number_of_catches 
        << " Passing Yards: " << footballPlayer[i].passing_yards
        << "Receiving Yards: " << footballPlayer[i].receiving_yards 
        << " Rushing Yards: " << footballPlayer[i].rushing_yards;
        cout << endl;
        }
     }
     break;

/////////////////////////////
///Update receivingYards/////
/////////////////////////////
    case 6:
     for (int i =0; i < 10; i++) {
        if(receiving_yards == footballPlayer[i].receiving_yards)
        {
        cout << "Name: " << footballPlayer[i].player_name 
        << " Position: " << footballPlayer[i].position 
        << " Touch Downs: " << footballPlayer[i].touch_down 
        << " Number of Catches: " << footballPlayer[i].number_of_catches 
        << " Passing Yards: " << footballPlayer[i].passing_yards
        << "Receiving Yards: " << footballPlayer[i].receiving_yards 
        << " Rushing Yards: " << footballPlayer[i].rushing_yards;
        cout << endl;
        }
     }
     break;


///////////////////////////////
/////Update rushing yards//////
///////////////////////////////
    case 7:
     for (int i =0; i < 10; i++) {
        if(rushing_yards == footballPlayer[i].rushing_yards)
        {
        cout << "Name: " << footballPlayer[i].player_name 
        << " Position: " << footballPlayer[i].position 
        << " Touch Downs: " << footballPlayer[i].touch_down 
        << " Number of Catches: " << footballPlayer[i].number_of_catches 
        << " Passing Yards: " << footballPlayer[i].passing_yards
        << "Receiving Yards: " << footballPlayer[i].receiving_yards 
        << " Rushing Yards: " << footballPlayer[i].rushing_yards;
        cout << endl;
        }
     }
     break;

//Quit the program
    case 99:
        break;
     


/////////////////
///Saving Data///
///////////////// 

char response;
cout << "Would you like to save data: (y,Y/n,N) N";
cin >> response;
cout << endl;

if (response == 'y' || 'Y'){
inFile.close();    
}

    return 0;
}
}
Leave a Comment