Question

This project will allow you to practice with one dimensional arrays, function and the same time...

This project will allow you to practice with one dimensional arrays, function and the same time review the old material. You must submit it on Blackboard and also demonstrate a run to your instructor.

General Description: The National Basketball Association (NBA) needs a program to calculate the wins-losses percentages of the teams.

Write a complete C++ program including comments to do the following:

Create the following:

•a string array that holds the names of the teams

•an integer array that holds the number of wins for the corresponding team

•an integer array that holds the number of losses for the corresponding team

•A double array that holds the percentage for the corresponding team

•a function named ‘displayMenu’

•a  function named ‘calculateStats’

•a  function named ‘maxPercent’

•a  function named ‘minPercent’

•a  function named ‘printReport’

•a  function named ‘sortPercentage’

•a  function named ‘sortAlpha’

See the function descriptions below.

Start this program by declaring and initializing the string array ‘teams’, the integer array ‘wins’ and the integer array ‘losses’. Then continue by asking the question: "How many teams in the league".

1.Calculate statistics (use the function calculateStats)

2.Call the function ‘displayMenu’ to display the menu below:

MAIN MENU

-----------------

1.Display Teams

2.Team Standings

3.Best Team

4.Worst Team

5.Update Statistics

6.Exit

3.Depending on the menu selection call the appropriate functions, display possible results. Always pause and strike a key to return back to the menu.

a)If the menu selection is 1, then display the teams in alphabetical order, along with the corresponding wins, losses and percentages. (call sortAlpha)

b)If the menu selection is 2, then display the teams in descending order by percentage, along with the corresponding wins, losses and percentages. (call sortPercentage )

c)If the menu selection is 3, then display the team with the best percentage, along with the corresponding wins, losses and percentage. (call maxPercent )

d)If the menu selection is 4, then display the team with the worst percentage, along with the corresponding wins, losses and percentage. (call minPercent )

e)If the menu selection is 5, then ask for the team name to update the statistics. Display the current statistics (wins-losses) and ask for the updated ones. Update the ‘wins’ and/or ‘losses’ arrays. You should decide how to perform this step. Use a function named ‘upddate’

f) If the menu selection is 6 display a message and exit the program.

Description of Functions.

The function displayMenu will display the menu above and it will prompt the user for a choice. It will then return and int (the choice).

The function calculateStats will receive 4 parameters: an int that represents the number of teams in the league;

an integer array ‘wins’ that holds the number of wins for the corresponding team, an integer array ‘losses’ that holds the number of losses for the corresponding team and a double array named ‘percentage’. ‘calculateStats will calculate the percentage of wins as compared to the total games (wins / (wins+losses) ) for each team and assign the value to the corresponding element of the ‘percentage’ array.

The function printReport will receive all the parameters that are required to create the output. The function will simply display all the relevant information.

The function maxPercent will receive 2 parameters. The first parameter represents the number of teams in the league; the second parameter is an array that holds the percentages. The function will find and return the index (subscript) of the team with the maximum percentage to the main function.  

The function minPercent will receive 2 parameters. The first parameter represents the number of teams in the league; the second parameter is an array that holds the percentages. The function will find and return the index (subscript) of the team with the minimum percentage to the main function.  

The function sortPercentage will receive 5 parameters: an int that represents the number of teams in the league; a string array ‘teams’ that holds the names of the teams, an integer array ‘wins’ that holds the number of wins for the corresponding team, an integer array ‘losses’ that holds the number of losses for the corresponding team and a double array ‘percentage’ that holds the percentage of each team. ‘sortPercentage will sort the ‘percentage’ array in descending order. (each time you sort an element of the array, you must carry along the information of the other arrays)

The function sortAlpha will receive 5 parameters: an int that represents the number of teams in the league; a string array ‘teams’ that holds the names of the teams, an integer array ‘wins’ that holds the number of wins for the corresponding team, an integer array ‘losses’ that holds the number of losses for the corresponding team and a double array ‘percentage’ that holds the percentage of each team. ‘sortAlpha will sort the ‘teams’ array in alphabetical order. (each time you sort an element of the array, you must carry along the information of the other arrays)

The function printReport will display a report. (see format below) The report must include headings and your name. You must determine which parameters you need.

Your printout should look like this:

BASKETBALL  STATISTICS

===================

  TEAM. WINS         LOSSES   PERCENTAGE

  ===========        =======   ============

KNICKS 20. 40 50%

LAKERS 12 36 30%

  Etc ......             .....              .....

     -------- ---------------

TOTALS: 94 190 49%

Best team : ……………….

Worst team:……………….

Use the following data:

Team            Wins    Losses      Percentage

KNICKS 26 16 .635

NETS 17 28 .378

LAKERS 16 27 .372

Atlanta 24 20 .545

Chigago 23 21 .523

DALLASi 29 16 .644

Houston 22 22 .500

HEAT 19 27 .413

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

Code

#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
void calculateStats(int teams,int wins[],int loss[],double per[]);
int displayMenu();
void sortAlpha(int teams,string names[],int wins[],int loss[],double per[]);
void print(int teams,string names[],int wins[],int loss[],double per[]);
void sortPercentage (int teams,string names[],int wins[],int loss[],double per[]);
int maxPercent (int teams,double per[]);
int minPercent (int teams,double per[]);
void update (int teams,string names[],int wins[],int loss[],double per[]);
void printReport (int teams,string names[],int wins[],int loss[],double per[]);
int main()
{
   const int totalTeam=8;
   int option;
   string names[]={"KNICKS","NETS","LAKERS","Atlanta","Chigago","DALLASi","Houston","HEAT"};
   int wins[]={26,17,16,24,23,29,22,19};
   int loss[]={16,28,27,20,21,16,22,27},pos;
   double Percentage[totalTeam];
   calculateStats(totalTeam,wins,loss,Percentage);
   do
   {
       option=displayMenu();
       switch (option)
       {
       case 1:
           sortAlpha(totalTeam,names,wins,loss,Percentage);
           print(totalTeam,names,wins,loss,Percentage);
           break;
       case 2:
           sortPercentage(totalTeam,names,wins,loss,Percentage);
           print(totalTeam,names,wins,loss,Percentage);
           break;
       case 3:
           pos=maxPercent(totalTeam,Percentage);
           cout<<"Best team :"<<names[pos]<<" Wins: "<<wins[pos]<<" Loss: "<<loss[pos]<<" Percentage: "<<Percentage[pos]<<endl<<endl;
           break;
       case 4:
           pos=minPercent(totalTeam,Percentage);
           cout<<"Worst team :"<<names[pos]<<" Wins: "<<wins[pos]<<" Loss: "<<loss[pos]<<" Percentage: "<<Percentage[pos]<<endl<<endl;
           break;
       case 5:
           update(totalTeam,names,wins,loss,Percentage);
           break;
       case 6:
           printReport(totalTeam,names,wins,loss,Percentage);
           cout<<"Thnak you for using my app\n\n";
           break;
       default:
           cout<<"Invalid choice try agian !!"<<endl<<endl;
           break;
       }
   }while(option!=6);
   return 1;
}
int maxPercent (int teams,double per[])
{
   double maxPer=per[0];
   int maxIndex=0;
   for(int i=0;i<teams;i++)
   {
       if(maxPer<per[i])
       {
           maxIndex=i;
           maxPer=per[i];
       }
   }
   return maxIndex;
}
int minPercent (int teams,double per[])
{
   double minPer=per[0];
   int minIndex=0;
   for(int i=0;i<teams;i++)
   {
       if(minPer>per[i])
       {
           minIndex=i;
           minPer=per[i];
       }
   }
   return minIndex;
}
void update (int teams,string names[],int wins[],int loss[],double per[])
{
   string name;
   cout<<"Enter the name of the teams to update its states: ";
   cin>>name;
   int pos=-1;
   for(int i=0;i<teams;i++)
       if(name==names[i])
       {
           pos=i;
           break;
       }
   if(pos<0)
   {
       cout<<"Teams not in the list!"<<endl<<endl;
       return;
   }
   cout<<"Current states :"<<endl;
   cout<<"Wins: "<<wins[pos]<<endl;
   cout<<"Loss: "<<loss[pos]<<endl;
  
   cout<<"\nEnter new win stat for "<<name<<" :";
   cin>>wins[pos];
   cout<<"Enter new loss stat for "<<name<<" :";
   cin>>loss[pos];

   per[pos]=(wins[pos]/(double)(wins[pos]+loss[pos]));
  
   cout<<"States for the team "<<name<<" has been updated"<<endl<<endl;
}
void printReport (int teams,string names[],int wins[],int loss[],double per[])
{
   int percentage,totalWin=0,totalLoss=0;
   cout<<"\n\nBASKETBALL STATISTICS"<<endl;
   cout<<"==================================="<<endl;
   cout<<"TEAM\tWINS\tLOSSES\tPERCENTAGE"<<endl;
   cout<<"==================================="<<endl;
   for(int i=0;i<teams;i++)
   {
       percentage=(per[i])*100;
       cout<<names[i]<<"\t"<<wins[i]<<"\t"<<loss[i]<<"\t"<<percentage<<"%"<<endl;
       totalLoss+=loss[i];
       totalWin+=wins[i];
   }
   percentage=(totalWin/(double)(totalLoss+totalWin))*100;
   cout<<"TOTALS\t"<<totalWin<<"\t"<<totalLoss<<"\t"<<percentage<<"%"<<endl;
   cout<<endl;
}
void sortPercentage (int teams,string names[],int wins[],int loss[],double per[])
{
   string tempName;
   int tempWin;
   int tempLoss;
   double tempPer;
   for(int i=0;i<teams;i++)
   {      
       for(int j=i+1;j<teams;j++)
       {
           if(per[i]<per[j])
           {
               tempName =names[i];
               names[i]=names[j];
               names[j]=tempName;

               tempWin =wins[i];
               wins[i]=wins[j];
               wins[j]=tempWin;

               tempLoss =loss[i];
               loss[i]=loss[j];
               loss[j]=tempLoss;

               tempPer =per[i];
               per[i]=per[j];
               per[j]=tempPer;
              
           }
       }
   }
}
void print(int teams,string names[],int wins[],int loss[],double per[])
{
   cout<<fixed<<setprecision(3);
   cout<<"\n\nTeam\tWins\tLosses\tPrcentage"<<endl;
   for(int i=0;i<teams;i++)
   {
       cout<<names[i]<<"\t"<<wins[i]<<"\t"<<loss[i]<<"\t"<<per[i]<<endl;
   }
   cout<<endl;
}
void sortAlpha(int teams,string names[],int wins[],int loss[],double per[])
{
   string tempName;
   int tempWin;
   int tempLoss;
   double tempPer;
   for(int i=0;i<teams;i++)
   {      
       for(int j=i+1;j<teams;j++)
       {
           if(names[i]>names[j])
           {
               tempName =names[i];
               names[i]=names[j];
               names[j]=tempName;

               tempWin =wins[i];
               wins[i]=wins[j];
               wins[j]=tempWin;

               tempLoss =loss[i];
               loss[i]=loss[j];
               loss[j]=tempLoss;

               tempPer =per[i];
               per[i]=per[j];
               per[j]=tempPer;
              
           }
       }
   }
}
void calculateStats(int teams,int wins[],int loss[],double per[])
{
   for(int i=0;i<teams;i++)
   {
       per[i]=(wins[i]/(double)(wins[i]+loss[i]));
   }
}
int displayMenu()
{
   int choice;
   cout<<"MAIN MENU\n-----------------"<<endl;
   cout<<"1.Display Teams\n2.Team Standings\n3.Best Team\n4.Worst Team\n5.Update Statistics\n6.Exit"<<endl;
   cout<<"Enter your choice: ";
   cin>>choice;
   return choice;
}

outputs

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
This project will allow you to practice with one dimensional arrays, function and the same time...
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
  • Using Java In this assignment we are working with arrays. You have to ask the user...

    Using Java In this assignment we are working with arrays. You have to ask the user to enter the size of the integer array to be declared and then initialize this array randomly. Then use a menu to select from the following Modify the elements of the array. At any point in the program, if you select this option you are modifying the elements of the array randomly. Print the items in the array, one to a line with their...

  • use C++            Project 6 1. Using vectors or arrays, write a function named word_rev() that reverse...

    use C++            Project 6 1. Using vectors or arrays, write a function named word_rev() that reverse any given word. 2. Write a program that will: Ask the user to enter a word. Save the entry as word_entered. Call word_rev on the entry Display the reversed entry (word_entered) 3. Write a function named prime() that determine whether or not a given number n (greater than one) is prime. The algorithm: If n is even then n is not a prime number...

  • Using c 3 File Input & Data Processing Reading data from a file is often done in order to pro...

    using c 3 File Input & Data Processing Reading data from a file is often done in order to process and aggregate it to get ad- ditional results. In this activity you will read in data from a file containing win/loss data from the 2011 Major League Baseball season. Specifically, the file data/mlb_nl_2011.txt contains data about each National League team. Each line contains a team name fol- lowed by the number of wins and number of losses during the 2011...

  • Tasks Write a program that prints in text mode Project 2 written by YOURNAME And shows...

    Tasks Write a program that prints in text mode Project 2 written by YOURNAME And shows in a graphical way, as shown below, the names stored in a file. The coordinates to print the names will be also read from another file. Here is an example of what your graphic output should look like with the two files that are provided for test purposes. Drawing Panel Adam Bernie Cameron Daniel Fanny Gerard Harold Issac Jackie Raitlyn Note that the colors...

  • #include <stdio.h> // Define other functions here to process the filled array: average, max, min, sort,...

    #include <stdio.h> // Define other functions here to process the filled array: average, max, min, sort, search // Define computeAvg here // Define findMax here // Define findMin here // Define selectionSort here ( copy from zyBooks 11.6.1 ) // Define binarySearch here int main(void) { // Declare variables FILE* inFile = NULL; // File pointer int singleNum; // Data value read from file int valuesRead; // Number of data values read in by fscanf int counter=0; // Counter of...

  • C++ Programming

    PROGRAM DESCRIPTIONIn this project, you have to write a C++ program to keep track of grades of students using structures and files.You are provided a data file named student.dat. Open the file to view it. Keep a backup of this file all the time since you will be editing this file in the program and may lose the content.The file has multiple rows—each row represents a student. The data items are in order: last name, first name including any middle...

  • Debug and fix the Java console application that uses 2 dimensional arrays but the application does...

    Debug and fix the Java console application that uses 2 dimensional arrays but the application does not compile nor execute. Student enters only integers to select courses for registration from a menu. No data type validation of the user menu selection is checked or required. The program terminates only when the student closes it. No registration of other courses not displayed by the program . No registration more than once for the same course. No registration for more than 9...

  • Project Description: In this project, you will combine the work you’ve done in previous assignments to...

    Project Description: In this project, you will combine the work you’ve done in previous assignments to create a separate chaining hash table. Overview of Separate Chaining Hash Tables The purpose of a hash table is to store and retrieve an unordered set of items. A separate chaining hash table is an array of linked lists. The hash function for this project is the modulus operator item%tablesize. This is similar to the simple array hash table from lab 5. However, the...

  • PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4...

    PLEASE INCLUDE SAW-PROMPTS FOR 2 PLAYERS NAMES(VALIDATE NAMES). SHOW MENU (PLAYER MUST SELECT FROM MENU B4 THE GAME STARTS 1=PLAY GAME, 2=SHOW GAME RULES, 3=SHOW PLAYER STATISTICS, AND 4=EXIT GAME WITH A GOODBYE MESSAGE.) PLAYERS NEED OPTION TO SHOW STATS(IN A DIFFERNT WINDOW-FOR OPTION 3)-GAME SHOULD BE rock, paper, scissor and SAW!! PLEASE USE A JAVA GRAPHICAL USER INTERFACE. MUST HAVE ROCK, PAPER, SCISSORS, AND SAW PLEASE This project requires students to create a design for a “Rock, Paper, Scissors,...

  • Program 7 Arrays: building and sorting (100 points) Due: Friday, October 30 by 11:59 PM Overview...

    Program 7 Arrays: building and sorting (100 points) Due: Friday, October 30 by 11:59 PM Overview For this assignment, write a program that will calculate the quiz average for a student in the CSCI 240 course. The student's quiz information will be needed for later processing, so it will be stored in an array. For the assignment, declare one array that will hold a maximum of 12 integer elements (ie. the quiz scores). It is recommended that this program be...

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