Okay guys. I appreciate both of your answers. Can you look at this again. I tried doing it your way, Lerner, doing the same thing for perimeter as you suggested for area. Now it compiles, asks for length and width twice each and the correct calculations as long as I enter the same values both times for length and width. can you tell me why? Ugh, I think my brain is fried.
#include
using namespace std;
class Rectangle // Class Rectangle
{
public:
Rectangle[float L=1, float W=1]; // Constructor
float getLength[] const;
void setLength[float L];
float getWidth[]const;
void setWidth[float W];
/*float perimeter[float ,float]; */// Perimeter function
//float area [float, float]; // Area funcion
void Rectangle::calculatePerimeter[] {perimeter = [[2*length] + [2*width]];}
float Rectangle::getPerimeter[]const {return perimeter;}
void Rectangle::calculateArea[]{area = width * length;}
float Rectangle::getArea[]const {return area;}
private:
float length, width, area, perimeter;
}; // End of class Rectangle
Rectangle::Rectangle[float L, float W] // Scope function
{
setLength[L];
setWidth[W];
calculateArea[];
calculatePerimeter[];
}
void Rectangle::setWidth[float W]
{
do
{
cout > W;
}
while [[W < 0.0] || [W > 20.0]];
width = W;
}
float Rectangle::getWidth[]const
{
return width;
}
void Rectangle::setLength[float L]
{
do
{
cout > L;
}
while [[L < 0.0] || [L > 20.0]];
length = L;
}
float Rectangle::getLength[]const
{
return length;
}
//float Rectangle::perimeter[float L, float W]
//{
//return[[2*L] + [2*W]];
//}
//float Rectangle::area[float L, float W]
//{
//return[L*W];
//}
int main[]
{
Rectangle MyRectangle;
float length = 0.0;
float width = 0.0;
MyRectangle.setWidth[width];
MyRectangle.getWidth[];
MyRectangle.setLength[length];
MyRectangle.getLength[];
MyRectangle.calculateArea[];
MyRectangle.calculatePerimeter[];
cout 20.0]]
{
width = 1.0;
}
else
{
width = W;
}
return;
}
float getWidth[]
{
return W;//Is this right?
}
void Rectangle::setLength[float L]//same here-do/while loop?
{
if [[L < 0.0] || [L > 20.0]]
{
length = 1.0;
}
else
{
length = L;
}
return;
}
float getLength[]
{
return L;
}
void Rectangle::get[float L, float W]
{
}
double Rectangle:perimeter[float L, float W]
{
perimeter = [2*L] + [2*W];
cout 20.0]]
{
width = 1.0;
}
else
{
width = W;
}
return;
}
float Rectangle::getWidth[]const
{
return width;
}
void Rectangle::setLength[float L]//same here-do/while loop?
{
if [[L < 0.0] || [L > 20.0]]
{
length = 1.0;
}
else
{
length = L;
}
return;
}
float Rectangle::getLength[]const
{
return length;
}
float Rectangle::perimeter[float L, float W]
{
return[[2*L] + [2*W]];
//cout