Question

The data analyst for ESPN needs to calculate the statistics for Lebron Jame’s recent NBA basketball...

The data analyst for ESPN needs to calculate the statistics for Lebron Jame’s recent NBA basketball game. Write a c++program to calculate the two and three point field goal percentages based on the number of total shots attempted and total shots made. Use any of Lebron Jame’s most recent game statistics to test program (i.e. can visit stats.nba.com for statistics).

In addition to main(), also use the following six functions in your program:

getNumberOfTwoPointsMade() : a value-returning function that asks for the number of two points made. Use a return statement to send it to main().

getNumberOfThreePointsMade() : a value-returning function that asks for the number of three points made. Use a return statement to send it to main(). getTotalNumberOfShotsAttempted() : a value-returning function that asks for the total number of shots attempted. Use a return statement to send it to main(). getPercentageOfTwoPointsMade() : a value-returning function that calculates the the percentage of two points made. Use a return statement to send it to main(). getPercentageOfThreePointsMade() : a value-returning function that calculates the the percentage of three points made. Use a return statement to send it to main(). IsBetterThanChance() : a value-returning function that returns true or false (true: if he made 50% or above percentages of shots and false: if he made less than 50% percentages of shots) – Display message in main() based on this return value.

NOTE: 1. The problem requires that you determine the parameters needed for each function.

2. The main() function should display the statistics on the computer screen.

3. No Global non-constant variables should be used.

Here is my solution. Is this correct?

#include<iostream>
using namespace std;

//function prototype
int getNumberOfTwoPointsMades(int);
int getNumberOfThreeOointsMades(int);
int getNumberOfShotsAttempted(int);
double getPercentageOfTwoPointsMade(int,int);
double getPercentageOfThreePointsMade(int,int);
bool isBetterThanChance(double, double);

int main() {
  

   //prompt the user to enter the number of two points made
   cout<<"Enter the number of two points made: "<<endl;
   int numOfTwoPointsMade;  
   cin>>numOfTwoPointsMade;

      //prompt the user to enter the number of three points made
   cout<<"Enter the number of three points made: "<<endl;
   int numOfThreePointsMade;
   cin>>numOfThreePointsMade;

  
   //prompt the user to enter ther number of total shots
   cout<<"Enter the total number of shots attempted: "<<endl;
   int total;
   cin>>total;


double twoPointsPercent= getPercentageOfTwoPointsMade(numOfTwoPointsMade,total);
double threePointsPercent = getPercentageOfThreePointsMade(numOfThreePointsMade,total);
bool result =isBetterThanChance(twoPointsPercent,threePointsPercent);
  
if (result==true) {
  
cout<<"It is better than chance."<<endl;
}

else {
    cout<<"It is not better than chance."<<endl;
}
  
return 0;  
  
}


int getNumberOfTwoPointsMades(int x){
return x;
}

int getNumberOfThreeOointsMades(int y){
return y;
}

int getNumberOfShotsAttempted(int z) {
return z;
}

double getPercentageOfTwoPointsMade(int x, int z){
  
double g=(x/(z*1.0))*100;
return g;
  
}

double getPercentageOfThreePointsMade(int y, int z){
  
double k=(y/(z*1.0))*100;
return k;

  
}

bool isBetterThanChance(double g, double k) {
  
   if (g>=50.0 && k>=50.0) {
  
  
   return true;

}
   else {
return false;
  
}
}

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

The last function requires some modification as per given statement. Instead of each g and k to be >=50% which means all the shots are fired we have to check (g+k)>=50 % because both 2 point and 3 point are included in shots. (This is what I got from problem statement).

Here is the code:

#include<iostream>
using namespace std;

//function prototype
int getNumberOfTwoPointsMades(int);
int getNumberOfThreeOointsMades(int);
int getNumberOfShotsAttempted(int);
double getPercentageOfTwoPointsMade(int,int);
double getPercentageOfThreePointsMade(int,int);
bool isBetterThanChance(double, double);

int main() {
  

//prompt the user to enter the number of two points made
cout<<"Enter the number of two points made: "<<endl;
int numOfTwoPointsMade;
cin>>numOfTwoPointsMade;

//prompt the user to enter the number of three points made
cout<<"Enter the number of three points made: "<<endl;
int numOfThreePointsMade;
cin>>numOfThreePointsMade;

  
//prompt the user to enter ther number of total shots
cout<<"Enter the total number of shots attempted: "<<endl;
int total;
cin>>total;


double twoPointsPercent= getPercentageOfTwoPointsMade(numOfTwoPointsMade,total);
double threePointsPercent = getPercentageOfThreePointsMade(numOfThreePointsMade,total);
bool result =isBetterThanChance(twoPointsPercent,threePointsPercent);
  
if (result==true) {
  
cout<<"It is better than chance."<<endl;
}

else {
cout<<"It is not better than chance."<<endl;
}
  
return 0;
  
}


int getNumberOfTwoPointsMades(int x){
return x;
}

int getNumberOfThreeOointsMades(int y){
return y;
}

int getNumberOfShotsAttempted(int z) {
return z;
}

double getPercentageOfTwoPointsMade(int x, int z){
  
double g=(x/(z*1.0))*100;
return g;
  
}

double getPercentageOfThreePointsMade(int y, int z){
  
double k=(y/(z*1.0))*100;
return k;

  
}

bool isBetterThanChance(double g, double k) {
  
if (g+k>=50.0) {
  
  
return true;

}
else {
return false;
  
}
}

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

Sample output:

Sample output:

Add a comment
Know the answer?
Add Answer to:
The data analyst for ESPN needs to calculate the statistics for Lebron Jame’s recent NBA basketball...
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
  • So far your TestEqual functions have tested values but haven't made any changes... Q: If you...

    So far your TestEqual functions have tested values but haven't made any changes... Q: If you changed one of the variable values in your function, would it change the value of the variable in main? Why? Q: What are the two options for passing parameters into a function? (by _________ and by __________) What's the difference? Write a new function, MakeEqual, that takes two integers and if they are not equal (tested using your TestEqual function), displays a message and...

  • How do can I update this code (Code A): Code (A) #include using namespace std; int fibonacci(int n) { int a = 0,...

    How do can I update this code (Code A): Code (A) #include using namespace std; int fibonacci(int n) { int a = 0, b = 1, c; if (n <= 1) return n; for (int i = 2; i <= n; i++) { c = a + b; a = b; b = c; } return b; } int fibonacciRecursive(int n) { if (n <= 1) { return n; } return fibonacciRecursive(n-1) + fibonacciRecursive(n-2); } int main() { int n;...

  • Help with C++ reverse program with leading zeros. I need to put the line from the...

    Help with C++ reverse program with leading zeros. I need to put the line from the function that display the zeros in main not in the function. So how can I move the display with leading zeros in main. Thanks. Here is my code. #include <iostream> #include <cstdlib> #include <iostream> using std::cout; using std::cin; using std::endl; //function templates int reverseNum(int); int main() { //variables char buf[100]; int num; while (true) { //prompt user for input cout << "Enter the number...

  • This is for a C++ program: I'm almost done with this program, I just need to...

    This is for a C++ program: I'm almost done with this program, I just need to implement a bool function that will ask the user if they want to repeat the read_course function. I can't seem to get it right, the instructions suggest a do.. while loop in the main function. here is my code #include <iostream> #include <cstring> #include <cctype> using namespace std; const int SIZE = 100; void read_name(char first[], char last[]); void read_course(int & crn, char des[],...

  • Write a C/C++ program that simulate a menu based binary number calculator. This calculate shall have the following three...

    Write a C/C++ program that simulate a menu based binary number calculator. This calculate shall have the following three functionalities: Covert a binary string to corresponding positive integers Convert a positive integer to its binary representation Add two binary numbers, both numbers are represented as a string of 0s and 1s To reduce student work load, a start file CSCIProjOneHandout.cpp is given. In this file, the structure of the program has been established. The students only need to implement the...

  • IP requirements: Load an exam Take an exam Show exam results Quit Choice 1: No functionality...

    IP requirements: Load an exam Take an exam Show exam results Quit Choice 1: No functionality change. Load the exam based upon the user's prompt for an exam file. Choice 2: The program should display a single question at a time and prompt the user for an answer. Based upon the answer, it should track the score based upon a successful answer. Once a user answers the question, it should also display the correct answer with an appropriate message (e.g.,...

  • In C++ ***//Cat.h//*** #ifndef __Cat_h__ #define __Cat_h__ #include <string> using namespace std; struct Cat { double...

    In C++ ***//Cat.h//*** #ifndef __Cat_h__ #define __Cat_h__ #include <string> using namespace std; struct Cat { double length; double height; double tailLength; string eyeColour; string furClassification; //long, medium, short, none string furColours[5]; }; void initCat (Cat&, double, double, double, string, string, const string[]); void readCat (Cat&); void printCat (const Cat&); bool isCalico (const Cat&); bool isTaller (const Cat&, const Cat&); #endif ***//Cat.cpp//*** #include "Cat.h" #include <iostream> using namespace std; void initCat (Cat& cat, double l, double h, double tL, string eC,...

  • 81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5...

    81. The following function call doesn’t agree with its prototype:              cout << BoxVolume( 10, 5 );                    int BoxVolume(int length = {1}, int width = {1}, int height = {1});                                                     T__   F__                                                                     82. The following function is implemented to swap in memory the          argument-values passed to it:         void swap(int a, int b)                   {           int temp;             temp = a;             a = b;             b = temp;        ...

  • Fix this code so only the function prototype comes before main. #include <iostream> using namespace std;...

    Fix this code so only the function prototype comes before main. #include <iostream> using namespace std; bool isMultiple(int num1, int num2) { return num1 % num2 == 0; } int main() { char ch = 'Y'; int num1, num2; while(ch =='Y') // While ch is equal to Y { cout << "Enter two numbers(largest first): "; cin >> num1; // Getting 1st number cin >> num2; // Getting 2nd number if(isMultiple(num1, num2)) cout << num2 << " " << "IS...

  • I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using...

    I NEED A PSEUDOCODE ALGORITHM FOR THIS CODE PLEASE C++: #include #include #include #include using namespace std; int NumOfEmployees(); int TotDaysAbsent(int); double AverageAbsent(int, int); int main() {         cout << endl << "Calculate the average number of days a company's employees are absent." << endl << endl;      int numOfEmployees = NumOfEmployees();         TotDaysAbsent(numOfEmployees);    return 0; } int NumOfEmployees() {    int numOfEmployees = 0;     cout << "Please enter the number of employees in the company: ";         cin >> numOfEmployees;     while(numOfEmployees <= 0)     {            ...

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