Seu SlideShare está sendo baixado. ×

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

1 de 3 Anúncio

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

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

Anúncio

### 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; };