CIS Logo SVC Logo

   Computing & Information Systems


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 selected Answer B, also shown below, for your rewrite of the Results function. Although this version correctly calls the CalculateCost function, it fails to send back the updated value in parameter TotalCost since this parameter is not a reference parameter. (A reference parameter is indicated by an ampersand.) Go back and try this part again.

void CalculateCost(float Price, int NumPurchased, float & Cost)
   Cost = Price * NumPurchased;
   if (Cost > 80.0)
      Cost = Cost - 5.0;

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

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

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