The MyPoint Class

less than 1 minute read

The code has been modified slightly and now uploaded to the site.

A UML diagram is not provided.

Question

<— Return Home

94.cpp

#include <iostream>
#include "MyPoint94.h"
using namespace std;

int main(){
    MyPoint94 point1;
    MyPoint94 point2(10, 30.5);
    // point2.getDistance(point1.getPointX(), point1.getPointY(), point2.getPointX(), point2.getPointY());
    std::cout << point1.getDistance(point2) << "\n";
}

<— Return Home

MyPoint94.h

#ifndef MyPoint94_H
#define MyPoint94_H

class MyPoint94{
    public:
        MyPoint94();
        MyPoint94(double pointX, double pointY);
        double getPointX();
        double getPointY();
        // double getDistance(double x1, double y1, double x2, double y2);
        double getDistance(MyPoint94 other);


    private:
        double x;
        double y;
};

#endif

<— Return Home

MyPoint94.cpp

#include "MyPoint94.h"
using namespace std;

MyPoint94::MyPoint94(){
    x = 0;
    y = 0;
}

MyPoint94::MyPoint94(double pointX, double pointY){
    x = pointX;
    y = pointY;
}

// double MyPoint94::getDistance(double x1, double y1, double x2, double y2){
//     return ((y2 - y1) / (x2 - x1));
// }

double MyPoint94::getDistance(MyPoint94 other){
    return ((other.getPointY() - getPointY()) / (other.getPointX() - getPointX()));
}
double MyPoint94::getPointX(){
    return x;
}

double MyPoint94::getPointY(){
    return y;
}

<— Return Home