i have this object program and it basically works but when it returns length, area, etc it gives me a negative totally incorrect answer help??!!
for more info look at thread called Rectangle class
// rectangle.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
class Rectangle{
public:Rectangle();
Rectangle(float urx, float ury, float ulx, float uly, float llx,float lly, float lrx, float lry);
void calclength(float urx, float ulx);
void calcwidth(float ury, float lry);
float area();
float perimeter();
void setlength(float lrx, float llx);
void setwidth(float uly, float lly);
void print();
float getlength();
float getwidth();
bool square(float urx, float ury, float lrx, float lry);
private:float upprx, uppry, upplx, upply, lowrx, lowry,length, width, lowlx, lowly;
};
Rectangle:: Rectangle(){
lowlx=1.0;
lowly=1.0;
upplx=1.0;
upply=2.0;
lowrx=2.0;
lowry=1.0;
upprx=2.0;
uppry=2.0;}
Rectangle:: Rectangle(float urx, float ury, float ulx, float uly, float llx,
float lly, float lrx, float lry){
lowlx=llx; lowly=lly; lowrx=lrx; lowry=lry; upplx=ulx; upply=uly; upprx=urx;
uppry=ury;}
void Rectangle:: calclength(float urx, float lrx){
length=urx-lrx;}
void Rectangle:: calcwidth(float ury, float lry){
width=ury-lry;}
float Rectangle:: area(){
return (length*width);}
float Rectangle:: perimeter(){
return (2*length+2*width);}
void Rectangle:: setlength(float lrx, float llx){
if( lrx<0.0||lrx>20.0)
lowrx=2;
else
lowrx=lrx;
if(llx<0.0||llx>20.0)
lowlx=1;
else
lowlx=llx;}
void Rectangle:: setwidth(float uly, float lly){
if(uly<0.0||uly>20.0)
upply=2;
else
upply=uly;
if(lly<0.0||lly>20.0)
lowly=1;
else
lowly=lly;}
float Rectangle:: getlength(){
return length;}
float Rectangle:: getwidth(){
return width;}
void Rectangle:: print(){
cout <<"Rectangle length = "<<length<< " and width = "<<width<<endl;}
bool Rectangle:: square(float urx, float uly, float lrx, float lry){
if(urx==lrx&&lry==uly){
cout <<"This is not a rectangle it is a square"<<endl;}
return 0;}
int main(int argc, char* argv[])
{
Rectangle coor;
Rectangle rect(2.0, 2.0, 2.0, 6.0, 9.0, 2.0, 9.0, 6.0);
Rectangle rect2(6.0,2.0, 6.0,6.0,10.0,2.0,10.0,6.0);
coor.setlength(0,0);
coor.setwidth(0,0);
coor.getlength();
coor.getwidth();
rect.setlength(9.0,2.0);
rect.setwidth(6.0,2.0);
rect.getlength();
rect.getwidth();
coor.print();
coor.square(0,0,0,0);
rect.print();
rect2.setlength(10.0,6.0);
rect2.setwidth(6.0,2.0);
rect2.getlength();
rect2.getwidth();
cout<<"The area is "<< rect.area()<<endl;
rect2.print();
cout<<"The perimeter is "<<rect2.perimeter()<<endl;
return 0;
}