Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class called Point that contains two doubles that represent its x- and y-coordinates. It should have get and set methods for both fields.

image text in transcribed
image text in transcribed
Write a class called Point that contains two doubles that represent its x- and y-coordinates. It should have get and set methods for both fields. It should have a constructor that takes two double parameters and initializes its coordinates with those values. It should have a default constructor that initializes both coordinates to zero. It should also contain a method called distanceTo that takes as a parameter another Point and returns the distance from the Point that was passed as a parameter to the Point that we called the method of. You will need to use sqrt(). For example at the end of the following, dist should be equal to 5.0: Point p1(-1.5, 0.0); Point pz01.5, 4.0); double dist p1.distanceTo(pz); Next, write a class called LineSegment that contains two Point-pointers, where each holds the address of a Point object that represents an endpoint of the LineSegment. It should have get and set methods for both fields and a constructor that takes the addresses of two Point objects and passes them to the set methods to initialize the data members. Your LineSegment constructor and set and get methods should only be working with Point-pointers- they shouldn't do anything with x- and y-coordinates. LineSegment should also contain a method called length that returns the length of the LineSegment by using the distanceTo method on its endpoints and a method called slope that returns the slope of the LineSegment. You don't need to do anything special for vertical ines - division by zero will result in the special value inf, which stands for "infinity". Your program will not be tested with line segments where both endpoints have the same coordinates. The LineSegement class might be used as follows: coordinates. The LineSegement class might be used as follows: Point p1(4.3, 7.52); Point p2C-17.0, 1.5); LineSegment 1s1(&pl, &p2); double length-1s1.lengthO; double slope = 1s1. slope(); The functions for the Point class should have the following names: . setXCoord, getXCoord setYCoord, getYCoord distanceTo The functions for the LineSegment class should have the following names: setEnd1, getEnd1 setEnd2, getEnd2 e length slope The files must be named: Point.hpp, Point.cpp, LineSegment.hpp and LineSegment.cpp Point.cpp and LineSegment.hpp should both #include Point.hpp. LineSegment.cpp should #include LineSegment.hpp. The main method you write for testing will also need to include LineSegment.hpp. If you named the file with your main method "geomMain.cpp", then you can compile your program with "g++ Point.cpp LineSegment.cpp geomMain.cpp-o geom

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

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

More Books

Students also viewed these Databases questions

Question

=+ (f) Show for 0 x 1 that D( A) =x for some A.

Answered: 1 week ago

Question

1. Identify three communication approaches to identity.

Answered: 1 week ago

Question

d. Who are important leaders and heroes of the group?

Answered: 1 week ago

Question

3. Describe phases of minority identity development.

Answered: 1 week ago