Programming using C Write a program that uses a structure na
Programming using C++:
Write a program that uses a structure named HockeyPlayer to store the following information about a hockey player: Name Team Position played Number of goals Number of assists Your program should create two HockeyPlayer variables, store values in their members, and pass each one, in turn to a function that displays the information about the players in a clearly formatted manner.Solution
//Tested on ubuntu,Linux
/*****************Hocky.cpp***************/
#include <iostream>
using namespace std;
/**
* structure declarations with variables
* */
struct HockyPlayer
{
char name[50];
char team[50];
int positionPlayed;
int numbesOfGoals;
int numberOfAssists;
};
/**
* displaying player information
* */
void displayInfo(HockyPlayer *hockyPlayer,int size){
cout << \"Displaying Information: \" << endl;
// Displaying information
for(int i = 0; i < size; ++i)
{
std::cout<<\"************************\"<<std::endl;
std::cout << \"Palyer Name: \" << hockyPlayer[i].name << std::endl;
std::cout << \"Team Name: \" << hockyPlayer[i].team << std::endl;
std::cout<< \"Position played: \"<<hockyPlayer[i].positionPlayed<<std::endl;
std::cout<< \"Number of Goals: \"<<hockyPlayer[i].numbesOfGoals<<std::endl;
std::cout<< \"Number of Assists: \"<<hockyPlayer[i].numberOfAssists<<std::endl;
}
}
/**
* Main function start
* */
int main(){
/**
* creating variables of hockyPlayer of size 2
* you can also increase size of array
* */
HockyPlayer hockyPlayer[2];
cout << \"Enter information of HockyPlayers: \" << std::endl;
// storing information into hockyPlayer array of structure
//prompt for player informations
for(int i = 0; i < 2; ++i) {
std::cout << \"Enter name: \"<<std::endl;
std::cin>>hockyPlayer[i].name;
std::cout << \"Enter Team Name: \"<<std::endl;
std::cin>>hockyPlayer[i].team;
std::cout << \"Enter position played: \"<<std::endl;
std::cin>>hockyPlayer[i].positionPlayed;
std::cout << \"Enter numbesOfGoals: \"<<std::endl;
std::cin>>hockyPlayer[i].numbesOfGoals;
std::cout << \"Enter numberOfAssists: \"<<std::endl;
std::cin>>hockyPlayer[i].numberOfAssists;
}
/**
* calling displayInfo function for displaying information
* */
displayInfo(hockyPlayer,2);
return 0;
}
/**
* Main function ENd
* */
/**************output************/
raj@raj:~/Desktop/chegg$ g++ Hocky.cpp
raj@raj:~/Desktop/chegg$ ./a.out
Enter information of HockyPlayers:
Enter name:
Mandeep
Enter Team Name:
India
Enter position played:
2
Enter numbesOfGoals:
13
Enter numberOfAssists:
1
Enter name:
Roberts
Enter Team Name:
England
Enter position played:
4
Enter numbesOfGoals:
18
Enter numberOfAssists:
2
Displaying Information:
************************
Palyer Name: Mandeep
Team Name: India
Position played: 2
Number of Goals: 13
Number of Assists: 1
************************
Palyer Name: Roberts
Team Name: England
Position played: 4
Number of Goals: 18
Number of Assists: 2
Thanks a lot


