#include<iostream>
using namespace std;
template<typename p>
class Rectangle
{
private:
p width ;
p length ;
p area ;
public:
void setData(p w, p l)
{
width = w;
length = l;
}
void calcArea()
{
area = width * length ;
}
p getWidth()
{
return width ;
}
p getLength()
{
return length ;
}
p getArea ()
{
return area ;
}
};
int main()
{
Rectangle<double> obj1;
obj1.setData(4.5,7.8);
obj1.calcArea();
cout<<"the width of the Rectangle:"<<obj1.getWidth()<<endl;
cout<<"the length of the Rectangle:"<<obj1.getLength()<<endl;
cout<<"the area of the Rectangle:"<<obj1.getArea()<<endl;
}
No comments:
Post a Comment