Question

Write a program that declares a struct to store the data of a football player (players name, players position, number of to*****k ***** ******k *** *k Assignment: A5 Structs <1> Look Up a Player * <2> Edit a Player * <3> Print Team Roster <4> To Qu

k k k* *** Assignment: A5 Structs * <1> Look Up a Player * <2> Edit a Player * <3> Print Team Roster * <4> To Quit **********

In C++:

Functions to include:

editPlayer: is a void fn, which takes an array of playerType and calls
lookUpPlayer which returns the index of the target (-1 if not found).
If found allows the user to edit any of the data members of the player via a menu system.
lookUpPlayer: is a int fn, which takes an array of playerTypes, prompts the user for the
name of the player and attempts to find them. If found, prints message "found" and returns the index,
otherwise prints "not found" and returns -1. ** Extra credit 2 pts if you make it case insensitive and
substrings work (i.e. "lex" is found in the string "Lexacon".
printPlayer is a void fn, that that takes a playerType variable by value and prints a single players' record.
printTeam, is a void fn, takes the entire array and calls printPlayer for each record.
readFile, is a void fn which populates the array from a file "input.txt" make it local
writeFile, is a void fn which saves the database to "output.txt"

InFile Contents (no user inputs, just read inputs from the below contents):

Alexander, Maurice
DB
1
0
0
0
0
Alexander, D.J.
LB
0
0
0
0
0
Baldwin, Doug
WR
3
15
86
400
12
Battle, Isaiah
OT
0
0
0
0
0
Beal, Emmanuel
LB
0
0
0
0
0
Beavers, Willie
OT
0
0
0
0
0
Britt, Justin
C
1
0
0
0
0
Brown, Jaron
WR
2
30
0
322
0
Brown, Duane
OT
0
0
0
0
0
Calitro, Austin
LB
0
0
0
0
0

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

// Feel free to write a comment if you have any queries

// Output is at the bottom

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <string>
#include <climits>
using namespace std;

struct player {
string name;
string position;
int numTouchdowns;
int numCatches;
int numPassingYards;
int numReceivingYards;
int numRushingYards;
};

void readFile(player p[], ifstream& fin) {
fin.open("input.txt");
if(!fin.is_open()) {
cerr << "Cannot open file. Exiting." << endl;
exit(1);
}
string line;
int i = 0;
while(fin && i < 10) {
getline(fin, p[i].name);
getline(fin, p[i].position);
getline(fin, line);
p[i].numTouchdowns = stoi(line);
getline(fin, line);
p[i].numCatches = stoi(line);
getline(fin, line);
p[i].numPassingYards = stoi(line);
getline(fin, line);
p[i].numReceivingYards = stoi(line);
getline(fin, line);
p[i].numRushingYards = stoi(line);
i++;
}
}
void writeFile(player p[], ofstream& fout) {
fout.open("output.txt");
if(!fout.is_open()) {
cerr << "Cannot open file. Exiting." << endl;
exit(1);
}
int i = 0;
while(i < 10) {
fout << p[i].name << "\n";
fout << p[i].position << "\n";
fout << p[i].numTouchdowns << "\n";
fout << p[i].numCatches << "\n";
fout << p[i].numPassingYards << "\n";
fout << p[i].numReceivingYards << "\n";
fout << p[i].numRushingYards << "\n";
i++;
}
}

void printPlayer(player p) {
cout << left << setw(30) << p.name << "\t\t" << p.position << "\t\t" << p.numTouchdowns << "\t\t"
<< p.numCatches << "\t\t" << p.numPassingYards << "\t\t" << p.numReceivingYards
<< "\t\t" << p.numRushingYards << "\n\n";
}

void printTeam(player p[]) {
cout << left << setw(30) << "Name" << "\t" << "Position" << "\t" << "Num Touchdowns" << "\t"
<< "numCatches" << "\t" << "numPassingYards" << "\t\t" << "numReceivingYards"
<< "\t" << "numRushingYards" << "\n\n";
for(int i = 0; i < 10; i++) {
printPlayer(p[i]);
}
}

int lookUpPlayer(player p[]) {
string searchName;
cout << "Search: ";
cin >> searchName;
cout << endl;
for(int i = 0; i < 10; i++) {
auto found = p[i].name.find(searchName);
if(found != string::npos) {
cout << "Found" << endl;
return i;
}
}
return -1;
}

void editPlayer(player p[]) {
int index = lookUpPlayer(p);
if(index == -1) {
cout << "Can't find player. Returning" << endl;
return;
}
int choice;


cout << "Edit Player" << endl;
cout << left << setw(50) << "" << "CURRENT VALUES" << endl;
cout << left << setw(50) << "1. Edit Name" << p[index].name << endl;
cout << left << setw(50) << "2. Edit position" << p[index].position << endl;
cout << left << setw(50) << "3. Edit number of touch downs" << p[index].numTouchdowns << endl;
cout << left << setw(50) << "4. Edit number of catches" << p[index].numCatches << endl;
cout << left << setw(50) << "5. Edit number of passing yards" << p[index].numPassingYards << endl;
cout << left << setw(50) << "6. Edit number of receiving yards" << p[index].numReceivingYards << endl;
cout << left << setw(50) << "7. Edit number of rushing yards" << p[index].numRushingYards << endl;
cout << left << setw(50) << "8. Return to Main Menu" << endl;
cout << "Choice(1-8): ";
cin >> choice;
string s;
switch(choice) {
case 1: cout << "Enter new name: ";
getchar();
getline(cin, s);
s = p[index].name;
break;
case 2: cout << "Enter new position: ";
getchar();
getline(cin, s);
s = p[index].position;
break;
case 3: cout << "Enter new number of touchdowns: ";
cin >> p[index].numTouchdowns;
break;
case 4: cout << "Enter new number of catches: ";
cin >> p[index].numCatches;
break;
case 5: cout << "Enter new number of passing yards: ";
cin >> p[index].numPassingYards;
break;
case 6: cout << "Enter new number of receiving yards: ";
cin >> p[index].numReceivingYards;
break;
case 7: cout << "Enter new number of rushing yards: ";
cin >> p[index].numRushingYards;
break;
case 8: return;
default: cout << "Invalid choice." << endl;
}
}

int main() {
player p[10];
ifstream fin;
ofstream fout;
readFile(p, fin);
  
int choice;
while(1) {
cout << "Menu" << endl;
cout << "1. Look up a player" << endl;
cout << "2. Edit a player" << endl;
cout << "3. Print Team Roster" << endl;
cout << "4. To quit" << endl;
cout << "Choice(1-4): ";
cin >> choice;
switch(choice) {
case 1: lookUpPlayer(p);
break;
case 2: editPlayer(p);
break;
case 3: printTeam(p);
break;
case 4: return 0;
default: cout << "Invalid choice, try again" << endl;
}
}

writeFile(p, fout);
fin.close();
fout.close();
}

OUTPUT

Add a comment
Know the answer?
Add Answer to:
In C++: Functions to include: editPlayer: is a void fn, which takes an array of playerType...
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
  • In C Program This program will store the roster and rating information for a soccer team. There w...

    In C Program This program will store the roster and rating information for a soccer team. There will be 3 pieces of information about each player: Name: string, 1-100 characters (nickname or first name only, NO SPACES) Jersey Number: integer, 1-99 (these must be unique) Rating: double, 0.0-100.0 You must create a struct called "playData" to hold all the information defined above for a single player. You must use an array of your structs to to store this information. You...

  • Java 7.17 Clone of LAB*: Program: Soccer team roster This program will store roster and rating...

    Java 7.17 Clone of LAB*: Program: Soccer team roster This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (1) Prompt the user to input five pairs of numbers: A player's jersey number (0-99, but this is NOT enforced by the program nor tested) and the player's rating (1-9, not enforced like jersey numbers). Store the jersey numbers in one int array and the ratings in another int...

  • A competition takes place for the development of a new functionality that will be added on...

    A competition takes place for the development of a new functionality that will be added on the NBA daily stats. This new functionality will show the player with the maximum ratio of points per minute. Develop a program in C++ that prompts the user to enter data for a number of NBA players and then outputs the player(s) with the maximum ratio of points per minute. You can store the players entered by the user in an array of structs...

  • In C only Please! This lab is to write a program that will sort an array...

    In C only Please! This lab is to write a program that will sort an array of structs. Use the functions.h header file with your program. Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like though it is recommended that you use bubble sort, insertion sort, or selection sort...

  • 5.19 Lab 11b: Soccer team roster Instructor note: NOTE Unlike our other assignments, this one has...

    5.19 Lab 11b: Soccer team roster Instructor note: NOTE Unlike our other assignments, this one has only two programs: People's Weights and this one. To earn 30 points, you must do both assignments. Allow ample time to complete them Passing arrays to methods Review Chapter 6.8 Array Parameters if you wish to use methods in your program (a good idea). Since we pass a reference to the array's location in memory, changes made to the array within the method will...

  • (C++) Write a program that declares a struct to store the data of a football player...

    (C++) Write a program that declares a struct to store the data of a football player (player’s name, player’s position, number of touchdowns, number of catches, number of passing yards, number of receiving yards, and the number of rushing yards). Declare an array of 10 components to store the data of 10 football players. Your program must contain a function to input data and a function to output data. Add functions to search the array to find the index of...

  • 5.19 Ch 5 Program: Soccer team roster (Vectors) (C++) This program will store roster and rating...

    5.19 Ch 5 Program: Soccer team roster (Vectors) (C++) This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers in one int vector and the ratings in another int vector. Output these vectors (i.e., output the roster). (3 pts) Ex:...

  • 5.22 LAB*: Program: Soccer team roster steam This program will store roster and rating information for...

    5.22 LAB*: Program: Soccer team roster steam This program will store roster and rating information for a soccer team Coaches rate players during tryouts to ensure (1) Prompt the user to input five pairs of numbers: A player's jersey number (0.99) and the player's rating (1-9) Store in one int array and the ratings in another int array Output these arrays (e. output the roster) (3 pts) numbers EX Enter player 1 jersey number: Enter player l's rating: Enter player...

  • I need help programming the main args. I am not sure what to do after I...

    I need help programming the main args. I am not sure what to do after I create an array list and scanner.h import java.util.ArrayList; import java.util.Scanner; public class Fantasy Football public static void main(string] args) ArrayList<String> availablePlayers - new ArrayList<String>0; addPlayers (avallablePlayers), Stringt roster; roster = new String[5]; Scanner player = new Scanner(System.in); System.out.println("Enter Player you would like on your tein: "); String playeri - player.nextLine(); public static int search(ArrayListString> array, String player) for (int i = 0; i <...

  • This program will store a roster of most popular videos with kittens. The roster can include...

    This program will store a roster of most popular videos with kittens. The roster can include at most 10 kittens.You will implement structures to handle kitten information. You will also use functions to manipulate the structure. (1) Create a structure kitten. The structure should contain the following attributes: name; string color; string score; integer Important! The name of the structure and each of its field must match exactly for the program to work and be graded correctly. (2) Create a...

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