Hi there. I am trying to create a class rectangle. It should have data members length and width of type float (which should default to 1). The class should have member functions that calc. area() and perimeter() and also separate get() and set() functions for length and width. These should require the user to enter valid length and width between 0 and 20.0 (use a do while loop). Then I have to add a draw function, but I'm not even there yet. Can someone look at my code and give me a general idea of where I am going? It all looks like a big mess to me and I just keep making it worse now! Thanks for taking the time to help me.
#include <iostream>
using namespace std;
class Rectangle // Class Rectangle
{
public:
Rectangle(float=1, float=1); // Constructor
float getLength(){return length;}
void setLength(float L);
float getWidth(){return width;}
void setWidth(float W);
double perimeter(void){return (length*2 + width*2);} // Perimeter function
double area(void) {return length*width);} // Area funcion
private:
float length;
float width;
}; // End of class Rectangle
Rectangle::Rectangle(float L, float W) // Scope function
{
length=L;
width=W;
}
double Rectangle:perimeter(float L, float W)
{
}
double Rectangle::area(float L, float W)
{
}
void Rectangle::setWidth(float W)
{
if ((W < 0.0) || (W > 20.0))
{
width = 1.0;
}
else
{
width = W;
}
return;
}
void Rectangle::setLength(float L)
{
do
cout << "Please enter a valid length: " <<endl;
cin >> L;
while ((L < 0.0) || (L > 20.0))
else
{
Length = L;
}
return;
}
void Rectangle::get(float L, float W)
{
}
int main() // main()
{
return 0;
} // End of main()