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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Step 1: Overview of the given question

In the above question, the request is to create a C# class called Point that can store x and y coordinates and provides the following features:

  1. Default constructor that sets coordinates to (0, 0).
  2. Parameterized constructor for custom coordinates.
  3. Accessor methods to get and set the coordinates (using properties).
  4. A Display method to format and return the coordinates as a string.

The question also includes a usage example demonstrating how to create instances of the Point class, set values, and display them

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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education