Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm stuck on this C++ program. Overview The Stanley Cup is the trophy awarded annually to the playoff champion of the National Hockey League (NHL).

I'm stuck on this C++ program.

Overview

The Stanley Cup is the trophy awarded annually to the playoff champion of the National Hockey League (NHL). It is the oldest professional sports trophy in North America.

For this assignment, write a program that will process a file of data that contains the winners of the Stanley Cup between 1927 and 2018. It will allow the user of the program to name a hockey team and learn how many times that the team has won the Stanley Cup.

Input File

The file with the input data can be downloaded and saved on your computer. It is called stanley_cup.txt and can be found here:

http://faculty.cs.niu.edu/~byrnes/csci240/pgms/stanley_cup.txt (This is the file the program should be used on)

The file contains the names of the teams that have won the Stanley Cup in the order that they were won from 1927 through 2018. The Stanley Cup was not awarded in the year 2005 because the season was cancelled due to a lockout. Therefore, that year has the string "Not Awarded" rather than a team name.

Processing

The main function for this program is pretty basic. It should start by creating an array that can hold a maximum of 100 string elements. Each element in the array will be the name of a team that won the Stanley Cup (or "Not Awarded"). There should also be an integer to hold the number of teams that are in the array, an integer to hold the number of times a specific team has won the Stanley Cup, and a string to hold a specific team name.

Call the buildArray function that is described below to fill the array with the names of the teams. The value returned from the function should be saved in the integer that was created to hold the number of teams that are in the array.

Display the integer value that is returned from the buildArray function with an appropriate label.

Prompt the user for the name of a hockey team and save the value in the string variable.

Call the numWins function that is described below to find the number of times the selected team has won the Stanley Cup. The value returned from the function should be saved in the integer that was created to hold the number of times that a specific team has won the Stanley Cup.

Finally, display either the number of times that the selected team has won the Stanley Cup or the number of times that the Cup was not awarded if the user entered "Not Awarded".

Reading a string

In the previous assignments, whenever an input operation was performed, the input operator (>>) was used with either cin or an input file stream variable. This worked because the information that was being inputted was either separated by whitespace (a space or a newline character) or was being read one character at a time.

For this assignment, the input operator CANNOT be used because the team names will have at least one space separating the parts of the name. For example:

Chicago Blackhawks New York Rangers

Rather than trying to read the team names in parts, it should be read as a "whole" string. To do this, the getline function must be used. The format for getline is:

getline( name_of_the_input_stream, name_of_the_string_to_hold_data );

So, if the information should come from standard input (the keyboard):

string str; getline( cin, str ); 

or from an input file:

string str; getline( infile, str ); 

The Functions

For this program, two functions are required:

int buildArray( string team_array[] )

This function will place the values from the input file into the passed in array of strings.

It takes one argument: an array of strings that will be filled with the names of the teams that have won the Stanley Cup. It returns an integer: the number of teams that were placed into the array.

This function should use a standard read loop pattern to read the data from the file and place it into the array. Read the first team name from the file. In a loop that executes while there is data in the file, put the team name that was read into the array, update the array subscript, and get another name from the file.

Once all of the data has been read from the file, return the number of teams that were placed into the array.

int numWins( string team_array[], int numTeams, string search_team )

This function will search the array of Stanley Cup winning teams to determine the number of times that a specific team has won the Stanley Cup.

It takes three arguments: an array of strings that will be searched, an integer that represents the number of teams that are in the array (ie. the number of teams to be searched), and a string that represents the specific team to search for in the array. It returns an integer: the number of times that the specified team was found in the array.

In a loop that executes exactly one time for the number of teams that are in the array (ie. numTeams number of times), check to see if the specific team to search for in the array (ie. search_team) is found in the array of strings that will be searched (ie. team_array). If the specific team is found, increment a counter by 1.

Once the loop is finished executing, return the counter.

Symbolic Constant

This program requires the use of 1 symbolic constant. The constant should represent the maximum number of teams that can be placed into the array. The value should be 100.

Programming Requirements:

Add #include and #include at the top of the program. Depending on the compiler, #include might also have to be added at the top of the program to be able to use the getline function.

As with program 6, each of the functions should have a documentation box that describes the function. This is the last reminder about function documentation that will appear in the assignment write-ups.

Hand in a copy of the source code using Blackboard.

This should be the output for the program.

The output will depend on the teams that the user specifies.

Run 1

There are 92 entries in the input file Team? Chicago Blackhawks The Chicago Blackhawks have won the Stanley Cup 6 time(s). 

Run 2

There are 92 entries in the input file Team? Montreal Canadiens The Montreal Canadiens have won the Stanley Cup 22 time(s). 

Run 3

There are 92 entries in the input file Team? Not Awarded The Stanley Cup was not awarded 1 time(s). 

Run 4

There are 92 entries in the input file Team? Nashville Predators The Nashville Predators have won the Stanley Cup 0 time(s). 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

1. What is Ebola ? 2.Heart is a muscle? 3. Artificial lighting?

Answered: 1 week ago

Question

14-18 Compare the two major types of planning and control tools.

Answered: 1 week ago