Question: Programming Exercise 15, Chapter 11, describes how to design the class pointType to implement a point. Redo this programming exercise so that the class pointType

Programming Exercise 15, Chapter 11, describes how to design the class pointType to implement a point. Redo this programming exercise so that the class pointType

Programming Exercise 15, Chapter 11, describes how to design the class pointType to implement a point. Redo this programming exercise so that the class pointType:

Overloads the stream insertion operator, <<, for easy output.

Overloads the stream extraction operator, >>, for easy input. (A point is input as (a, b).)

Overloads the assignment operator to copy a point into another point.

Overloads the binary operator +, as a member function, so that it returns the distance between two points.

Overloads the operator ==, as a member function, so that it returns true if two points are the same; falseotherwise.

Overloads the operator !=, as a member function, so that it returns true if two points are not the same; falseotherwise.

Write a program to test your class.

***************************

pointType.cpp

***************************

//Implementation File for the class integerManipulation #include #include #include "pointType.h"

using namespace std;

void pointType::setPoint(double a, double b) { x = a; y = b; }

void pointType::setX(double a) { x = a; }

double pointType::getX() { return x; }

void pointType::setY(double b) { y = b; }

double pointType::getY() { return y; }

double pointType::distance(pointType & point) { return sqrt(pow(x - point.x, 2) + pow(y - point.y, 2)); }

void pointType::print() const { cout << "(" << x << ", " << y << ")" << endl; }

pointType::pointType(double a, double b) { setPoint(a, b); }

******************* pointType.h

*******************

#ifndef pointType_H #define pointType_H

class pointType { public: void setPoint(double a = 0, double b = 0); //Function to set the x and y coordinates of a point //Postcondition x = a; y = b;

void setX(double a = 0); //Function to set x coordinate. //Postcondition: x = a;

double getX(); //Function to return the x coordinate.

void setY(double b = 0); //Function to set y coordinate. //Postcondition: y = b;

double getY(); //Function to return the y coordinate.

double distance(pointType & point); //Function to return the distance between this point //point

void print() const; //Function to print the x and y coordinates.

pointType(double a = 0.0, double b = 0.0); //Constructor with a default parameter.

private: double x; double y; };

#endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!