Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Drawing;
  7. using GDIDrawer;
  8. using Utilities;
  9.  
  10. namespace ICA_14
  11. {
  12. class Program
  13. {
  14. static void Main(string[] args)
  15. {
  16. //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
  17. //Which means I can convert the method to void instead of CDrawer
  18. int[] iArray1;
  19. iArray1 = new int[20];
  20. int storage = 0;
  21. int search = 0;
  22. int foundAt = 0;
  23. Random rnd = new Random();
  24. Console.WriteLine("\t\t\tWilliam Fung ICA 14");
  25. for (int i = 0; i < 20; i++)
  26. {
  27. storage = rnd.Next(1, 29);
  28. iArray1[i] = storage;
  29.  
  30. }
  31. int[] iArray2 = (int[])iArray1.Clone();
  32. iArray2[1] = 0;
  33.  
  34. Draw(iArray1, "iArray1, Original Contents");
  35. Draw(iArray2, "iArray2");
  36. iArray2 = new int[40];
  37. iArray1.CopyTo(iArray2, 10);
  38. Draw(iArray2, "iArray2, copied at 10");
  39. Array.Clear(iArray2, 10, 10);
  40. Draw(iArray2, "iArray2, cleared");
  41. Array.Sort(iArray1);
  42. Draw(iArray1, "iArray1, sorted");
  43.  
  44. Console.WriteLine("Array list:");
  45. for (int i = 0; i < 20; i++)
  46. {
  47. Console.WriteLine(iArray1[i]);
  48. }
  49. CUtilities.GetValue(out search, "Enter an integer to search for in iArray1 between 1 and 29: ", 1, 29);
  50. foundAt = Array.BinarySearch(iArray1, search);
  51. Console.WriteLine(foundAt);
  52. if (foundAt < 0)
  53. {
  54. Draw(iArray1, "iArray1, search not found in Array");
  55. //same edit to be made as last one, draw it, return it, then add the text over it
  56.  
  57. }
  58. if (foundAt >= 0)
  59. {
  60. CDrawer Canvas = new CDrawer(800, 600);
  61. Canvas.Scale = 20;
  62. for (int i = 0; i < iArray1.Length; i++)
  63. {
  64. Canvas.AddLine(i, 0, i, iArray1[i], Color.Yellow, 4);
  65. Canvas.AddText("iArray1, binary search", 24);
  66. Canvas.AddLine(foundAt, 0, foundAt, iArray1[foundAt], Color.Red, 4);
  67. //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
  68. }
  69. Console.WriteLine("Press enter to open the next graph: ");
  70. Console.ReadLine();
  71.  
  72. }
  73. Array.Reverse(iArray1);
  74. Draw(iArray1, "iArray1, reversed");
  75.  
  76.  
  77.  
  78. }
  79. static CDrawer Draw(int [] iArray, string sMessage)
  80. {
  81. CDrawer Canvas = new CDrawer(800, 600);
  82. Canvas.Scale = 20;
  83. for (int i = 0; i < iArray.Length; i++)
  84. {
  85. Canvas.AddLine(i, 0, i, iArray[i], Color.Yellow, 4);
  86. Canvas.AddText(sMessage, 24);
  87. }
  88. Console.WriteLine("Press enter to open the next graph: ");
  89. Console.ReadLine();
  90. return Canvas;
  91.  
  92. }
  93.  
  94. }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement