CIS Logo SVC Logo

   Computing & Information Systems
   Department

 

Schoology Facebook        Search CIS Site      Tutorials

Software Design Using C++



Review of Functions and Parameters



Answering the Question


Your rewrite of the CalculateCost function was as follows. In addition, you chose Answer C, also shown below, as your rewrite of the Results function. This is correct. Note that it calls CalculateCost correctly (with 2 parameters and an answer returned in the function name) and also sends back the updated value in reference parameter TotalCost.


float CalculateCost(float Price, int NumPurchased)
   {
   float TempCost;

   TempCost = Price * NumPurchased;
   if (TempCost > 80.0)
      TempCost = TempCost - 5.0;

   return TempCost;
   }

void Results(float Price, int NumPurchased, float & TotalCost)
   {
   float Cost;

   Cost = CalculateCost(Price, NumPurchased);
   TotalCost = TotalCost + Cost;
   cout << "Unit price: " << Price << "   Number purchased: "
      << NumPurchased << "   Cost: " << Cost << endl << endl;
   }

Now try putting all of the pieces together. Write the complete working program, with your 2 rewritten functions within it. Then click on NEXT to see the answer.

You can go back to the overall review listing: Review of Introductory Topics.

Back to the main page for Software Design Using C++

Author: Br. David Carlson with contributions by Br. Isidore Minerd
Last updated: January 15, 2013
Disclaimer