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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
#include <ctype.h>
#include "Arch_Rect_Win.h"
using namespace std;
class Arch_Rect_Win
{
private:
int Width, Height;
double pi, p, TotalArea, PricePSqIn;
char ArchOrRect;
public:
Arch_Rect_Win();
double getHeight() const;
double getWidth() const;
double getArea();
double getPrice() const;
double getPricePSqIn() const;
char getRectOrArch() const;
int setData(char *, char *, char *, char );
};
int main()
{
Arch_Rect_Win aWin;
char h[10], w[10],p[10];
char rORa;
int validData;
int Height = 0;
int Width = 0;
int PricePSqIn = 0;
do
{
cout << "\n\t Enter Window Height: ";
cin >> h;
cout << "\t Enter Window Width: ";
cin >> w;
cout << "\t Enter Price Per Sq in: ";
cin >> p;
cout << "\t Enter ""A"" for Arch, ""R"" for Rectangle: ";
cin >> rORa;
validData = aWin.setData(h,w,p, rORa);
if (validData == 0)
{
cout << "\n\n\tError in Data!";
cout << "\n\t\tMust enter either ""A"" for Arch or ""R"" for Rect";
cout <<"\n\t\tIf Arch Window, height must be >= half of the width for arch window\n";
}
} while (validData == 0);
system("CLS");
if (aWin.getRectOrArch() == 'A')
cout << "\n\t\t* * * Arch Window * * *\n";
else
cout <<"\n\t\t\t * * * Rectangle Window * * *\n";
cout << setiosflags (ios::showpoint | ios::fixed) << setprecision(2);
cout <<"\n\t Height: " << aWin.getHeight();
cout <<"\n\t Width: " << aWin.getWidth();
cout <<"\n\tPrice Per Sq. In.: " << aWin.getPricePSqIn();
cout <<"\n\t Total Area: " << aWin.getArea();
cout <<"\n\t Total Price: " << aWin.getPrice();
getch();
}
Arch_Rect_Win::Arch_Rect_Win()
{
pi = 3.14159;
}
double Arch_Rect_Win::getHeight() const
{
return Height;
}
double Arch_Rect_Win::getWidth() const
{
return Width;
}
double Arch_Rect_Win::getPricePSqIn() const
{
return p;
}
char Arch_Rect_Win::getRectOrArch() const
{
return ArchOrRect;
}
double Arch_Rect_Win::getArea()
{
if(ArchOrRect == 'A')
{
double radius = Width*.5;
double AreaofArch = (pow(radius, 2.0) * pi)/2;
double AreaofRectangle = (Height - radius) *Width;
TotalArea = AreaofRectangle + AreaofArch;
return TotalArea;
}
else
{
double AreaofRectangle = Height * Width;
TotalArea = AreaofRectangle;
return TotalArea;
}
}
double Arch_Rect_Win::getPrice() const
{
return p * TotalArea;
}
int Arch_Rect_Win::setData(char *h, char *w, char *p, char AorR)
{
char buffer[256];
*h = atoi (buffer);
*w = atoi (buffer);
*p = atoi (buffer);
return 0;
}
|