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

Your lease is up and it’s time to move. Unfortunately, you have a lot of stuff a

ID: 3682316 • Letter: Y

Question

Your lease is up and it’s time to move. Unfortunately, you have a lot of stuff and you don’t want to spend too much time moving it because you’d rather be practicing your programming skills. Thankfully, you have friends who can help, though this help comes at a cost. Your friends can move 20 boxes an hour, but they require one 16 inch (diameter) pizza for this work. Write a function in C++ that takes the number of boxes you have and returns how much square feet of pizza you will have to buy. Use the function header: sqFtPizza(int numBoxes) and have it return the square feet of pizza as a float. Assume that the pizzas are perfectly round and that your friends require a full pizza even if they only work a partial hour. (In case you’ve forgotten your geometry, the area of a circle is pi*r^2. Use 3.14159 for pi.) PLEASE NOTE: You don't have to include a main() function. The only thing that should be in your solution is the function definition.

Explanation / Answer

//Use this below code for method sqFtPizza only

/**The method sqFtPizza that takes number of boxes as input
and retunrns the square feet of pizza required.*/
float sqFtPizza(int numBoxes)
{

   //Set constant for diameter, number of boxes
   //and PI value
   const int DIAMETER=16;
   const int BOXES_PER_HOUR=20;
   const float PI=3.14159;


   //calculate the radius
   int radius=DIAMETER/2.0;


   //Calculate the number of hours
   int hours=numBoxes/BOXES_PER_HOUR;


   //Check if the partial hour then increment the hours by one
   if(numBoxes%BOXES_PER_HOUR!=0)
       hours++;


   //return the area of the pizza
   return PI*radius*radius*hours;

}

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

//Note : This is the test program.Do not copy this code to your homework.

/**C++ test program that takes the number of boxes
and finds the square feet of the pizza required */
//squarefeet.cpp
#include<iostream>
using namespace std;
//function header
float sqFtPizza(int numBoxes);
int main()
{
   //set number of boxes
   int numBoxes=100;
   cout<<"Number of Boxes : "<<numBoxes<<endl;
   cout<<"Area of pizza required : "
       <<sqFtPizza(numBoxes)<<endl;

   //pause the program output on console
   system("pause");
   return 0;
}
/**The method sqFtPizza that takes number of boxes as input
and retunrns the square feet of pizza required.*/
float sqFtPizza(int numBoxes)
{

   //Set constant for diameter, number of boxes
   //and PI value
   const int DIAMETER=16;
   const int BOXES_PER_HOUR=20;
   const float PI=3.14159;

   //calculate the radius
   int radius=DIAMETER/2.0;

   //Calculate the number of hours
   int hours=numBoxes/BOXES_PER_HOUR;

   //Check if the partial hour then increment the hours by one
   if(numBoxes%BOXES_PER_HOUR!=0)
       hours++;
   //return the area of the pizza
   return PI*radius*radius*hours;

}

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

Sample output:

Number of Boxes : 100
Area of pizza required : 1005.31