Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

In elementary mathematics of 2-dimensions, each point on the plane (or paper or screen, if you like) can be represented by a pair of numbers, (x, y), where x tells you the horizontal location of the point and y tells you the vertical location. The values are relative to some "origin" (0,0). So (3.1, 0) is the point 3.1 units to the right of the origin, and (-3.6, 5) is the point 3.6 units to the left of the origin and 5 units above it. This allows us to label every point in the plane with a unique (x,y) coordinate pair. The two numbers, x and y, are called the coordinates of the point.

Create a class called Point that has the following private members:

•float x - the x-coordinate of the point.
•float y - the y-coordinate of the point.
Point should also contain

•private static MIN_VAL and MAX_VAL - which are initialized to -10.0 and +10.0, respectively. These will represent the legal range of both the x and y coordinates for all Points in the class. It is important that these be static values since all objects will share the same range limits.
If you wish, you can let x and y (and the two statics) be doubles. If you do, adjust the data types of corresponding members below to be compatible with your choice.

Supply the following instance members:

•Two Constructors, 
?one that takes no arguments which constructs a default point of (A, A), where A = (MIN_VAL + MAX_VAL) / 2 (which would be (0,0) if MIN_VAL = -MAX_VAL),
?and another that takes two arguments, x and y which constructs a point (x, y).
•bool Set(float x, float y) - a mutator which sets the coordinates of the point to x and y.
•float GetX() and float GetY(), accessors for the x and y coordinates of the Point.
•DisplayPoint() - displays the Point in the form "(0.46, -0.102)"
Also create a public static method:

•bool SetRange(float new_min_val, float new_max_val) - a static method that changes the floats MIN_VAL and MAX_VAL to the values passed (if successful). This method must check that new_min_val < new_max_val and return true or false, accordingly. Note that any changes made to MIN_VAL and MAX_VAL through this method will not enforce the range of any previously constructed Points, but will only affect future constructor and mutator calls.
Create another class called Polygon that has the following members:

•num_points - a private instance member, an int, that describes the number of Points in the current Polygon.
•points[] - an array of Points representing the list of points that define this Polygon. This is a private instance member.
•MAX_POINTS - a constant static that gives the maximum number of Points allowed in the array (can be used to declare the array if you wish). Note that num_points could be much smaller than MAX_POINTS. For ex, you might choose MAX_POINTS to be 100, but three different objects might have num_points set to 3, 13 and 7.
You should supply all of the following (at a minimum):

•A Constructor that takes no parameters and sets the number of points to 0.
•A Constructorthat takes three parameters. 
?The first parameter is an int: num_points, which indicates how many points the newly constructed Polygon will contain.
?The second is an array of floats: x_array[], which contains all the x-coordinates of the Points in the newly constructed Polygon.
?The third is an array of floats: y_array[], which contains all the y-coordinates of the Points in the newly constructed Polygon.
For ex, the x-y coordinates of the first (really 0th) Point in the Polygon would come from x_array[0] and y_array[0], the x-y coordinates of the second (really 1st) Point in the Polygon would come from x_array[1] and y_array[1], the x-y coordinates of the third (really 2nd) Point in the Polygon would come from x_array[2] and y_array[2], and so on. (The two arrays are called parallel arrays because they work together (in parallel) to specify the Points: if you want to get the coordinates of the kth Point in the Polygon, you would use the x_array[k - 1] for the x-coordinate and y_array[k - 1] for the y-coordinate.)

The actual arrays passed might be larger than the int num_points passed, and that's okay! We only use the first num_points elements of the two arrays. For ex, the arrays might each be 100 elements, but if num_points is 3, we are only using the first three elements of each array.

Only supply these two constructors and no other, although you may combine the two using default parameters. 


•bool SetPoints(int num_points, float x_values[], float y_values[]) - a mutator that takes an int, num_points, and two float arrays. The two float arrays provide the x-y coordinates of the Points in the requested Polygon in the same manner described in detail for the constructor, above. This method overprepares any values in the existing object, and creates a fresh Polygon from scratch - it does not append points to the existing Polygon. Return false (error) if the internal points[] array is smaller than num_points or if num_points is < 0. There is another possible reason for failure (false return) that you must consider - this is part of your assignment. Do not ask what it is, but figure it out based on the information above.
•void ShowPolygon() - displays the points in the Polygon as a text string such as "(3.5, 1.2), (-9.1, 5.5), (0.120, -0.30)", ...."
•bool AddPoint( float x, float y) - adds (appends) a new Point to the list, but only if there is room!
•bool AddPoint (Point p) - adds (appends) a new Point to the list, but only if there is room!
As always, make sure that mutators, constructors and any methods that affect private data filter out bad parameters from the client.

This ex gives lots of opportunity to use/invoke some methods to make other methods' lives easier. Make sure you are not duplicating code, but exploiting this opportunity.

We don't care if a Polygon's points cause it to be drawn with sides crossing (if we were to draw it, which most of you will not). Any list of (x,y) pairs will be considered a valid Polygon, assuming that they are valid Points.

Generate a sample main() that tests your classes. 

•Establish one set of min/max values for the statics in the Point class using the static mutator.
•Set and display a few Point objects manually. Check that your range limitation works by attempting to set values of one Point outside the range and proving that your Point rejects this attempt.
•Next, instantiate three Polygons manually from literal values in your program, i.e., do not involve the user with run-time input. 
•Two Polygons should be constructed with float arrays arguments for the x and y values, instantly populating the Polygon. The third should be instantiated using the default constructor, then filled with points using the mutator methods. Use different coordinate values for the Points for all three Polygons (i.e., don't create two identical Polygons).
•Display the Polygons.
•Make changes to the Polygons using the mutators of that class and display them again.
•In at least one Polygon mutator call, attempt to set values illegally (in any sense of the word based on the above criteria) and prove that your class protects against this attempt. 

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M9105955

Have any Question?


Related Questions in Computer Engineering

What is the difference between accounting costs and

What is the difference between accounting costs and economic costs? Why do economic costs include both explicit (revealed and expressed) costs and implicit (present but not obvious) costs? What are the differences betwee ...

On crait 40 of the surviving resistance fightersnbspare

On Crait, 40% of the surviving resistance fighters are pilots. Preparing for KyloRen's assault on their position, a random sample of 25 resistance fighters is taken. Using this information, answer the following questions ...

Question 1 designing team and team identityusing the

Question: 1. Designing Team and Team Identity. Using the Internet, team should read at least 5 academically reviewed articles on designing. 2. Please do not change the wording of the original summary. Include the team me ...

A supermarket awards coupons depending on how much a

A supermarket awards coupons depending on how much a customer spends on groceries. For example, if you spend $50, you will get a coupon worth eight percent of that amount. The following table shows the percent used to ca ...

A decision maker has ordered every commodity in walmart

A decision maker has ordered every commodity in Walmart alphabetically according to the commodity's name. Every time when he needs to choose from several commodities, he always choose the second one according to his orde ...

What is the binary representation of the decimal number

What is the binary representation of the decimal number 4.875 assuming the IEE 754 single precision format?

Request this to be done in jgrasp1 add a method to the

Request this to be done in JGrasp 1. Add a method to the program that calculates the cube of every number between a lower bound and an upper bound that a user inputs (for instance, lower bound 1 and upper bound 9, for be ...

Fiona told her friend that she is very fortunate as the

Fiona told her friend that she is very fortunate as the slow-down in the economy has not decreased sales in her grocery store by much compared to sales of new cars in his car dealership. Explain what Fiona meant using th ...

Question share your favorite open web resource and what

Question : Share your favorite open web resource and what cool tools does it have? What can you learn from it? How will it help as a career resource? What is your favorite learning express or JCA course, tool, or Page. W ...

Discuss the role of insurance in healthcare delivery and

Discuss the role of insurance in healthcare delivery and productivity

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As