一道入门c#题,紧急求助

Youshouldcreateaprogramthatmanagesasetofpointsin3-dimensionalspace.Eachpointshouldbes... You should create a program that manages a set of points in 3-dimensional space. Each point should be set using. x, y and z values, and a unique label (a string). It should be possible to add new sections as needed. It shall not be possible to add points with the same label. It should be easy to print all the points. You must create a struct called Point and a class called My Locations. Point shall contain x, y, z (use double) and a label (string). My points shall contain a point table with size similar to that submitted to the constructor to My Locations. Members of the Point class should be private and could be changed using. properties. Objects of type My Locations will be indexed as it were a table. You should use an index. The following shall be possible from a test program: class Test Program { static void Main (string [] args) { Point p1 = new Point (0, 0, 0, "Sola"); Point p2 = new Point (5, -6, 7, "Earth"); // Prints single point: Console.WriteLine (p1); Console.WriteLine (); 题目太长发布下,剩下部分只好截图:
发现这格式没法看,直接整个截图吧。。。

谢谢大家!
展开
 我来答
wolf_410
2014-09-13
知道答主
回答量:6
采纳率:0%
帮助的人:5万
展开全部
  •  大概思路这样吧,细节上楼主要自己修改下。

  • class MyLocation
        {
            private Point[] points;
            private int _max;
            public MyLocation(int max)
            {
                points = new Point[max];
            }
            public Point this[int index]
            {
                get
                {
                    if (points != null && index >= 0 && index<_max)
                    {
                        return points[index];
                    }
                    return null;
                }
                set
                {
                    if (points != null && index >= 0 && index < _max)
                    {
                        foreach (Point p in points)
                        {
                            if(p!=null && p.Name==value.Name)
                            {
                                Console.WriteLine("this will give an error message");
                                return;
                            }
                        }
                        points[index] = value;
                    }
                }
            }
            public string ToString()
            {
                StringBuilder sb = new StringBuilder();
                if (points != null)
                {
                    foreach (Point p in points)
                    {
                        sb.AppendLine(p.ToString());
                    }
                }
                return sb.ToString();
            }
        }
        class Point
        {
            public double X
            { get; set; }
            public double Y
            { get; set; }
            public double Z
            { get; set; }
            public string Name
            {
                get;
                set;
            }
            public Point(double x, double y, double z, string name)
            {
                X = x;
                Y = y;
                Z = z;
                Name = name;
            }
            public string ToString()
            {
                return String.Format("{0}:[{1} {2} {3}]", Name, X, Y, Z);
            }
        }
追问
可以帮忙写出完整代码么,非常感谢。。。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式