O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Do the following with the class Shape- Add prototypes for methods Area.docx

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio

Confira estes a seguir

1 de 3 Anúncio

Do the following with the class Shape- Add prototypes for methods Area.docx

Baixar para ler offline

Do the following with the class Shape: Add prototypes for methods Area and Perimeter that will return values of template type T (these will be required methods in derived classes so write them appropriately).
// 1) *******************************************************************
template <class T>
class Point {
public:
void setX(T a) {
X = a;
}
void setY(T b) {
Y = b;
}
T getX() {
return X;
}
T getY() {
return Y;
}
private:
T X;
T Y;
};
// 2) *******************************************************************
template <class T>
class Shape
{
public:
private:
Point<T> Origin;
};
Solution
// 1) *******************************************************************
template <class T>
class Point {
public:
void setX(T a) {
X = a;
}
void setY(T b) {
Y = b;
}
T getX() {
return X;
}
T getY() {
return Y;
}
private:
T X;
T Y;
};



// 2) *******************************************************************
template <class T>
class Shape
{
public:
T Perimeter(T a,T b)
{
return a+b;
}
T Area(T a,T b);
{
return a*b;
}
private:
Point<T> Origin;
};
.

Do the following with the class Shape: Add prototypes for methods Area and Perimeter that will return values of template type T (these will be required methods in derived classes so write them appropriately).
// 1) *******************************************************************
template <class T>
class Point {
public:
void setX(T a) {
X = a;
}
void setY(T b) {
Y = b;
}
T getX() {
return X;
}
T getY() {
return Y;
}
private:
T X;
T Y;
};
// 2) *******************************************************************
template <class T>
class Shape
{
public:
private:
Point<T> Origin;
};
Solution
// 1) *******************************************************************
template <class T>
class Point {
public:
void setX(T a) {
X = a;
}
void setY(T b) {
Y = b;
}
T getX() {
return X;
}
T getY() {
return Y;
}
private:
T X;
T Y;
};



// 2) *******************************************************************
template <class T>
class Shape
{
public:
T Perimeter(T a,T b)
{
return a+b;
}
T Area(T a,T b);
{
return a*b;
}
private:
Point<T> Origin;
};
.

Anúncio
Anúncio

Mais Conteúdo rRelacionado

Semelhante a Do the following with the class Shape- Add prototypes for methods Area.docx (16)

Mais de wviola (20)

Anúncio

Mais recentes (20)

Do the following with the class Shape- Add prototypes for methods Area.docx

  1. 1. Do the following with the class Shape: Add prototypes for methods Area and Perimeter that will return values of template type T (these will be required methods in derived classes so write them appropriately). // 1) ******************************************************************* template <class T> class Point { public: void setX(T a) { X = a; } void setY(T b) { Y = b; } T getX() { return X; } T getY() { return Y; } private: T X; T Y; }; // 2) ******************************************************************* template <class T> class Shape { public: private: Point<T> Origin; };
  2. 2. Solution // 1) ******************************************************************* template <class T> class Point { public: void setX(T a) { X = a; } void setY(T b) { Y = b; } T getX() { return X; } T getY() { return Y; } private: T X; T Y; }; // 2) ******************************************************************* template <class T> class Shape { public: T Perimeter(T a,T b) { return a+b; } T Area(T a,T b);
  3. 3. { return a*b; } private: Point<T> Origin; };

×