Example of Using Structures - 1

In the solution to the second lab assignment, we passed several parameters to functions. The parameters were all related in some way: they represented costs for installing carpet:
int sqYards;              // Square yards purchased 
float CostPerSqYard;      // Cost per square yard
float laborPerSqYard;     // Labor per square yard
float discountPercentage; // Discount rate applied to carpet cost
float floorPrep;          // Floor preparation cost
float carpetCost;         // Total cost for carpet
float laborCost;          // Total cost for labor
float carpetDiscount;     // Total discount for customer
float totalTax;           // Total tax on purchase
float totalCharge;        // Total charge for customer
Another approach would be to use structured data:
struct InputCost     
{
  int sqYards;              // Square yards purchased 
  float costPerSqYard;      // Cost per square yard 
  float laborPerSqYard;     // Labor per square yard
  float discountPercentage; // Discount rate
  float floorPrep;          // Floor preparation cost
};

struct TotalCost     
{
  float carpetCost;         // total carpet cost
  float laborCost;          // total labor cost
  float carpetDiscount;     // discount on carpet
  float totalTax;           // tax on purchase
  float totalCharge;        // total charge to customer
};
Previous page
Next page

Back to Lesson 14 Index
Back to Outline