Exercise
ArrayList of Points
Objetive
Create a structure named "Point3D" to represent a point in 3D space with coordinates X, Y, and Z.
Create a program that has a menu where the user can:
Add data for one point
Display all the entered points
Exit the program
The program should use ArrayLists instead of arrays.
Example Code
using System;
using System.Collections;
namespace Point3D
{
class Program
{
struct Point3D
{
double x, y, z;
}
static void Main(string[] args)
{
bool exit = false;
ArrayList list = new ArrayList();
Point3D points = new Point3D();
string answer;
do
{
Console.WriteLine("1. Add data for one point");
Console.WriteLine("2. Display all the entered points");
Console.WriteLine("x. Display all the entered points");
Console.WriteLine();
Console.Write("Enter a option: ");
answer = Console.ReadLine();
if (answer.ToLower() == "x")
{
exit = true;
}
else if (answer == "1")
{
Console.Write("Point x: ");
list.Add(Convert.ToInt32(Console.ReadLine()));
Console.Write("Point y: ");
list.Add(Convert.ToInt32(Console.ReadLine()));
Console.Write("Point z: ");
list.Add(Convert.ToInt32(Console.ReadLine()));
}
}
while (!exit);
}
}
}