1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
//******************************************************************
// Canvas program
// This program computes the dimensions and costs of materials
// to build a painting canvas of given dimensions. The user is
// asked to enter the length and width of the painting and the
// costs of the wood (per inch) and canvas (per square inch)
//******************************************************************
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <fstream>
using namespace std;
void FindData(double, double, double, double);
void FindWood(double&, double&, double);
void FindCanvas(double&, double&);
void FindTotalCost(double&, double&, double&);
void PrintResults();
const int OVERLAP = 5; // Extra inches needed for canvas overlap on frame
int main()
{
double length; // Length of painting in inches
double width; // Width of painting in inches
double woodCost; // Cost of wood per inch in dollars
double canvasCost; // Cost of canvas per square foot
double lengthOfWood; // Amount of wood to buy
double canvasWidth; // Width of canvas to buy
double canvasLength; // Length of canvas to buy
double canvasAreaInches; // Area of canvas in square inches
double totalCanvasCost; // Total cost of canvas being bought
double totalWoodCost; // Total cost of wood being bought
double totalCost; // Total cost of materials
cout << fixed << showpoint;
FindData(length, width, woodCost, canvasCost);
FindWood(lengthOfWood, totalWoodCost, woodCost);
FindCanvas(canvasAreaInches, totalCanvasCost);
FindTotalCost(totalCanvasCost, totalWoodCost, totalCost);
PrintResults();
getch();
return 0;
}
void FindData(double length, double width, double woodCost, double canvasCost)
{
cout << "Enter length and width of painting:" << endl;
cin >> length >> width;
cout << "Enter cost per inch of the framing wood in dollars:"
<< endl;
cin >> woodCost;
cout << "Enter cost per square inch of canvas in dollars:"
<< endl;
cin >> canvasCost;
}
void FindWood(double& lengthOfWood, double& totalWoodCost, double woodCost, double& length, double& width)
{
lengthOfWood = (length + width) * 2;
totalWoodCost = lengthOfWood * woodCost;
}
void FindCanvas(double& canvasAreaInches, double& totalCanvasCost, double& width, double& length, double& canvasCost, double& canvasWidth, double& canvasLength)
{
canvasWidth = width + OVERLAP;
canvasLength = length + OVERLAP;
canvasAreaInches = canvasWidth * canvasLength;
totalCanvasCost = canvasAreaInches * canvasCost;
}
void FindTotalCost(double& totalCanvasCost, double& totalWoodCost, double& totalCost)
{
totalCost = totalWoodCost + totalCanvasCost;
}
void PrintResult(double& length, double& width, double& lengthOfWood, double& canvasLength, double& canvasWidth, double& woodCost, double& canvasCost, double& totalWoodCost, double& totalCanvasCost, double& totalCost)
{
// Print the dimensions
cout << endl << setprecision(1);
cout << "Painting is " << length << " in. long and "
<< width << " in. wide." << endl;
cout << setw(5) << ' ' << "Buy " << lengthOfWood << " in. of wood." << endl;
cout << setw(5) << ' ' << "Buy a " << canvasLength << " in. by "
<< canvasWidth << " in. canvas" << endl;
//Print the costs
cout << endl << setprecision(2);
cout << "The wood costs $" << woodCost << " per in." << endl;
cout << "The canvas costs $" << canvasCost << " per sq. in." << endl;
cout << endl;
cout << "Your costs will be: " << endl;
cout << setw(5) << ' ' << "Wood cost - $" << totalWoodCost << endl;
cout << setw(5) << ' ' << "Canvas cost - $" << totalCanvasCost << endl;
cout << "Total cost of materials $" << totalCost << endl;
}
| |