write a C++ program that stores information about players who have been selected
ID: 3545584 • Letter: W
Question
write a C++ program that stores information about players who have been selected as participants in a fantasy football league. the data for this program is given below or can be saved in a file named fantasy.dat. this file contains the following information about each player: name, NFL team, position, and fantasy league owner's name. Your program should read these data into an array of nested structures and then create an attractively formatted report listing the information.
File: fantasy.dat
anderson sf k joann
timpson phill wr jim
el way den Qb jackv
salaam chi rb bill
carney sd k vince
sanders det rb john
carter minn wr jackr
freeman gb wr ron
watters phil rb chris
chmura gb te steve
bledsoe ne Qb chris
faulk ind rb jim
george tenn rb steve
bettis pitt rb jackv
stewart pittt qb bill
dudley oak te john
marino mia qb vince
kirby sf rb ron
warrren sea rb jack
martin ne rb joann
Explanation / Answer
Note:save the below code in same path, that is where you have fantasy.dat file data. compile and execute.
#include <iostream>
#include <fstream>
using namespace std;
struct info {
char name[20];
char NFLteam[20];
char position[20];
char FLownerName[20];
};
int main() {
string line;
info array[50];
int i = 0;
ifstream myfile("fantasy.dat");
if (myfile.is_open()) {
for(i =0;getline(myfile, line) && i <= 50;i++ ){
sscanf(line.c_str(), "%s %s %s %s", array[i].name, array[i].NFLteam,
array[i].position, array[i].FLownerName);
}
}
myfile.close();
for (int j = 0; j < i; j++) {
cout << " ----------------------------- ";
cout << "Name : " << array[j].name;
cout << "NFL team : " << array[j].NFLteam;
cout << " Position : " << array[j].position;
cout << "fantasy league owner Name: " << array[j].FLownerName;
cout << " ----------------------------- ";
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.