using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace Q2_VisualisingGraphs_V1 { internal class Program { static void Main(string[] args) { //Declare variables int scaleX = 10; int scaleY = 5; List coords = new List(); string filePath = "W:/13/noah.phizacklea/Scholarship Exam/files/simple_graph_3.txt"; //Try catch loop try { //Ensure file exists if (File.Exists(filePath)) { //Read the lines from the file string[] lines = File.ReadAllLines(filePath); //Parse into coords foreach (string line in lines) { //Split the lines by spaces string[] parts = line.Split(' '); //Convert string parts to int and store in coords if (parts.Length == 2 && int.TryParse(parts[0].Trim(), out int x) && int.TryParse(parts[1].Trim(), out int y)) { coords.Add(new int[] { x, y }); } } } else { //File couldn't be found Console.WriteLine("File not found"); return; } } catch (Exception ex) { //Error message Console.WriteLine("An error occurred: " + ex.Message); return; } //Plot the graph for (int y = scaleY; y >= -scaleY; y--) { Console.Write(y.ToString().PadLeft(2) + "|"); if (y == 0) { //Write the x-axis Console.Write("+"); for (int x = 0; x < scaleX; x++) { Console.Write("-"); } Console.WriteLine("-"); } //Loop to check for points for (int x = 0; x <= scaleX; x++) { //If y = 0 don't plot as the x axis causes issues if (y == 0) { Console.Write(" "); continue; } //Check if the coord is in the list bool isPointPlotted = false; foreach (var coord in coords) { if (coord[0] == x && coord[1] == y) { isPointPlotted = true; break; } } //Check if the point is correct if so place an x if (isPointPlotted) { Console.Write("x"); } else { Console.Write(" "); } } Console.WriteLine(); } //Keep the program open Console.ReadLine(); } } } //Couldn't figure out how to override the x axis which had already been drawn with the new plotted point everything I tried just resulted //in the points appearing on a new line so I decided to just not plant points at y = 0