Inheriting Struct

  • Thread starter Thread starter Jeff0803
  • Start date Start date
J

Jeff0803

Guest
Recently I had an interview but failed the coding test.

The consumer code was given and the struct and interface was assignment.

Here is the description of the assignment and consumer code.

Create a console application that can calculate the Euclidean distance between two points.
The points can be passed in as either 2 dimensional points or 3 dimensional points.
You should have an interface that exposes the necessary methods to clients.
Use object oriented principles appropriately to solve this problem,
the key here is how you design your application, not if you can calculate the Euclidean distance correctly.

And the consumer code is like the following

static void Main(string[] args)
{
// The definition for the types Point, Point2d and Point3d should be part of your design
Point point2d_1 = new Point2d(0, 0);
Point point2d_2 = new Point2d(3, 4);
Console.WriteLine("point2d_1 is " + point2d_1.Dist(point2d_2) + " distance away from point2d_2");
Point point3d_1 = new Point3d(0, 0, 0);
Point point3d_2 = new Point3d(3, 4, 5);
Console.WriteLine("point2d_1 is " + point3d_1.Dist(point3d_2) + " distance away from point2d_2");
}

Struct can be inherited from an Interface but can't from other Struct.

How to make Struct to do this?

I want to know how to do this for the concrete knowledge.

Continue reading...
 
Back
Top