Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a c++ program that - extends the Point class from HW #5.1(codes are on the bottom) - data members - x, y, and z

Write a c++ program that

- extends the Point class from HW #5.1(codes are on the bottom)

- data members

- x, y, and z coordinates

- member functions

- setter and getter for each data member

- overload the + operator to add two points (adds each coordinate)

- overload the ! operator to return true if point is NOT the origin (0,0,0)

- in main()

- instantiate three Point objects (default constructor)

- initialize data members for 2 objects using setter member functions

- no prompting, just hard code these values

- add these 2 Point objects and assign the result into the third object

- display coordinates for the resulting object

- instantiate another Point object (default constructor)

- use the ! operator on the object and inform the user if that Point was the origin or not

#include

#include

using namespace std;

class Point

{

private:

int xcoordinate;

int ycoordinate;

public:

//funtion prototypes

int getXcoord(void);

int getYcoord(void);

void setXcoord(int xcoord);

void setYcoord(int ycoord);

double distance(void);

Point(int xcoord, int ycoord);

//default constructor

Point()

{

xcoordinate = 0;

ycoordinate = 0;

}

};

// constructor that has two parameter

Point::Point(int xcoord, int ycoord)

{

xcoordinate = xcoord;

ycoordinate = ycoord;

}

// getter setter methods

void Point::setXcoord(int xcoord)

{

xcoordinate = xcoord;

}

int Point::getXcoord( void )

{

return xcoordinate;

}

void Point::setYcoord(int ycoord)

{

ycoordinate = ycoord;

}

int Point::getYcoord( void )

{

return ycoordinate;

}

double Point::distance( void )

{

return sqrt((xcoordinate*xcoordinate) + (ycoordinate*ycoordinate));

}

// Main function for the program

int main( )

{

Point obj;

obj.setXcoord(7);

obj.setYcoord(4);

cout<<"Distance from orgin: "<

return 0;

}

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

Step: 3

blur-text-image

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

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

2. Outline the functions of nonverbal communication

Answered: 1 week ago