Q8: Write a generic class Pair which has two type parameters Solution #include \
ID: 640263 • Letter: Q
Question
Q8: Write a generic class Pair which has two type parameters
Explanation / Answer
#include "Point.h" // user-defined header in the same directory #include #include using namespace std; // Constructor (default values can only be specified in the declaration) Point::Point(int x, int y) : x(x), y(y) { } // Use member initializer list // Public getter for private data member x int Point::getX() const { return x; } // Public setter for private data member x void Point::setX(int x) { this->x = x; } // Public getter for private data member y int Point::getY() const { return y; } // Public setter for private data member y void Point::setY(int y) { this->y = y; } // Public member function to set both x and y void Point::setXY(int x, int y) { this->x = x; this->y = y; } // Public member function to return the magitude double Point::getMagnitude() const { return sqrt(x*x + y*y); // sqrt in } // Public member function to return the argument double Point::getArgument() const { return atan2(y, x); // atan2 in } // Public member function to print description about this point void Point::print() const { coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.