答案 0 :(得分:6)
答案 1 :(得分:3)
答案 2 :(得分:1)
答案 3 :(得分:1)
//This Is The Complete Program A Run This 10 Time on VC++ For More check
//For More Code and Information and News www.exploretomorrow.blogspot.com
#include <iostream>
using namespace std;
class Rectangle // Class Rectangle
{
public:
Rectangle(float L, float W); // 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 L, W, length, width;
}; // End of class Rectangle
Rectangle::Rectangle(float L, float W) // Scope function
{
length=L;
width=W;
}
void Rectangle::setWidth(float W)//I'd like to change this to a do/ while loop??
{
if ((W < 0.0) || (W > 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 << "The perimeter of the rectangle is: " << perimeter << endl;
}
double Rectangle::area(float L, float W)
{
area = L*W;
cout << "The area of the rectangle is : " << area << endl;
}
int main() // main() I'm sure something is wrong here.
// I understand the main function, but when I use classes I get confused...
{
rectangle MyRectangle;
cout << "Please enter the length of the rectangle: " << endl;
cin >> MyRectangle.getlength >> endl;
cout << "Please enter the width of the rectangle: " << endl;
cin >> MyRectangle.getwidth >> endl;
return 0;
} // End of main()