header
//---------------------------------------------------------
// Canvas Cost Calculator
//
// Given the dimensions of a painting (inches), the cost of
// canvas (dollars per square foot), and the cost of the
// wood for the frame (dollars per linear inch), this program
// calculates and displays how many inches of wood to buy, 
// how much canvas to buy, the cost of the wood and canvas,
// and the total cost.
//
// In this version, the input values come from a file whose
// name is entered by the user.
//
// D. Searls
// Asbury College
// Jan 2002
//---------------------------------------------------------

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

// function prototypes

void inputDimensionsAndUnitCosts(double& width, double& height,
                                 double& unitCostOfWood,
                                 double& unitCostOfCanvas);
double lengthOfWood(double w, double h);
void findSizeOfCanvas(double w, double h,
                      double& canvasWidth, double& canvasHgt);
double costOfWood(double length, double unitCost);
double costOfCanvas(double w, double h, double unitCost);
void displayPurchaseDetails(double canvasWidth, double canvasHgt,
                            double canvasCost, double woodLength,
                            double woodCost, double totalCost);

int main()
{
    double height, width;   // Height and width of painting
    double canvasHgt,
           canvasWidth;     // Height and width of canvas
    double framePerimeter;  // Perimeter of frame
    double unitCostWood;    // Cost (per linear inch) of wood for frame
    double unitCostCanvas;  // Cost (per square foot) of canvas
    double woodCost;        // Cost of wood
    double canvasCost;      // Cost of canvas
    double totalCost;       // Total cost of wood and canvas

    inputDimensionsAndUnitCosts(width, height,
                                unitCostWood, unitCostCanvas);

    framePerimeter = lengthOfWood(width, height);
    woodCost = costOfWood(framePerimeter, unitCostWood);

    findSizeOfCanvas(width, height, canvasWidth, canvasHgt);
    canvasCost = costOfCanvas(canvasWidth, canvasHgt, unitCostCanvas);
    
    totalCost = woodCost + canvasCost;

    displayPurchaseDetails(canvasWidth, canvasHgt,
                           canvasCost, framePerimeter,
                           woodCost, totalCost);
    return 0;
}

//---------------------------------------------------------
// inputDimensionsAndUnitCosts
//
// Returns: void
//
// Purpose: allow the user to enter the width and height
//   of the painting, the cost of the wood frame material
//   (per linear inch) and the cost of the canvas (per
//   square foot).
//
// Out parameters: width, height, unitCostOfWood, and
//   unitCostOfCanvas
//--------------------------------------------------------
void inputDimensionsAndUnitCosts(double& width, double& height,
                                 double& unitCostOfWood,
                                 double& unitCostOfCanvas)
{
    cout << "Width of canvas: ";
    cin >> width;
    cout << "Height of canvas: ";
    cin >> height;
    cout << "Cost of wood per linear inch: ";
    cin >> unitCostOfWood;
    cout << "Cost of canvas per square foot: ";
    cin >> unitCostOfCanvas;
}

//---------------------------------------------------------
// lengthOfWood
//
// Returns: the length of wood that must be purchased to
//   construct the frame for the canvas.
//
// In parameters: w (width) and h (height) of painting
//--------------------------------------------------------
double lengthOfWood(double w, double h)
{
    // Four inches added to allow for cutting miters

    return (w + h)*2.0 + 4.0;
}

//---------------------------------------------------------
// findSizeOfCanvas
//
// Returns: void
//
// Purpose: find the dimensions of the canvas necessary
//   for a painting of size w by h.
//
// In parameters: w, h
//
// Out parameters: canvasWidth, canvasHgt
//--------------------------------------------------------
void findSizeOfCanvas(double w, double h, double& canvasWidth, double& canvasHgt)
{
    canvasWidth = w + 5.0;
    canvasHgt = h + 5.0;
}

//---------------------------------------------------------
// costOfWood
//
// Returns: the cost of the wood need to construct the
//   frame for the canvas.
//
// In parameters: length of wood needed (inches) and
//   unitCost (cost per inch).
//--------------------------------------------------------
double costOfWood(double length, double unitCost)
{
    return length*unitCost;
}

//---------------------------------------------------------
// costOfCanvas
//
// Returns: the cost of the canvas need for the painting.
//
// In parameters: area of canvas (square inches), unitCost
//   (cost per square foot)
//--------------------------------------------------------
double costOfCanvas(double w, double h, double unitCost)
{
    return (w*h/144.0) * unitCost;
}

//---------------------------------------------------------
// displayPurchaseDetails
//
// Returns: void
//
// Purpose: display the dimensions of the painting and all
//   of the purchase details.
//
// In parameters: width and height of painting, canvasWidth,
//   canvasHgt, unitCanvasCost, canvasCost, woodLength,
//   unitWoodCost, woodCost, totalCost
//--------------------------------------------------------
void displayPurchaseDetails(double canvasWidth, double canvasHgt,
                            double canvasCost, double woodLength,
                            double woodCost, double totalCost)
{
    cout << fixed << setprecision(1);

    cout << endl;
    cout << "You will need " << woodLength
         << " inches of wood for the frame.\n";
    cout << "The canvas must be "
         << canvasWidth << " inches wide and "
         << canvasHgt << " inches high.\n\n";

    cout << setprecision(2);
    cout << "The wood will cost $" << woodCost << ". \n";
    cout << "The canvas will cost $" << canvasCost << ".\n";
    cout << "The total cost will be $" << totalCost << ".\n\n";
}