Search


Software Design Using C++



Review of Functions and Parameters



Answering the Question


Let's first rewrite the CalculateCost function. Here are possible answers to this. Click on the one that you think is the best solution.
  • Answer A

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

  • Answer B

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

  • Answer C

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

  • Answer D

    
    void CalculateCost(float Price, int NumPurchased, float & Cost)
       {
       Cost = Price * NumPurchased;
       if (Cost > 80.0)
          Cost = Cost - 5.0;
       }
    
Back to the main page for Software Design Using C++

Authors: Br. David Carlson and Br. Isidore Minerd
Last updated: August 27, 2009