SOURCE FILE: conepain.cpp
//******************************************************************
// ConePaint program
// This program computes the cost of painting traffic cones in
// each of three different colors, given the height and diameter
// of a cone in inches, and the cost per square foot of each of
// the paints
//******************************************************************
#include <iostream>
#include <iomanip> // For setw() and setprecision()
#include <cmath> // For sqrt()
using namespace std;
const float HT_IN_INCHES = 30.0; // Height of a typical cone
const float DIAM_IN_INCHES = 8.0; // Diameter of base of cone
const float INCHES_PER_FT = 12.0; // Inches in 1 foot
const float RED_PRICE = 0.10; // Price per square foot
// of red paint
const float BLUE_PRICE = 0.15; // Price per square foot
// of blue paint
const float GREEN_PRICE = 0.18; // Price per square foot
// of green paint
const float PI = 3.14159265; // Ratio of circumference
// to diameter
int main()
{
float heightInFt; // Height of the cone in feet
float diamInFt; // Diameter of the cone in feet
float radius; // Radius of the cone in feet
float surfaceArea; // Surface area in square feet
float redCost; // Cost to paint a cone red
float blueCost; // Cost to paint a cone blue
float greenCost; // Cost to paint a cone green
cout << fixed << showpoint; // Set up floating-pt.
// output format
// Convert dimensions to feet
heightInFt = HT_IN_INCHES / INCHES_PER_FT;
diamInFt = DIAM_IN_INCHES / INCHES_PER_FT;
radius = diamInFt / 2.0;
// Compute surface area of the cone
surfaceArea = PI * radius *
sqrt(radius*radius + heightInFt*heightInFt);
// Compute cost for each color
redCost = surfaceArea * RED_PRICE;
blueCost = surfaceArea * BLUE_PRICE;
greenCost = surfaceArea * GREEN_PRICE;
// Print results
cout << setprecision(3);
cout << "The surface area is " << surfaceArea << " sq. ft."
<< endl;
cout << "The painting cost for" << endl;
cout << " red is" << setw(8) << redCost << " dollars"
<< endl;
cout << " blue is" << setw(7) << blueCost << " dollars"
<< endl;
cout << " green is" << setw(6) << greenCost << " dollars"
<< endl;
return 0;
}