Quiz #3

1. Write a complete C# program with two classes. The first, called Point, is used to describe a point in three-dimensional space. You should include a three parameter constructor and a ToString method. The other class is used to test the Point class. In particular, create two Point objects with coordinates: 5,6,7 and 10,3,2, respectively. Then print out the objects.

 

using System;

namespace Quiz3
{

   class Point
   {
      double x, y, z;

      public Point(double x, double y, double z)
      {
         this.x = x;
         this.y = y;
         this.z = z;
      }

      public override string ToString()
      {
         return string.Format("{0} {1} {2}", x, y, z);
      }
   }

   public class PointTest
   {

      public static void Main()
      {
         Point p1 = new Point(5, 6, 7);

         Point p2 = new Point(10, 3, 2);

         Console.WriteLine("Point1 has coordinates: {0}", p1);

         Console.WriteLine("Point2 has coordinates: {0}",p2);
      }
   }
}

2. There are two broad categories of types. Name them.

Value and reference.