Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions