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

Write a C++ program that accomplishes each of the following requirements: 1. Cre

ID: 3775165 • Letter: W

Question

Write a C++ program that accomplishes each of the following requirements:

1. Create a class Point that contains the private integer data members xCoordinate and yCoordinate and declares stream insertion and stream extraction overloaded operator function as friends of the class.

2. Define the stream insertion and stream extraction operator functions. The stream extraction operator function should determine whether the data entered is valid, and, if not, it should set the failbit to indicate improper input. The stream insertion operator should not be able to display the point after an input error occurred.

3. Write a main function that tests input and output of class Point, using the overloaded stream extraction and stream insertion operators.

Your design should include three files, each responsible for one of the requirements.

For 5 bonus points, submit a screen shot of a terminal window showing your program’s input and output for the points (10, 20) and (a, 20).

Explanation / Answer

Here is the program what you have asked or and please do let me know if any errors occurs

1) #include <iostream>

class Point

{

friend std::ostream& operator<<(std::ostream&, const Point&);

friend std::istream& operator>>(std::istream&, Point&);

public:

Point();

~Point();

private:

int xCoordinate;

int yCoordinate;

};

2) Point.cpp

#include "stdafx.h"

#include "Point.h"

#include <string>

using namespace std;

Point::Point()

: xCoordinate(0), yCoordinate(0) {}

ostream& operator<<(ostream& output, const Point& point)

{

if (cin.fail() != true)

{

output << "X Coordinate: " << point.xCoordinate << " Y Coordinate: " << point.yCoordinate;

}

else

{

output << "Bad input was given.";

}

return output;

}

istream& operator>>(istream& input, Point& point)

{

input >> point.xCoordinate >> point.yCoordinate;

if (point.xCoordinate < 0 || point.yCoordinate < 0)

{

input.clear(ios::failbit);

}

return input;

}

Point::~Point()

{

}

3) MAIN—Point Class.cpp

#include "stdafx.h"

#include "Point.h"

#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{

Point point;

cout << "Choose a point on quadrant I of the coordinate planeby inputting an x and a y value " << endl;

cin >> point;

cout << point << " " << endl;

return 0;

}

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