- a constructor that takes two values corresponding to the xcoord and ycoord values and sets them accordingly

Microsoft Visual C#
7th Edition
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Joyce, Farrell.
Chapter9: Using Classes And Objects
Section: Chapter Questions
Problem 1CP: In previous chapters, you have created programs for the Greenville Idol competition. Now create a...
icon
Related questions
Question

In C#, How would you compile the necessary code to define a class that will store a point in space. It will need the following data members: xcoord, ycoord. Include the following methods:
- a default constructor that will set the coordinates to 0,0
- a constructor that takes two values corresponding to the xcoord and ycoord values and sets them accordingly
- accessor methods to get and set the values of the coordinates (you can use properties if you wish)
- a display constructor that returns a string in the format of (xcoord, ycoord)

Usage of the class:
    //create an instance of 2 points
    Point myPoint = new Point;
    //assign values using properties           |If you do not declare properties for the data items, you might do the following
    myPoint.Xcoord = 42;                       |myPoint.SetX(42);             
    myPoint.Ycoord = 19.63;                    |myPoint.SetY(19.63)    
    // use the Display() method
    WriteLine(“The point is “+myPoint.Display());   //output The point is (42, 19.63)

Expert Solution
steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Knowledge Booster
Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage