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.Threading.Tasks;
- using System.Drawing;
- using GDIDrawer;
- using Utilities;
- namespace ICA_14
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Add Canvas to the method parameters i.e (Canvas, x, x ) I would just have to replacae everything in the code to draw the red line and only keep the one to draw a red line
- //Which means I can convert the method to void instead of CDrawer
- int[] iArray1;
- iArray1 = new int[20];
- int storage = 0;
- int search = 0;
- int foundAt = 0;
- Random rnd = new Random();
- Console.WriteLine("\t\t\tWilliam Fung ICA 14");
- for (int i = 0; i < 20; i++)
- {
- storage = rnd.Next(1, 29);
- iArray1[i] = storage;
- }
- int[] iArray2 = (int[])iArray1.Clone();
- iArray2[1] = 0;
- Draw(iArray1, "iArray1, Original Contents");
- Draw(iArray2, "iArray2");
- iArray2 = new int[40];
- iArray1.CopyTo(iArray2, 10);
- Draw(iArray2, "iArray2, copied at 10");
- Array.Clear(iArray2, 10, 10);
- Draw(iArray2, "iArray2, cleared");
- Array.Sort(iArray1);
- Draw(iArray1, "iArray1, sorted");
- Console.WriteLine("Array list:");
- for (int i = 0; i < 20; i++)
- {
- Console.WriteLine(iArray1[i]);
- }
- CUtilities.GetValue(out search, "Enter an integer to search for in iArray1 between 1 and 29: ", 1, 29);
- foundAt = Array.BinarySearch(iArray1, search);
- Console.WriteLine(foundAt);
- if (foundAt < 0)
- {
- Draw(iArray1, "iArray1, search not found in Array");
- //same edit to be made as last one, draw it, return it, then add the text over it
- }
- if (foundAt >= 0)
- {
- CDrawer Canvas = new CDrawer(800, 600);
- Canvas.Scale = 20;
- for (int i = 0; i < iArray1.Length; i++)
- {
- Canvas.AddLine(i, 0, i, iArray1[i], Color.Yellow, 4);
- Canvas.AddText("iArray1, binary search", 24);
- Canvas.AddLine(foundAt, 0, foundAt, iArray1[foundAt], Color.Red, 4);
- //edits to make: pass the canvas over to the method, then return the canvas with the drawing back then overwrite the canvas at the foundat location with a redline
- }
- Console.WriteLine("Press enter to open the next graph: ");
- Console.ReadLine();
- }
- Array.Reverse(iArray1);
- Draw(iArray1, "iArray1, reversed");
- }
- static CDrawer Draw(int [] iArray, string sMessage)
- {
- CDrawer Canvas = new CDrawer(800, 600);
- Canvas.Scale = 20;
- for (int i = 0; i < iArray.Length; i++)
- {
- Canvas.AddLine(i, 0, i, iArray[i], Color.Yellow, 4);
- Canvas.AddText(sMessage, 24);
- }
- Console.WriteLine("Press enter to open the next graph: ");
- Console.ReadLine();
- return Canvas;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement