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 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
// area of shape.cpp : main project file.
#include "stdafx.h"
#include <iostream>
using namespace System;
using namespace std;
class Area_Finder
{
double height, base1, base2, radius;
public:
void set_dim(double &, double &, double &, double &);
double Calc_Rect();
double Calc_Tri();
double Calc_Trap();
double Calc_Cir();
};
void Area_Finder::set_dim(double &h, double &b1, double &b2, double &r)
{
height = h;
base1 = b1;
base2 = b2;
radius = r;
}
double Area_Finder::Calc_Rect()
{
return height * base1;
}
double Area_Finder::Calc_Tri()
{
return (.5) * (height * base1);
}
double Area_Finder::Calc_Trap()
{
return (height * (base1 + base2)) / 2;
}
double Area_Finder::Calc_Cir()
{
return (3.14159265 * radius * radius);
}
int main()
{
cout << "[1] Rectangle\n";
cout << "[2] Triangle\n";
cout << "[3] Trapezoid\n";
cout << "[4] Circle\n";
cout << "[5] Exit\n\n";
cout << "What is the shape you would like to find the Area of? ";
int a1;
cin >> a1;
while(a1 < 1 || a1 > 5) {
cout << "\nError, not a valid answer, try again.\n";
cin >> a1;
}
Area_Finder shape;
double h, b1, b2, r;
switch(a1)
{
case 1:
{
cout << "\n\nHeight? ";
cin >> h;
cout << "\n\nBase? ";
cin >> b1;
shape.set_dim(h,b1,b2,r);
cout << "\n\nArea of Rectangle: " << shape.Calc_Rect() << "\n\n";
break;
}
case 2:
{
cout << "\n\nHeight? ";
cin >> h;
cout << "\n\nBase? ";
cin >> b1;
shape.set_dim(h,b1,b2,r);
cout << "\n\nArea of Triangle: " << shape.Calc_Tri() << "\n\n";
break;
}
case 3:
{
cout << "\n\nHeight? ";
cin >> h;
cout << "\n\nBase1? ";
cin >> b1;
cout << "\n\nBase2? ";
cin >> b2;
shape.set_dim(h,b1,b2,r);
cout << "\n\nArea of Trapezoid: " << shape.Calc_Trap() << "\n\n";
break;
}
case 4:
{
cout << "\n\nRadius? ";
cin >> r;
shape.set_dim(h,b1,b2,r);
cout << "\n\nArea of Circle: " << shape.Calc_Cir() << "\n\n";
break;
}
case 5:
{
return 0;
break;
}
}
return 0;
}
|