Advertisement
DomBojko

Untitled

Mar 23rd, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. namespace ProfitCalculator
  4. {
  5. /// ==============================================================================
  6. public class RangeFinder
  7. {
  8. /// <summary>
  9. /// Performs calculations to find the start and end of the "best" data sequence
  10. /// which has the greatest sum of data values over that sequence.
  11. /// </summary>
  12. /// <param name="data">the data to be examined</param>
  13. /// <param name="bestStart">the start point found by the search</param>
  14. /// <param name="bestEnd">the end point found by the search</param>
  15. /// <param name="bestTotal">the sum of data values over that range</param>
  16. /// <param name="loops">the number of executions of the inner loop</param>
  17. public static void MaxSum(double[] data, out int bestStart,
  18. out int bestEnd, out double bestTotal, out int loops)
  19. {
  20. bestTotal = 0;
  21. bestStart = 0;
  22. bestEnd = 0;
  23. loops = 0;
  24. for (int i = 0; i < data.Length; i++)
  25. for (int n = 0; n < data.Length; n++)
  26. {
  27.  
  28. }
  29. }
  30. public static void MaxSum2(double[] data, out int bestStart,
  31. out int bestEnd, out double bestTotal, out int loops)
  32. {
  33. bestTotal = 0;
  34. bestStart = 0;
  35. bestEnd = 0;
  36. loops = 0;
  37. /// TODO - put your process code here
  38. }
  39. public static void MaxSum3(double[] data, out int bestStart,
  40. out int bestEnd, out double bestTotal, out int loops)
  41. {
  42. bestTotal = 0;
  43. bestStart = 0;
  44. bestEnd = 0;
  45. loops = 0;
  46. /// TODO - put your process code here
  47. }
  48. }
  49.  
  50. /// ==============================================================================
  51. /// <summary>
  52. /// Tests the Profits Calculator
  53. /// </summary>
  54. class Test
  55. {
  56. /// <summary>
  57. /// The main entry point for the application.
  58. /// </summary>
  59. static void Main()
  60. {
  61. double[] data;
  62. int bestStart, bestEnd;
  63. double bestTotal;
  64. int loops;
  65. /// name of the file and the number of readings
  66. string filename = "week52.txt";
  67. int items = 52;
  68. data = new double[items]; /// create the data array
  69. try
  70. {
  71. TextReader textIn = new StreamReader(filename);
  72. for (int i = 0; i < items; i++) /// input and store the data values
  73. {
  74. string line = textIn.ReadLine();
  75. data[i] = double.Parse(line);
  76. }
  77. textIn.Close();
  78. }
  79. catch
  80. {
  81. Console.WriteLine("File Read Failed");
  82. return;
  83. }
  84. /// ---------------------------------------------------------------------
  85. /// call the process method to find the best profit period
  86. /// ---------------------------------------------------------------------
  87. RangeFinder.MaxSum(
  88. data, out bestStart, out bestEnd, out bestTotal, out loops);
  89. Console.WriteLine("Start : {0} End : {1} Total {2} Loops {3}",
  90. bestStart, bestEnd, bestTotal, loops);
  91. }
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement