Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NBA MVP Loop c++ How do you get this program to get both player input and then d

ID: 3557380 • Letter: N

Question

NBA MVP Loop c++

How do you get this program to get both player input and then display results(As described on bottom)

#include

const int NUM_YEARS=15;//The number of years

const int NAME_SIZE=32;//The max size of the player name string

const int POINTS_GAME=16;

const int MIN_YEAR=2001;//The lowest year is 1999

const int MAX_YEAR=2014;//The highest year is 2014

int getYear(int count);

int binarySearch(int [],int,int);

void displayProd(char[][NAME_SIZE]);/////INCOMPLETE

int main()

{;

int yr[NUM_YEARS]={2001,2002,2003,2004,2005,2006,2007,2008,

2009,2010,2011,2012,2013,2014};

?

//MVP Names from 1999-2014

char names[NUM_YEARS][NAME_SIZE]=

{

"Allen Iverson",

"Tim Duncan",

"Tim Duncan",

"Kevin Garnett",

"Steve Nash",

"Steve Nash",

"Dirk Nowitzki",

"Kobe Bryant",

"LeBron James",

"LeBron James",

"Derrick Rose",

"LeBron James",

"LeBron James",

"Kevin Durant"

};

char description[NUM_YEARS][POINTS_GAME]=

{

"31.1",

"25.5",

"23.3",

"24.2",

"15.5",

"18.8",

"24.6",

"28.3",

"28.4",

"29.7",

"25.0",

"27.1",

"26.8",

"32.0"

};

int yrNum;

int index;

int index_2;

int c=0;

do

{

yrNum=getYear(c);

index=binarySearch(yr,NUM_YEARS,yrNum);

if(index==-1)

cout<<"That product number was not found. ";

else

cout<<"Player: "<< names[index]<

cout<<"PPG: "<

c++;

}while(true);

system("pause");

system("cls");

return 0;

}

int getYear(int count)

{

int yearNum;

cout<<"Displays MVPs from 2000-2001 season to 2013-2014"<

cout<<"Example 2004-2005 season you would enter 2005."<

cout<<"Enter the year from the 2000-2001 season to 2013-2014: ";

cout<<"Enter player "<<((count%2)+1)<

cin>>yearNum;

while(yearNumMAX_YEAR)

{

cout<<"Please enter between 2001 and 2014 ";

cin>>yearNum;

}

int t=0;

count=yearNum;

t=count;

return t;

?

}

int binarySearch(int array[], int numElems, int value)

{

int first = 0, // First array element

last = numElems-1, // Last array element

middle, // Mid point of search

position = -1; // Position of search value

bool found = false; // Flag

while (!found && first <= last)

{

middle = (first + last) / 2; // Calculate mid point

if (array[middle] == value) // If value is found at mid

{

found = true;

position = middle;

}

else if (array[middle] > value) // If value is in lower half

last = middle - 1;

else

first = middle + 1; // If value is in upper half

}

return position;

}

Displays MVPs from 2000-2001 season to 2013-2014
Example 2004-2005 season you would enter 2005.
Enter the year from the 2000-2001 season to 2013-2014:
Enter player 1
2001
Player: Allen Iverson
PPG: 31.1
Displays MVPs from 2000-2001 season to 2013-2014
Example 2004-2005 season you would enter 2005.
Enter the year from the 2000-2001 season to 2013-2014:
Enter player 2
2005
Player: Steve Nash
PPG: 15.5
Displays MVPs from 2000-2001 season to 2013-2014
Example 2004-2005 season you would enter 2005.
Enter the year from the 2000-2001 season to 2013-2014:
Enter player 1

HOW DO YOU GET IT LIKE THIS

Displays MVPs from 2000-2001 season to 2013-2014
Example 2004-2005 season you would enter 2005.
Enter the year from the 2000-2001 season to 2013-2014:

Displays MVPs from 2000-2001 season to 2013-2014

Enter the year from the 2000-2001 season to 2013-2014:
Enter player 1: 2001

Enter player 2: 2005

2001
Player: Allen Iverson PPG:

31.1

2005
Player: Steve Nash
PPG: 15.5

Explanation / Answer

Program Code:

#include "stdafx.h"

#include <iostream>
using namespace std;

const int NUM_YEARS=15;//The number of years

const int NAME_SIZE=32;//The max size of the player name string

const int POINTS_GAME=16;

const int MIN_YEAR=2001;//The lowest year is 1999

const int MAX_YEAR=2014;//The highest year is 2014

int getYear(int count);

int binarySearch(int [],int,int);

void displayProd(char[][NAME_SIZE]);/////INCOMPLETE

int main()

{

int yr[NUM_YEARS]={2001,2002,2003,2004,2005,2006,2007,2008,

2009,2010,2011,2012,2013,2014};


//MVP Names from 1999-2014

char names[NUM_YEARS][NAME_SIZE]=

{

"Allen Iverson",

"Tim Duncan",

"Tim Duncan",

"Kevin Garnett",

"Steve Nash",

"Steve Nash",

"Dirk Nowitzki",

"Kobe Bryant",

"LeBron James",

"LeBron James",

"Derrick Rose",

"LeBron James",

"LeBron James",

"Kevin Durant"

};

char description[NUM_YEARS][POINTS_GAME]=

{

"31.1",

"25.5",

"23.3",

"24.2",

"15.5",

"18.8",

"24.6",

"28.3",

"28.4",

"29.7",

"25.0",

"27.1",

"26.8",

"32.0"

};

int yrNum[2];

int index[2];

int index_2;

int c=0;

cout<<"Displays MVPs from 2000-2001 season to 2013-2014"<<endl;

cout<<"Example 2004-2005 season you would enter 2005."<<endl;

cout<<"Enter the year from the 2000-2001 season to 2013-2014: "<<endl;

for(int i=0;i<2;i++)
{
   yrNum[i]=getYear(c);
   index[i]=binarySearch(yr,NUM_YEARS,yrNum[i]);
   c++;
   if(index[i]==-1)
       cout<<"That product number was not found. ";

}
for(int i=0;i<2;i++)
{

cout<<"Player: "<< names[index[i]]<<endl;

cout<<"PPG: "<<description[index[i]]<<endl;


}
system("pause");

system("cls");

return 0;

}

int getYear(int count)

{

int yearNum;

cout<<"Enter player "<<((count%2)+1)<<" ";

cin>>yearNum;

while(yearNum>MAX_YEAR)

{

cout<<"Please enter between 2001 and 2014 ";

cin>>yearNum;

}

int t=0;

count=yearNum;

t=count;

return t;

}

int binarySearch(int array[], int numElems, int value)

{

int first = 0, // First array element

   last = numElems-1, // Last array element

   middle, // Mid point of search

   position = -1; // Position of search value

bool found = false; // Flag

while (!found && first <= last)

{

   middle = (first + last) / 2; // Calculate mid point

   if (array[middle] == value) // If value is found at mid

   {

       found = true;

       position = middle;

   }

   else if (array[middle] > value) // If value is in lower half

       last = middle - 1;

   else

       first = middle + 1; // If value is in upper half

}

return position;

}

Output:

Displays MVPs from 2000-2001 season to 2013-2014
Example 2004-2005 season you would enter 2005.
Enter the year from the 2000-2001 season to 2013-2014:
Enter player 1 2001
Enter player 2 2005
Player: Allen Iverson
PPG: 31.1
Player: Steve Nash
PPG: 15.5
Press any key to continue . . .