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

Visual Studio 2010 C++ Write a program that declares a struct to store the data

ID: 663081 • Letter: V

Question

Visual Studio 2010 C++

Write a program that declares a struct to store the data of a football player (players name, players 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 <fstream>
using namespace std;

struct FOOTBALL_PLAYER { // Declare FOOTBALL_PLAYER struct type
char name[25]; //declaring struct variables
int position;   
int touchdowns;
int catches;
int passingYards;
int recievingYards;
int rushingYards;
  
} football;

//function prototypes declaring
void inputdata(FOOTBALL_PLAYER *pointer);
void output(FOOTBALL_PLAYER pointer);
void search(string name,FOOTBALL_PLAYER pointer);

int main() {
FOOTBALL_PLAYER pointer = new FOOTBALL_PLAYER[10]; //arrays of sructs
inputdata(pointer); //callinginput function
output(pointer); //calling output function
string name;
cout<<"Enter name to search"; //reading name ti search
cin>>name;
search(name,pointer);
cout<<" Writing to file";
ofstream fout("muoutput.txt"); //finally storinf ourput data to file
for(int i=0;i<10;i++){
fout<<" Name is"<<pointer[i].name;
fout<<"Position is"<<pointer[i].position;
fout<<" ouchdowns is"<<pointer[i].touchdowns;
fout<<"catches is"<<pointer[i].catches;
fout<<"passingYards is"<<pointer[i].passingYards;
fout<<" ecievingYards is"<<pointer[i].recievingYards;
fout<<" ushingYards is"<<pointer[i].rushingYards;
}
fout.close();
}
void inputdata(FOOTBALL_PLAYER *pointer){ //reading inputs from user for 10 members and storing into array
for(int i=0;i<10;i++){
cout<<" enter name";
cin>>pointer[i].name;
cout<<" enter position";
cin>>pointer[i].position;
cout<<" enter touchdowns";
cin>>pointer[i].touchdowns;
cout<<" enter catches";
cin>>pointer[i].catches;
cout<<" enter passingYards";
cin>>pointer[i].passingYards;
cout<<" enter recievingYards";
cin>>pointer[i].recievingYards;
cout<<" enter rushingYards";
cin>>pointer[i].rushingYards;
}
}

void output(FOOTBALL_PLAYER pointer){ //printing 10 members struct data to console
for(int i=0;i<10;i++){
cout<<" Name is"<<pointer[i].name;
cout<<"Position is"<<pointer[i].position;
cout<<" ouchdowns is"<<pointer[i].touchdowns;
cout<<"catches is"<<pointer[i].catches;
cout<<"passingYards is"<<pointer[i].passingYards;
cout<<" ecievingYards is"<<pointer[i].recievingYards;
cout<<" ushingYards is"<<pointer[i].rushingYards;
}
}
void search(string name,FOOTBALL_PLAYER pointer){//searcing with in struct array using name as keyword
for(int i=0;i<10;i++){
if(pointer[i].name==name){
cout<<" Position is"<<pointer[i].position;
}
}
}