Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in C++ language that declares a struct to store the data of a fo

ID: 3547563 • Letter: W

Question

Write a program in C++ language that declares a struct to store the data of a football player (player's name, player's position, number of touchdowns, number of catches, number of passing yards, number of receiving yards, and the number of rushing yards).  Declare an array of 10 components to store the data of 10 football players.  Your program must contain a function to input data and a function to output data.  Add functions to search the array to find the index of a specific player, and update the data of a player.  (You may assume that input data is stored in a file.)  Before the program terminates, give the user the option to save data in a file.  Your program should be menu driven, giving the user various choices.

Explanation / Answer

#include <iostream>
#include <conio.h>
using namespace std;
#define SIZE 10

typedef struct
{
char name[20];
int homeruns;
int hits;
}INFO;

INFO inputdata(void)
{
INFO temp;

cout<<"Enter name of Player: ";
cin>>temp.name;
cout<<"Enter the Player's number of homeruns: ";
cin>>temp.homeruns;
cout<<"Enter the Player's number of hits: ";
cin>>temp.hits;
cout<<" ";

return temp;
}

void outputdata(INFO s[])
{
for(int i=0;i<SIZE;i++)
{
cout<<i+1<<". "<<s[i].name;
cout<<" has "<<s[i].homeruns;
cout<<" homeruns and ";
cout<<s[i].hits<<" hits"<<endl;
}
}


int main(){
INFO info[SIZE];

for(int i=0;i<SIZE;i++)
{
info[i]=inputdata();
}
outputdata(info);

getch();
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote