QuestionQuestion

Objective
To gain experience with using an array of structures, as well as with dynamic allocation of an array. This program provides further practice in file input, as well.

Task
You will write a program that reads and stores NFL team data from a file into an array of structs. You will then use this data and print it out in various formats, as well as manipulate the data, based on a user controlled menu with multiple selections.

Input File Format
• The first line of the input file will be a single integer number -- this value tells how many records are in the file. There's no guarantee how many records will be in the file, so you must create your dynamic array of structs only AFTER reading in this first integer value.
• After this, each line represents one NFL team. Each line consists of the following fields (in this order), separated by commas:
o Team Name: a character string (assume no more than 40 characters)
o Number of Wins: an integer
o Number of Losses: an integer
o Did team make the playoffs: a 1 or a 0. You can store this as an int or a boolean (your choice)
• You may assume that a file is in the correct format, that there is no trailing whitespace in the file, and that the types and limits will be as described above. You SHOULD test on many different files that have a different number of records in the file. I've provided you a single sample input file. Modify this as you wish (keeping the same formatting. It's best to modify this .txt file right in visual studio! Go to file, open, file, and click the .txt file from there. I'll open up in a seperate window in VS. Much easier this way.) to test your program to make sure it can handle files with different numbers of teams.

• A sample input file
{
7
New England Patriots,3,13,0
Buffalo Bills,15,1,1
Carolina Panthers,9,7,1
Jacksonville Jaguars,10,6,1
Miami Dolphins,7,9,0
Green Bay Packers,11,5,1
San Francisco 49ers,4,12,0
}

Program Details
1. Create a structure type called teamInfo. A variable of type teamInfo should contain fields for the following:
o team name
o wins
o losses
o playoffs
o win loss differential
o You're welcome to add any additional fields to the struct if you wish, but the ones above are required
The other fields match the data described in the input file format section. Use a c-string for the team name.

2. Your program should start by asking the user to type the name of the input file. Whenever a bad filename is entered, print an error message and prompt the user to re-enter the filename. The user should be ***forced*** to enter a correct filename

3. Open the input file and read the records into an array of teamInfo structures. You'll need to create this array dynamically, because you won't know how many records there are until you start reading the file itself. The data from each record in the file should be stored in one teamInfo structure (i.e. one array slot per team record)

4. Once you're done reading from the input file, close the file.

For each team, compute and store the win loss differential (based on the number of wins and losses for each team) as such:
Examples:
if a team has 9 wins and 7 losses, their win/loss differential is 2
if a team has 12 wins and 4 losses, their win/loss differential is 8
if a team has 2 wins and 14 losses, their win/loss differential is -12
if a team has 8 wins and 8 losses, their win/loss differential is 0
Enter a menu loop that allows the user to choose from the following options (they should enter the corresponding integer to choose):
1 - View team Win/Loss records
2 - Show teams with at least x wins
3 - List teams that made the playoffs
4 - List teams and their win/loss differential
5 - Sort teams by Win/Loss differential
0 - Exit program

Menu option 1 - View team Win/Loss Records:
When the user selects this option, print the teams and their win loss records in the following format, one per line. They can just be printed in the order that they're stored in your array:
Team W-L:
New York Giants 10-6
Buffalo Bills 16-0
(etc)

Menu option 2 - Show teams with at least x wins:
When the user selects this option, prompt the user for a number of wins, and print out the team names that have at least that many wins. Example:
Show teams with at least how many wins? --> 11
Detroit Lions
Carolina Panthers
Jacksonville Jaguars
(etc)

Menu option 3 - List teams that made the playoffs:
When the user selects this option, print out the teams that made the playoffs, in a COMMA SEPERATED list. Example:
Playoff teams:
Buffalo Bills, Green Bay Packers, San Franscisco 49ers ... etc
Make sure there's no comma after the last team in the list.

Menu option 4 - Print teams and their Win/Loss
For this option, go through your array and print the team name and their corresponding win/loss differential. If a team has a positive win loss differential, print a + before the value. Example:
Dallas Cowboys +3
Arizona Cardinals -5
etc...

Menu option 5 - Sort teams by Win/Loss differential
For this option, sort the teams by their win loss differential. You must actually sort the items in the array for the extra credit (aka, don't use if statements to print stuff in order). You can test this by selecting option 4 afterwards to print out the differential list to see if they're sorted properly. You can sort ascending or descending, your choice.
Make sure to clean up any dynamically allocated space before ending the program.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cctype>
#include <cstring>

using namespace std;

/**
* Create a structure type called teamInfo. A variable of type teamInfo should contain fields for the following:
    team name
    wins
    losses
    playoffs
    win loss differential
    You're welcome to add any additional fields to the struct if you wish, but the ones above are required

The other fields match the data described in the input file format section. Use a c-string for the team name.
*/

struct teamInfo {
    char * team_name;
    int wins;
    int losses;
    int playoffs;
    int win_loss_diff;
};

/**
* Your program should start by asking the user to type the name of the input
* file. Whenever a bad filename is entered, print an error message and prompt
* the user to re-enter the filename. The user should be ***forced*** to enter
* a correct filename
* @param file_name
*/
void askingForFileName(char * file_name);

/**
* Open the input file and read the records into an array of teamInfo structures.
* You'll need to create this array dynamically,
* because you won't know how many records there are until
* you start reading the file itself.
* The data from each record in the file should be stored
* in one teamInfo structure (i.e. one array slot per team record)
* @param file_name
* @return
*/
teamInfo * readFile(char * file_name, int & size);

void printMenu();

void task1(teamInfo * ti, int size);
void task2(teamInfo * ti, int size);
void task3(teamInfo * ti, int size);
void task4(teamInfo * ti, int size);
void task5(teamInfo * ti, int size);...

By purchasing this solution you'll be able to access the following files:
Solution.cpp and SolutionTeams.txt.

50% discount

Hours
Minutes
Seconds
$23.00 $11.50
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats