Computing & Information Systems    Department Search CIS Site      Tutorials

## Software Design Using C++

### Answering the Question

Your rewrite of the CalculateCost function was as follows. Choose from the list below of possible answers for a correct and compatible rewrite of the Results function.

 `````` float CalculateCost(float Price, int NumPurchased) { float TempCost; TempCost = Price * NumPurchased; if (TempCost > 80.0) TempCost = TempCost - 5.0; return TempCost; } ``````

• Answer A

 `````` 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; } ``````

• Answer B

 `````` 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; } ``````

• Answer C

 `````` 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; } ``````

• Answer D

 `````` 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
Disclaimer