The problem in my code lies somewhere in the
Class2DPoint object1 = new Class2DPoint(num[0], num[1]);

Class2DPoint object2 = new Class2DPoint(num[3], num[4]); part of the code and there is a problem in the object1 = object1 * object2; and

public Class2DPoint()
{
this.x = 0;
this.y = 0;
}

I only have 3 errors, can anyone help me out??

using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Text;
namespace mathprogramweek5
{
    class Coordinatetest
    {
        static void Main(string[] args) // Args means the user can input any text
        {
            int[] num;
            num = new int[6];

            Console.WriteLine("******* welcome to the corrdinate test program *****");
            Console.WriteLine(" This program calculates ");
            Console.WriteLine(" Distance between 2 points using 2D and 3D");
            Console.WriteLine(" ");
            Console.Write(" Enter the value of X for the first (3-Dimensionl figure) : ");
            int x1 = Convert.ToInt32(Console.ReadLine());
            num[0] = x1;
            Console.WriteLine(" ");

            Console.Write(" Enter the value of Y for the first (3-Dimensionl figure) : ");
            int y1 = Convert.ToInt32(Console.ReadLine());
            num[1] = y1;
            Console.WriteLine(" ");

            Console.Write(" Enter the value of Z for the first (3-Dimensionl figure) : ");
            int z1 = Convert.ToInt32(Console.ReadLine());
            num[2] = z1;
            Console.WriteLine(" ");

            Console.Write(" Enter the value of X for the second (3-Dimensionl figure) : ");
            int x2 = Convert.ToInt32(Console.ReadLine());
            num[3] = x2;
            Console.WriteLine(" ");

            Console.Write(" Enter the value of Y for the second (3-Dimensionl figure) : ");
            int y2 = Convert.ToInt32(Console.ReadLine());
            num[4] = y2;
            Console.WriteLine(" ");

            Console.Write(" Enter the value of Z for the second (3-Dimensionl figure) : ");
            int z2 = Convert.ToInt32(Console.ReadLine());
            num[5] = z2;

            Class2DPoint object1 = new Class2DPoint(num[0], num[1]);
            Class2DPoint object2 = new Class2DPoint(num[3], num[4]);
            Class3DPoint object3 = new Class3DPoint(num[0], num[1], num[2]);
            Class3DPoint object4 = new Class3DPoint(num[3], num[4], num[5]);
            Console.WriteLine(" Point of object in graph\n\n");
            object2.drawGraph(object3, object4);
            object1 = object1 - object4;
            Console.Write("\n\n Distance between points A and B in Object 1: ");
            double distance = Math.Sqrt(Math.Pow((x2 - x1), 2.0) + Math.Pow((y2 - y1), 2.0) + Math.Pow((z2 - z1), 2.0));
            Console.WriteLine(distance);
            object1.showDistance(object2);
            object2 = object3 * object4;
            Console.Write("\n3Dpoints, Distance between 2 3-Dimensional Figures : ");
            object3.showDistance(object4);
            object1 = object1 * object2;
            Console.Write(" \n Click Enter to close the program");
            Console.ReadLine();
        }
        public class Class2DPoint
        {
            protected int x;
            protected int y;

            public Class2DPoint()
            {
                this.x = 0;
                this.y = 0;
            }
            public double showDistance(Class2DPoint secondPoint)
            {
                int x1 = this.x;
                int y1 = this.y;
                int x2 = secondPoint.x;
                int y2 = secondPoint.y;
                double DISTANCE = Math.Sqrt(Math.Pow((x2 - x1), 2.0) + Math.Pow((y2 - y1), 2.0));
                Console.WriteLine(DISTANCE);
                return DISTANCE;
            }
            public static Class2DPoint operator -(Class2DPoint object1, Class2DPoint object2)
            {
                Class2DPoint OO = new Class2DPoint();
                OO.x = (object1.x - object2.x) * 2;
                OO.y = (object1.y - object2.y) * 2;
                return OO;
            }
            public void drawGraph(Class2DPoint obj, Class2DPoint obj1)
            {
                char[,] Andrew;
                Andrew = new char[10, 10];
                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        Andrew[i, j] = '.';
                    }
                }
                Andrew[obj.x, obj.y] = 'A';
                Andrew[obj1.x, obj1.y] = 'B';
                for (int k = 9; k >= 0; k--)
                {
                    Console.Write(k + 1);
                    Console.Write("\t");
                    for (int l = 0; l < 10; l++)
                    {
                        Console.Write(Andrew[k, l]);
                        Console.Write("   ");
                    }
                    Console.WriteLine();
                }
                Console.Write("\t");
                for (int k = 0; k < 10; k++)
                {
                    Console.Write(k + 1);
                    Console.Write("     ");
                }
                Console.WriteLine();
            }
        }
        public class Class3DPoint : Class2DPoint
        {
            private int z;
            public Class3DPoint()
                : base()
            {
                z = 0;
            }
            public Class3DPoint(int x, int y, int z)
                : base()
            {
                this.x = x;
                this.y = y;
                this.z = z;
            }
            public static Class3DPoint operator *(Class3DPoint object1, Class3DPoint object2)
            {
                Class3DPoint TT = new Class3DPoint();
                TT.x = (object1.x - object2.x) * 2;
                TT.y = (object1.y - object2.y) * 2;
                TT.z = (object1.z - object2.z) * 2;
                return TT;
            }
            public void drawgraph(Class3DPoint obj, Class3DPoint obj1)
            {
                char[,] Andrew;
                Andrew = new char[10, 10];
                for (int i = 0; i < 10; i++)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        Andrew[i, j] = '.';
                    }
                }
                Andrew[obj.x, obj.y] = 'A';
                Andrew[obj1.x, obj1.y] = 'B';
                for (int k = 9; k >= 0; k--)
                {
                    Console.Write(k + 1);
                    Console.Write("\t");
                    for (int l = 0; l < 10; l++)
                    {
                        Console.Write(Andrew[k, l]);
                        Console.Write("    ");
                    }
                    Console.WriteLine();
                }
                Console.Write("\t");
                for (int k = 0; k < 10; k++)
                {
                    Console.Write(k + 1);
                    Console.Write("    ");
                }
                Console.WriteLine();
            }
            public double showDistance(Class3DPoint secondPoint)
            {
                int x1 = this.x;
                int y1 = this.y;
                int z1 = this.z;
                int x2 = secondPoint.x;
                int y2 = secondPoint.y;
                int z2 = secondPoint.z;
                double distance = System.Math.Sqrt(x + y + z);
                Console.WriteLine(distance);
                return distance;
            }
        }
    }
}
Member Avatar for stbuchok

How are you multiplying 2 objects? You don't seem to be overloading an operator.

public class Class2DPoint
{
   ...

   //add this constructor
   public Class2DPoint(int x, int y)
   {
      this.x = x;
      this.y = y;
   }

   //add this user defined operator
   public static Class2DPoint operator *(left Class2DPoint, right Class2dPoint)
   {
      return new Class2DPoint(left.x * right.x, left.y * right.y);
   }

}

Hopefully I understood the issue and this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.