SHARE
TWEET

Untitled

a guest May 19th, 2017 36 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Media;
  6.  
  7. namespace Struct_Experiments
  8. {
  9.    
  10.    
  11.     class Program
  12.     {  
  13.         /*
  14.         Create a new Point3D struct. Give it the properties X, Y, and Z, all with type “int”.              Create a constructor that takes in and sets values for X, Y, and Z.
  15.         * */
  16.  
  17.         public struct Point3D
  18.         {
  19.             public int xVal, yVal, zVal;
  20.  
  21.             public int x { get { return xVal; } set { xVal = value; } }
  22.             public int y { get { return yVal; } set { yVal = value; } }
  23.             public int z { get { return zVal; } set { zVal = value; } }
  24.  
  25.             public Point3D(int x, int y, int z)
  26.             {
  27.                 xVal = x;
  28.                 yVal = y;
  29.                 zVal = z;
  30.             }
  31.         }
  32.        
  33.  
  34.         /*Create an Add(Point3D) method that returns a new Point3D which is the sum of the current          Point3D and the passed-in Point3D;
  35.          * */
  36.  
  37.         public int Add(Point3D point)
  38.         {
  39.             return new Point3D(point.x + xVal, point.y + yVal, point.z + zVal);
  40.         }
  41.  
  42.        
  43.         public override string ToString()
  44.         {
  45.             return string.Format("{0}.{1},{2}", xVal, yVal, zVal);
  46.         }
  47.  
  48.         static void Main(string[] args)
  49.         {
  50.             Point3D point1 = new Point3D(1, 2, 3);
  51.             Point3D point2 = new Point3D(6, 8, 10);
  52.             Point3D point3 = point2.Add(point1);
  53.  
  54.             Console.WriteLine(point1.ToString());
  55.             Console.WriteLine(point2.ToString());
  56.             Console.WriteLine(point3.ToString());
  57.         }
  58.     }
  59. }
RAW Paste Data
Challenge yourself this year...
Learn something new in 2017
Top