Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Media;
- namespace Struct_Experiments
- {
- class Program
- {
- /*
- 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.
- * */
- public struct Point3D
- {
- public int xVal, yVal, zVal;
- public int x { get { return xVal; } set { xVal = value; } }
- public int y { get { return yVal; } set { yVal = value; } }
- public int z { get { return zVal; } set { zVal = value; } }
- public Point3D(int x, int y, int z)
- {
- xVal = x;
- yVal = y;
- zVal = z;
- }
- }
- /*Create an Add(Point3D) method that returns a new Point3D which is the sum of the current Point3D and the passed-in Point3D;
- * */
- public int Add(Point3D point)
- {
- return new Point3D(point.x + xVal, point.y + yVal, point.z + zVal);
- }
- public override string ToString()
- {
- return string.Format("{0}.{1},{2}", xVal, yVal, zVal);
- }
- static void Main(string[] args)
- {
- Point3D point1 = new Point3D(1, 2, 3);
- Point3D point2 = new Point3D(6, 8, 10);
- Point3D point3 = point2.Add(point1);
- Console.WriteLine(point1.ToString());
- Console.WriteLine(point2.ToString());
- Console.WriteLine(point3.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement