Here are some changes I've made. Can anyone offer feedback for me? I'll also post the errors I get.
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
|
#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()
|
Errors: ya-there are a lot!
1>------ Build started: Project: more_practice, Configuration: Debug Win32 ------
1>Compiling...
1>more.cpp
1>c:\users\laura\desktop\more_practice\more_practice\more.cpp(40) : error C2065: 'W' : undeclared identifier
1>c:\users\laura\desktop\more_practice\more_practice\more.cpp(57) : error C2065: 'L' : undeclared identifier
1>c:\users\laura\desktop\more_practice\more_practice\more.cpp(60) : error C2039: 'get' : is not a member of 'Rectangle'
1> c:\users\laura\desktop\more_practice\more_practice\more.cpp(4) : see declaration of 'Rectangle'
1>c:\users\laura\desktop\more_practice\more_practice\more.cpp(66) : error C2470: 'Rectangle' : looks like a function definition, but there is no parameter list; skipping apparent body
1>c:\users\laura\desktop\more_practice\more_practice\more.cpp(73) : error C2511: 'double Rectangle::area(float,float)' : overloaded member function not found in 'Rectangle'
1> c:\users\laura\desktop\more_practice\more_practice\more.cpp(4) : see declaration of 'Rectangle'
1>c:\users\laura\desktop\more_practice\more_practice\more.cpp(81) : error C2065: 'rectangle' : undeclared identifier
1>c:\users\laura\desktop\more_practice\more_practice\more.cpp(81) : error C2146: syntax error : missing ';' before identifier 'MyRectangle'
1>c:\users\laura\desktop\more_practice\more_practice\more.cpp(81) : error C2065: 'MyRectangle' : undeclared identifier
1>c:\users\laura\desktop\more_practice\more_practice\more.cpp(83) : error C2065: 'MyRectangle' : undeclared identifier
1>c:\users\laura\desktop\more_practice\more_practice\more.cpp(83) : error C2228: left of '.getlength' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\laura\desktop\more_practice\more_practice\more.cpp(85) : error C2065: 'MyRectangle' : undeclared identifier
1>c:\users\laura\desktop\more_practice\more_practice\more.cpp(85) : error C2228: left of '.getwidth' must have class/struct/union
1> type is ''unknown-type''
1>Build log was saved at "file://c:\Users\Laura\Desktop\more_practice\more_practice\Debug\BuildLog.htm"
1>more_practice - 12 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========