# Project #77464 - Computer Science question

Project

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 passes those values to the set methods to initialize its fields. It should have a default constructor that initializes both coordinates to 0.  It should also contain a method called distanceTo that takes as a parameter a constant reference to 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 p2(1.5, 4.0);double dist = p1.distanceTo(p2);`

Next, write a class called LineSegment that contains two Points that represent its two endpoints. It should have get and set methods for both fields and a constructor that takes two Point parameters and passes them to the set methods to initialize the data members.  It 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 (if the LineSegment is vertical, go ahead and return the value you get when dividing doubles by zero, which is infinity).  The LineSegement class might be used as follows:

`Point p1(4.3, 7.52);Point p2(-17.0, 1.5);LineSegment ls1(p1, p2);double length = ls1.length();double slope = ls1.slope();`

Do not include a main method in the files you submit - just the definition of your Point and LineSegment classes.  I will be including a main method for testing, and there can only be one main method in a program.  You will of course need to have a main method for testing purposes - just make sure you delete it or comment it out before submitting your files.

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
• length
• slope

The files must be named: Point.hppPoint.cppLineSegment.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".

Practice project for classes (no points)

Write a class called Box that has double members height, width and length.  The class should have a three-parameter constructor that takes three parameters and passes them to set methods to initialize the fields of the Box.  It should have a default constructor that initializes each field to 1.  It should have set methods for each field.  It should have a method that returns the volume of the Box and a method that returns the surface area of the Box.

The class declaration (interface) and the function definitions (implementation) must be in separate files - the interface or "header" file has a .hpp extension and the implementation has a .cpp extension.  All data members should be private.

Your functions should have the following names:

• setHeight
• setWidth
• setLength
• getVolume
• getSurfaceArea

Name your files: Box.hpp and Box.cpp

1. Make sure you've read and understood section 7.11.
2. Box.hpp should have "include guards" as discussed on page 447 (use "BOX_HPP").
3. Box.cpp needs to #include Box.hpp.  When you include your own .hpp files (header files), put double quotes around them instead of angled brackets.
4. When testing your program with your own main method, put it in a separate file (this is the "client" code) and give it a name with a .cpp extension.
5. Your main method also needs to #include Box.hpp.
6. If you named the file with your main method "boxMain.cpp", then you can compile your program with "g++ Box.cpp boxMain.cpp -o box".

 Subject Computer Due By (Pacific Time) 07/26/2015 11:00 am
TutorRating
pallavi

Chat Now!

out of 1971 reviews
amosmm

Chat Now!

out of 766 reviews
PhyzKyd

Chat Now!

out of 1164 reviews
rajdeep77

Chat Now!

out of 721 reviews
sctys

Chat Now!

out of 1600 reviews

Chat Now!

out of 770 reviews
topnotcher

Chat Now!

out of 766 reviews
XXXIAO

Chat Now!

out of 680 reviews