Please use the following UML diagram and maincpp to complete

?Please use the following UML diagram and main.cpp to complete the code below

Rectangle T width T height: T Rectangle Rectangle(x T y T width height T) getWidth() T getHeight T set Width (newWidth T) void setHeight(newHeight T) void area float circumference float public Square T Square (x T y T, side T)

Solution

PROGRAM CODE:

Rectangle.h

/*

* Rectangle.h

*

* Created on: 21-Nov-2016

* Author: kasturi

*/

#ifndef RECTANGLE_H_

#define RECTANGLE_H_

using namespace std;

template<class T>

class Rectangle

{

private:

   T width;

   T height;

public:

   Rectangle();

   Rectangle(T w, T h);

   T getHeight();

   void setHeight(T height) ;

   T getWidth();

   void setWidth(T width);

   float area();

   float circumference();

};

template <class T>

   Rectangle<T>::Rectangle()

   {

       width = 0;

       height = 0;

   }

   template <class T>

   Rectangle<T>::Rectangle(T w, T h)

   {

       width = w;

       height = h;

   }

   template <class T>

   T Rectangle<T>::getHeight() {

       return height;

   }

   template <class T>

   void Rectangle<T>::setHeight(T height) {

       this->height = height;

   }

   template <class T>

   T Rectangle<T>::getWidth() {

       return width;

   }

   template <class T>

   void Rectangle<T>::setWidth(T width) {

       this->width = width;

   }

   template <class T>

   float Rectangle<T>::area()

   {

       float area = width * height;

       return area;

   }

   template <class T>

   float Rectangle<T>::circumference()

   {

       float circumference = 2 * (width + height);

       return circumference;

   }

#endif /* RECTANGLE_H_ */

Square.h

/*

* Square.h

*

* Created on: 21-Nov-2016

* Author: kasturi

*/

#ifndef SQUARE_H_

#define SQUARE_H_

#include \"Rectangle.h\"

using namespace std;

template<class T>

class Square : public Rectangle<T> {

private:

   T side;

public:

   Square(T w, T h, T s);

};

template <class T>

Square<T>::Square(T w, T h, T s) : Rectangle<T>(w, h)

{

   side = s;

}

#endif /* SQUARE_H_ */

//main class

RecMain.cpp

/*

* RecMain.cpp

*

* Created on: 21-Nov-2016

* Author: kasturi

*/

#include <iostream>

#include \"Square.h\"

#include \"Rectangle.h\"

using namespace std;

int main()

{

cout<<\"-------------------------------------------\"<<endl;

   cout<<\"-------------------SQUARE------------------\"<<endl;

   cout<<\"-------------------------------------------\"<<endl;

   Square<int> *square = new Square<int>(3, 3, 3);

   cout<<\"Area of Square:\"<<square->area()<<endl;

   cout<<\"Circumference of square:\"<<square->circumference()<<endl;

   cout<<\"Sides of square:\"<<square->getWidth()<<\",\"<<square->getHeight()<<endl;

}

OUTPUT:

-------------------------------------------

-------------------SQUARE------------------

-------------------------------------------

Area of Square:9

Circumference of square:12

Sides of square:3,3

?Please use the following UML diagram and main.cpp to complete the code below Rectangle T width T height: T Rectangle Rectangle(x T y T width height T) getWidth
?Please use the following UML diagram and main.cpp to complete the code below Rectangle T width T height: T Rectangle Rectangle(x T y T width height T) getWidth
?Please use the following UML diagram and main.cpp to complete the code below Rectangle T width T height: T Rectangle Rectangle(x T y T width height T) getWidth
?Please use the following UML diagram and main.cpp to complete the code below Rectangle T width T height: T Rectangle Rectangle(x T y T width height T) getWidth

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site