Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please answer question in C++, In this lab you will expand your SpacePoint class

ID: 3716283 • Letter: P

Question

Please answer question in C++,

In this lab you will expand your SpacePoint class to include the listed member functions.

In an optional component you will create class TriangleClass needed to represent a triangle w/ points in space.

Then in main() run a sequence of tests without reading input or writing output. Then, only if all tests pass, write "ALL TESTS PASSED!" with endline.

PointClass:

TriangleClass:

Example,

#include <iostream>
#include <cmath>
using namespace std;

class SpacePoint {
public:
void SetCoords(int x, int y); // Sets the value for member variables xCoord and yCoord
int GetX(); // returns xCoord
int GetY(); // returns yCoord
SpacePoint operator+(SpacePoint b); // Overloads '+' operator and adds two points:
// (x1,y1)+(x2,y2) is (x1+x2, y1+y2)
private:
int xCoord;
int yCoord;
};

class TriangleClass {
public:
void SetPoints(SpacePoint A, SpacePoint B, SpacePoint C);
double GetArea();
void Print();
private:
SpacePoint A;
SpacePoint B;
SpacePoint C;
};


int main(){


}

Explanation / Answer

//Code Starts

#include <iostream>
#include <cmath>
using namespace std;

class SpacePoint {
public:
void SetCoords(int x, int y) { // Sets the value for member variables xCoord and yCoord
xCoord = x;
yCoord = y;
}
int GetX() { // returns xCoord
return xCoord;
}   
int GetY() { // returns yCoord
return yCoord;
}
SpacePoint operator+(SpacePoint b) { // Overloads '+' operator and adds two points:
// (x1,y1)+(x2,y2) is (x1+x2, y1+y2)
SpacePoint res;
res.xCoord = xCoord + b.xCoord;
res.yCoord = yCoord + b.yCoord;
return res;
}
  
private:
int xCoord;
int yCoord;
};

class TriangleClass {
public:
void SetPoints(SpacePoint A, SpacePoint B, SpacePoint C);
double GetArea();
void Print();
private:
SpacePoint A;
SpacePoint B;
SpacePoint C;
};


int main(){
SpacePoint S1;
S1.SetCoords(4, 3);
cout<<S1.GetX()<<endl;
cout<<S1.GetY()<<endl;
SpacePoint S2;
S2.SetCoords(1, 2);
SpacePoint S3 = S1 + S2;
cout<<S3.GetX()<<" "<<S3.GetY()<<endl;
return 0;
}

//Code Ends.

As, The type of input is not given, I've tried to complete the mandatory part. Please ask again if there is any doubt. Thank You!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote