1 answer

CAN YOU SOLVE THIS WITH EXPLANATION? The first part of your program will read some player...

Question:

The first part of your program will read some play
CAN YOU SOLVE THIS WITH EXPLANATION?

The first part of your program will read some player information from a file, format the information, put it into an array of structures, and then display that array on the screen. You will find the following structure useful: The input for your program is in a file called players.txt. Each record in the file represents one player and is made up of multiple fields that are separated by colons. The fields for each player are the player name, role, number of goals scored, number of assists, and number of shots attempted. A record in the file resembles the following: Your main function should open players.txt, check that it opened correctly, and should invoke a function (readPlayer) that reads the contents of players.txt into an array of playerlnfo structures. The readPlayer function should take as input the array of playerlnfo structures and it should return the number of players in the array. Upon return of readPlayer, your program should invoke displayPlayer, a new function, which takes the playerlnfo array and the number of elements in this array, and it displays for each player, their name, number of goals scored, number of assists, number of points, number of shots, and shooting percentage as follows: Use the following formulas for the calculated values (points and shooting %) using a function: Number of Points = Number of Goals Scored + Number of Assists Shooting Percentage = Number of Goals Scored/Number of Shots Taken * 100

Answers

Please let me know if you need more information:-

==========================================

#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
struct playerInfo {
   char playerName[25];
   char role[10];
   int goalScored;
   int assists;
   int shots;
};
int readPlayer(ifstream& fin, playerInfo *pInfo);
void savePlayer(ofstream& fout, playerInfo *pInfo,int count);
void displayPlayer(playerInfo *pInfo ,int count);
int readPlayer(ifstream& fin, playerInfo *pInfo) {
   string temp;
   int i = 0;
   while (fin.eof() == NULL){
       char tmp[300];
       fin.getline(pInfo[i].playerName,25,':');
       fin.getline(pInfo[i].role,10,':');
       fin.getline(tmp,100,':');
       pInfo[i].goalScored = atoi(tmp);//converts string to decimal ; we can also use atol
       fin.getline(tmp,100,':');
       pInfo[i].assists = atoi(tmp);//converts string to decimal; we can also use atol
       fin.getline(tmp,100,'\n');
       pInfo[i].shots = atoi(tmp);//converts string to decimal; we can also use atol
       i++;
   }
return i;//counts records
}
void savePlayer(ofstream& fout, playerInfo *pInfo,int count){
   fout<<"Player\t\t\tGoals\tAssists\tPoints\tShots\tShooting%"<<endl;
       for(int i=0;i<count;i++){
           fout<<pInfo[i].playerName<<"\t\t\t"<<pInfo[i].goalScored<<"\t\t"<<pInfo[i].assists;
           fout<<"\t\t"<<(pInfo[i].goalScored + pInfo[i].assists)<<"\t\t"<<pInfo[i].shots<<"\t\t"<<((pInfo[i].goalScored/(double)pInfo[i].shots)*100)<<endl;
       }
}
void displayPlayer(playerInfo *pInfo, int count){
cout<<"Player\t\t\tGoals\t\tAssists\t\tPoints\t\tShots\t\tShooting%"<<endl;
   for(int i=0;i<count;i++){
       cout<<pInfo[i].playerName<<"\t\t\t"<<pInfo[i].goalScored<<"\t\t"<<pInfo[i].assists;
       cout<<"\t\t"<<(pInfo[i].goalScored + pInfo[i].assists)<<"\t\t"<<pInfo[i].shots<<"\t\t"<<((pInfo[i].goalScored/(double)pInfo[i].shots)*100)<<endl;
   }
}


int main() {
   playerInfo pInfo[200];
   ifstream inFile;
   inFile.open("players.txt");open file
   if (!inFile) {//if file not opened properly
       cout << "Error opening players.txt" << endl;
       return 1;
   }
   int p_count = readPlayer(inFile, pInfo);//read data to array
   //cout<<p_count;
   displayPlayer(pInfo,p_count);//display array data
   inFile.close();//close in file
   ofstream outFile;
   outFile.open("teams.txt");
   if (!outFile) {//if file not opened properly
           cout << "Error opening teams.txt" << endl;
           return 1;
   }
   savePlayer(outFile,pInfo,p_count);//save data
   outFile.close();//close file
   return 0;
}

======================================

SAMPLE_INPUT/OUTPUT:-

=======================================

Player ABC DEF BCD DER Goals 28 12 Assists 54. 52 Points 82 64 Shots 233 193 Shooting% 12.0172 6.21762players.t Players Data.cpp 1 ABC DEF offence: 28:54:233 2 BCD DER:offence:12:52:193

自players.txt € Players-Data.cpp 自teams.txt × 1 Player 2 ABC DEF 3 BCD DER 4 Goals Assists Points Shots Shooting% 28 12 54 52

Thanks

.

Similar Solved Questions

1 answer
Suppose that the price of a bottle of wine is €25 in Paris, and the wine...
Suppose that the price of a bottle of wine is €25 in Paris, and the wine is sold at $40 in New York. What will be the exchange rate if the law of one price holds? please show steps...
1 answer
Smith Company manufactures fish tanks. One of the fish tanks that the company produces is a...
Smith Company manufactures fish tanks. One of the fish tanks that the company produces is a 2.6 gallon fish tank that the conpany sells foe $37.50. The fish tanks are manufactured in an outdated fish tank manufacturing facility that is labor intense, relying heavily on direct labor workers. Variable...
1 answer
Prepare journal entries, as appropriate, to record these transactions. (We suggest you post the journal entries...
Prepare journal entries, as appropriate, to record these transactions. (We suggest you post the journal entries to general ledger T-accounts.) Note: The Croton City continuing problem is introduced in Chapter 3 on page 3-32. You should review the scenario in Chapter 3 before preparing the journal en...
1 answer
QUESTION 1 In 1900, the leading cause of death in the United States was which of...
QUESTION 1 In 1900, the leading cause of death in the United States was which of the following conditions? diphtheria pneumonia and influenza tuberculosis typhoid fever QUESTION 2 Which of the following types of behaviors is typically easiest to change? A. New behaviors that can be substituted with ...
1 answer
. Complete the following statements with one of the terms listed below. A term may be...
. Complete the following statements with one of the terms listed below. A term may be used once, more than once, or not at all. •             Finished goods inventory •          ...
1 answer
On February 1, 2021, Arrow Construction Company entered into a three-year construction contract to build a...
On February 1, 2021, Arrow Construction Company entered into a three-year construction contract to build a bridge for a price of $8,030,000. During 2021, costs of $2,010,000 were incurred with estimated costs of $4,010,000 yet to be incurred. Billings of $2,510,000 were sent, and cash collected was ...
1 answer
38. Determine the structure based on the following molecular formula, IR, and NMR spectrum: Formula, Coloạo 2H2H
38. Determine the structure based on the following molecular formula, IR, and NMR spectrum: Formula, Coloạo 2H2H...
1 answer
1. Write an equation that describes voltage supplied by a wall outlet. (f = 60 Hz,...
1. Write an equation that describes voltage supplied by a wall outlet. (f = 60 Hz, Vrms = 120 V) 2. What is the instantaneous voltage of a sine wave at half of a period? Describe Alternating Current (AC). Explain how resistors, capacitors, and inductors behave in an AC circuit. WRITEUP REQUIREMENTS...
1 answer
Gulliver Travel Agencies thinks interest rates in Europe are low. The firm borrows euros at 9...
Gulliver Travel Agencies thinks interest rates in Europe are low. The firm borrows euros at 9 percent for one year. During this time period the dollar falls 12 percent against the euro. What is the effective interest rate on the loan for one year? (Consider the 12 percent fall in the value of the do...
1 answer
Renal Nursing List 2 (two) examples for the problems listed in the left column questions answer?...
Renal Nursing List 2 (two) examples for the problems listed in the left column questions answer? 8.7)Types of dialysis 8.8) Parts of the urinary system 8.9) Purposes / indication for bladder irrigation 8.10) Diseases causing proteinuria...
1 answer
A physicist's left eye is myopic (i.e., nearsighted). This eye can see clearly only out to...
A physicist's left eye is myopic (i.e., nearsighted). This eye can see clearly only out to a distance of 35 cm. Find the focal length and the power of a lens that will correct this myopia when worn 2.0 cm in front of the eye. focal length: power: power: diopters Is this a converging or a divergi...
1 answer
1. (4) The following are the results from an interrupted mating experiment. Your supervisor has asked...
1. (4) The following are the results from an interrupted mating experiment. Your supervisor has asked you to interpret these results and draw a map showing the distances between the genes. The experimental set up was as follows: Hfr arg + mal + met + pur + pyr + xyl + azi s X F - arg- mal- met- pur-...
3 answers
Correct the following tenese Concentration does not mean (1) think only one idea
correct the following tenese Concentration does not mean (1) think only one idea. Concentration means holding a central issue in mind while you (2)except or reject ideas that are related to that issue. In the words of F. Scott (3)(1896-1940), author of the nover (4)"The Great Gatsby," "T...
1 answer
12. If two groups of numbers have the same mean, then their standard deviations must also...
12. If two groups of numbers have the same mean, then their standard deviations must also be equal. their medians must also be equal. their modes must also be equal. other measures of location need not be the same 13. The Sample Mean can never be negative. can assum...
1 answer
2. Jake is married filing jointly and has AGI in 2018 of $200,000. He wants to...
2. Jake is married filing jointly and has AGI in 2018 of $200,000. He wants to know if he should itemize deductions in 2018. Jake has paid $20,000 in 2018 for mortgage interest for principal of $1 Million of a mortgage taken out on November 12, 2017. In 2018, Jake paid $13,000 in property taxes and ...
1 answer
Current Attempt in Progress Oriole Company sells one product. Presented below is information for January for...
Current Attempt in Progress Oriole Company sells one product. Presented below is information for January for Oriole Company Jan. 1 Inventory 120 units at $5 each 4 Sale 96 units at $8 each 11 Purchase 141 units at $7 each 13 Sale 113 units at $9 each 20 Purchase 160 units at $ each 27 Sale 104 units...