Question

The first part of your program will read some play

CAN YOU SOLVE THIS WITH EXPLANATION?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
CAN YOU SOLVE THIS WITH EXPLANATION? The first part of your program will read some player...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Need C programming help. I've started to work on the program, however I struggle when using...

    Need C programming help. I've started to work on the program, however I struggle when using files and pointers. Any help is appreciated as I am having a hard time comleting this code. #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LINE 100 #define MAX_NAME 30 int countLinesInFile(FILE* fPtr); int findPlayerByName(char** names, char* target, int size); int findMVP(int* goals, int* assists, int size); void printPlayers(int* goals, int* assists, char** names, int size); void allocateMemory(int** goals, int** assists, char*** names, int size);...

  • need help on C++ Discussion: The program should utilize 3 files. player.txt – Player name data...

    need help on C++ Discussion: The program should utilize 3 files. player.txt – Player name data file – It has: player ID, player first name, middle initial, last name soccer.txt – Player information file – It has: player ID, goals scored, number of penalties, jersey number output file - formatted according to the example provided later in this assignment a) Define a struct to hold the information for a person storing first name, middle initial, and   last name). b) Define...

  • C++ Please Provide .cpp Overview For this assignment, implement and use the methods for a class...

    C++ Please Provide .cpp Overview For this assignment, implement and use the methods for a class called Player that represents a player in the National Hockey League. Player class Use the following class definition: class Player { public: Player(); Player( const char [], int, int, int ); void printPlayer(); void setName( const char [] ); void setNumber( int ); void changeGoals( int ); void changeAssists( int ); int getNumber(); int getGoals(); int getAssists(); private: char name[50]; int number; int goals;...

  • Need done in C++ Can not get my code to properly display output. Instructions below. The...

    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...

  • Use basic C++ 3. A text file, superstars.txt, contains statistics on cricket players. For each player,...

    Use basic C++ 3. A text file, superstars.txt, contains statistics on cricket players. For each player, the file contains the player's first name, last name, number of matches played, total number of runs scored, number of times the player scored 100 runs in a match, and the number of wickets taken. The last row of data in the file contains the word "END" only. Some rows are shown below 30 11867 164 Chanderpaul Shivnarine 34 11912 130 Lara Brian 73...

  • This is subject of C++ Your program should read the file answers.dat. This file contains the...

    This is subject of C++ Your program should read the file answers.dat. This file contains the name of the student who took the quiz, and his answers for each question. The answers file has the following format: The student name is always the first line. A student name may or may not have last names. For example, both Elvis Presley and Cher took this class. A quiz always has 11 questions. There is one answer per line. Each answer is...

  • c++ program Notes 1. Your program should use named string constant for the file name to open the file. Do not add any pa...

    c++ program Notes 1. Your program should use named string constant for the file name to open the file. Do not add any path to the file name because the path on your computer is not likely to exist on the computer the instructor uses to grade the program. Points may be deducted if you don't follow this instruction. 2. Split statements and comments longer than 80 characters into multiple lines and use proper indentations for the split portions. 3....

  • What to submit: your answers to exercises 2. Write a Java program to perform the following...

    What to submit: your answers to exercises 2. Write a Java program to perform the following tasks: The program should ask the user for the name of an input file and the name of an output file. It should then open the input file as a text file (if the input file does not exist it should throw an exception) and read the contents line by line. It should also open the output file as a text file and write...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT