|
-
December 5th, 2007, 09:53 AM
#1
Implementing Acessor/Mutator Functions
Hey, I just needed some help on a c++ project I was doing....we are supposed to implement accessor/mutator functions for all the data fields in the Rectangle class....
here is my code before we were told to implement these two kinds of functions....help is appreciated
#include<iostream>
using namespace std;
class Rectangle
{
public:
double height;
double width;
Rectangle()
{
width = 1;
height = 1;
}
Rectangle(double height2, double width2)
{
width = width2;
height = height2;
}
double getArea()
{
return width*height;
}
double getPerimeter()
{
return 2*width*2*height;
}
};
int main()
{
Rectangle Rectangle1(50,5);
Rectangle Rectangle2(35.9,3.5);
cout<<"Rectangle1:"<<endl;
cout<<"Width: "<<Rectangle1.width<<endl;
cout<<"Height: "<<Rectangle1.height<<endl;
cout<<"Area: "<<Rectangle1.getArea()<<endl;
cout<<"Perimeter: "<<Rectangle1.getPerimeter()<<endl;
cout<<endl;
cout<<"Rectangle2:"<<endl;
cout<<"Width: "<<Rectangle2.width<<endl;
cout<<"Height: "<<Rectangle2.height<<endl;
cout<<"Area: "<<Rectangle2.getArea()<<endl;
cout<<"Perimeter: "<<Rectangle2.getPerimeter()<<endl;
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|