Need done in C++
Can not get my code to properly display output. Instructions below. The code compiles but output is very off.
Write a program that scores the following data about a soccer player in a structure:
Player’s Name
Player’s Number
Points Scored by Player
The program should keep an array of 12 of these structures. Each element is for a different player on a team. When the program runs, it should ask the user to enter the data for each player. It should then show a table that lists each player’s number, name, and points scored. The program should also calculate and display the total points earned by the team. The number and name of the player who has earned the most points should also be displayed.
#include <iostream>
#include <iomanip>
using namespace std;
// Declaration of the Player structure
struct Player
{
char name[45]; // Player's name
int number; // Player's number
int points; // Points scored by the player
};
const int numPlayers = 12; // The number of players
// Function prototypes
void getPlayerInfo(Player &);
void showInfo(Player);
int getTotalPoints(Player[], int);
void showHighest(Player[], int);
//***********************************************
// Function main *
//***********************************************
int main()
{
Player team[numPlayers];
int index;
for (index = 0; index < 12; index++)
{
cout << "\nPLAYER #" << (index + 1) <<
"\n";
cout << "---------\n";
getPlayerInfo(team[index]);
cin.get();
}
cout.width(20);
cout.setf(ios::left);
cout << "\nNAME";
cout.width(10);
cout << "NUMBER";
cout.width(10);
cout << "POINTS SCORED\n";
for (index = 0; index < 12; index++)
showInfo(team[index]);
cout << "TOTAL POINTS: " << getTotalPoints(team,
numPlayers) << endl;
showHighest(team, numPlayers);
}
//***********************************************
// Function getPlayer *
// This function accepts a reference to a Player*
// structure variable. The user is asked to *
// enter the player's name, number, and the *
// number of points scored. This data is stored *
// in the reference parameter. *
//***********************************************
void getPlayerInfo(Player &p)
{
while (p.points < 0)
{
cout << p.points << endl;
cout << "Player name: ";
cin.getline(p.name, 45);
cout << "Player's number: ";
cin >> p.number;
cout << "Points scored: ";
cin >> p.points;
}
}
//***********************************************
// Function showInfo *
// This function displays the data in the Player*
// structure variable passed into the parameter.*
//***********************************************
void showInfo(Player p)
{
cout << setw(20) << p.name;
cout << setw(10) << p.number;
cout << setw(10) << p.points << endl;
}
//***********************************************
// Function getTotalPoints *
// This function accepts an array of Player *
// structure variables as its argument. The *
// function calciulates and returns the total *
// of all the players points in the array. *
//***********************************************
int getTotalPoints(Player p[], int size)
{
int total = 0;
for (int index = 0; index < size; index++)
total += p[index].points;
return total;
}
//***********************************************
// Function showHighest *
// This function accepts an array of Player *
// structure variables. It displays the name *
// of the player who scored the most points. *
//***********************************************
void showHighest(Player p[], int size)
{
int highest = 0, highPoints = p[0].points;
for (int index = 1; index < size; index++)
{
if (p[index].points > highPoints)
{
highest = index;
highPoints = p[index].points;
}
}
cout << "The player who scored the most points is: ";
cout << p[highest].name << endl;
}
Here is code:
#include <iostream>
#include <iomanip>
#include <limits>
using namespace std;
// Declaration of the Player structure
struct Player
{
char name[45]; // Player's name
int number; // Player's number
int points; // Points scored by the player
};
const int numPlayers = 12; // The number of players
// Function prototypes
void getPlayerInfo(Player &);
void showInfo(Player);
int getTotalPoints(Player[], int);
void showHighest(Player[], int);
//***********************************************
// Function main *
//***********************************************
int main()
{
Player team[numPlayers];
int index;
for (index = 0; index < numPlayers; index++)
{
cout << "\nPLAYER #" << (index + 1) << "\n";
cout << "---------\n";
getPlayerInfo(team[index]);
cin.get();
}
cout.width(20);
cout.setf(ios::left);
cout << "\nNAME";
cout.width(10);
cout << "NUMBER";
cout.width(10);
cout << "POINTS SCORED\n";
for (index = 0; index < 12; index++)
showInfo(team[index]);
cout << "TOTAL POINTS: " << getTotalPoints(team, numPlayers) << endl;
showHighest(team, numPlayers);
}
//***********************************************
// Function getPlayer *
// This function accepts a reference to a Player*
// structure variable. The user is asked to *
// enter the player's name, number, and the *
// number of points scored. This data is stored *
// in the reference parameter. *
//***********************************************
void getPlayerInfo(Player &p)
{
cout << "Player name: ";
cin.getline(p.name, 45);
cout << "Player's number: ";
// check if input is valid or not
while (!(cin >> p.number))
{
// flush the cin data
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Invalid entry, Try again : ";
}
do
{
cout << "Points scored: ";
cin >> p.points;
} while (p.points < 0);
}
//***********************************************
// Function showInfo *
// This function displays the data in the Player*
// structure variable passed into the parameter.*
//***********************************************
void showInfo(Player p)
{
cout << setw(20) << p.name;
cout << setw(10) << p.number;
cout << setw(10) << p.points << endl;
}
//***********************************************
// Function getTotalPoints *
// This function accepts an array of Player *
// structure variables as its argument. The *
// function calciulates and returns the total *
// of all the players points in the array. *
//***********************************************
int getTotalPoints(Player p[], int size)
{
int total = 0;
for (int index = 0; index < size; index++)
total += p[index].points;
return total;
}
//***********************************************
// Function showHighest *
// This function accepts an array of Player *
// structure variables. It displays the name *
// of the player who scored the most points. *
//***********************************************
void showHighest(Player p[], int size)
{
int highest = 0, highPoints = p[0].points;
for (int index = 1; index < size; index++)
{
if (p[index].points > highPoints)
{
highest = index;
highPoints = p[index].points;
}
}
cout << "The player who scored the most points is: ";
cout << p[highest].name << endl;
}
Output:


Need done in C++ Can not get my code to properly display output. Instructions below. The...
I need this done in C++ Can someone help me get my code from crashing. The code compiles but it can be easily crashed with user input. The rubric and code below Instructions: Write a program that scores the following data about a soccer player in a structure: Player’s Name Player’s Number Points Scored by Player The program should keep an array of 12 of these structures. Each element is for a different player on a...
I am getting an error that the variable num was not declared in the scope on the line of code that has; while(num != 5). Do you know how to fixe this error? #include <iostream> #include <iomanip> #include <string> #include<fstream> #include <cstring> using namespace std; //Declare the structure struct Games { string visit_team; int home_score; int visit_score; }; // Function prototypes int readData(Games *&stats); int menu(); void pickGame(Games *&stats, int size); void inputValid (Games *&stats, int size); void homeTotal(Games *&stats,...
Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem to get my code to work. The output should have the AVEPPG from highest to lowest (sorted by bubbesort). The output of my code is messed up. Please help me, thanks. Here's the input.txt: Mary 15 10.5 Joseph 32 6.2 Jack 72 8.1 Vince 83 4.2 Elizabeth 41 7.5 The output should be: NAME UNIFORM# AVEPPG Mary 15 10.50 Jack 72 8.10 Elizabeth 41 7.50 Joseph 32 6.20 Vince 83 4.20 My Code: #include <iostream>...
I need to update this C++ code according to these instructions.
The team name should be "Scooterbacks".
I appreciate any help!
Here is my code:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void menu();
int loadFile(string file,string names[],int jNo[],string
pos[],int scores[]);
string lowestScorer(string names[],int scores[],int size);
string highestScorer(string names[],int scores[],int size);
void searchByName(string names[],int jNo[],string pos[],int
scores[],int size);
int totalPoints(int scores[],int size);
void sortByName(string names[],int jNo[],string pos[],int
scores[],int size);
void displayToScreen(string names[],int jNo[],string pos[],int
scores[],int size);
void writeToFile(string...
In need of some help with a LCR C++ game. The code will run, but I need it to cycle through the turns automatically so that the only input from the user is the number of players. It's also showing the winner as the person with 0 chips which is incorrect and I can't figure out why. Any help is greatly appreciated as this is already late. Game rules: Develop a program that follows the rules of Left Center Right...
I want to change this code and need help. I want the code to not use parallel arrays, but instead use one array of struct containing the data elements, String for first name, String for last name,Array of integers for five (5) test scores, Character for grade. If you have any idea help would be great. #include #include #include #include using namespace std; const int NUMBER_OF_ROWS = 10; //number of students const int NUMBER_OF_COLUMNS = 5; //number of scores void...
What's wrong with my code? : I'm trying to use recursive functions to display and count all the even numbers of an array. However, I can't seem get the program output the number of even integers . Here's the output I want: Here are the 5 even numbers: // Luckily, however, my code does output all the even numbers. But, I also want the program to tell me how may even integers there are. 2 8 14 18 22 MY...
Convert the TreeArray C++ source code(posted below) into a BinaryTree, using this TreeNode definition: class TreeNode<T> T data TreeNode<T> left TreeNode<T> right Since this TreeNode is a generic Template, use any data file we've used this quarter to store the data in the BinaryTree. To do this will likely require writing a compare function or operator. Hint: Think LEFT if the index is calculate (2n+1) and RIGHT if index is (2n+2). Source code: #include<iostream> using namespace std;...
Can I get a C++ code and output for this program using classes instead of using struct. The following program implements a Last In First Out (LIFO) stack. ( I want to use class for function definitions too and if main need.) #include <iostream> using namespace std; const int MAX = 100; struct stack { int s[MAX]; // an array of integers int top; // the index of the last number }; void push(stack &, int); void pop(stack&,...
using the source code at the bottom of this page, use the following instructions to make the appropriate modifications to the source code. Serendipity Booksellers Software Development Project— Part 7: A Problem-Solving Exercise For this chapter’s assignment, you are to add a series of arrays to the program. For the time being, these arrays will be used to hold the data in the inventory database. The functions that allow the user to add, change, and delete books in the store’s...