Advertisement
Guest User

1.

a guest
Nov 23rd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 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. KLASA ZA 2:
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12.  
  13. namespace ConsoleApplication10
  14. {
  15. class matrixgenerator
  16. {
  17. private static matrixgenerator instance;
  18. private Random generator;
  19. private matrixgenerator()
  20. {
  21. this.generator = new Random();
  22. }
  23. public static matrixgenerator GetInstance()
  24. {
  25. if (instance == null)
  26. {
  27. instance = new matrixgenerator();
  28. }
  29. return instance;
  30. }
  31. public int NextInt()
  32. {
  33. return this.generator.Next();
  34. }
  35. public int NextInt(int upperBound)
  36. {
  37. return this.generator.Next(upperBound);
  38. }
  39. public int NextInt(int lowerBound, int upperBound)
  40. {
  41. return this.generator.Next(lowerBound, upperBound);
  42. }
  43. public double[][] creatematrix(int broj_redaka,int broj_stupaca)
  44. {
  45. double[][] matrix = new double[broj_redaka][];
  46. for (int i = 0; i < 5; i++)
  47. {
  48. matrix[i] = new double[broj_stupaca];
  49. }
  50. for(int i=0;i<broj_redaka;i++)
  51. {
  52. for(int j=0;j<broj_stupaca;j++)
  53. {
  54. matrix[i][j] = this.generator.NextDouble();
  55. }
  56. }
  57. return matrix;
  58. }
  59. }
  60. }
  61.  
  62. KLASA ZA 1:
  63. namespace ConsoleApplication10
  64. {
  65. class Dataset : Prototype
  66. {
  67. private List<List<string>> data; //list of lists of strings
  68. public Dataset()
  69. {
  70. this.data = new List<List<string>>();
  71. }
  72. public Dataset(string filePath) : this()
  73. {
  74. this.LoadDataFromCSV(filePath);
  75. }
  76. public void LoadDataFromCSV(string filePath)
  77. {
  78. using (System.IO.StreamReader reader = new System.IO.StreamReader(filePath))
  79. {
  80. string line;
  81. while ((line = reader.ReadLine()) != null)
  82. {
  83. List<string> row = new List<string>();
  84. string[] items = line.Split(',');
  85. foreach (string item in items)
  86. {
  87. row.Add(item);
  88. }
  89. this.data.Add(row);
  90. }
  91. }
  92. }
  93. public IList<List<string>> GetData()
  94. {
  95. return
  96. new System.Collections.ObjectModel.ReadOnlyCollection<List<string>>(data);
  97. }
  98. public void ClearData()
  99. {
  100. this.data.Clear();
  101. }
  102.  
  103. public Prototype Clone()
  104. {
  105. Dataset lista = new Dataset();
  106. for(int i=0;i<this.data.Count;i++)
  107. {
  108. lista.data.Add(new List<string>());
  109. for(int j=0;j<data[i].Count;j++)
  110. lista.data[i].Add(this.data[i][j]);
  111. }
  112. return (Prototype)this.MemberwiseClone();
  113. return lista;
  114. }
  115. }
  116. }
  117. MAIN:
  118. namespace ConsoleApplication10
  119. {
  120. class Program
  121. {
  122. public static void Print(Dataset DATA)
  123. {
  124. for (int i = 0; i < DATA.GetData().Count; i++)
  125. {
  126.  
  127. for (int j = 0; j < DATA.GetData()[i].Count; j++)
  128. {
  129. Console.Write(DATA.GetData()[i][j] + ", ");
  130. }
  131. Console.WriteLine();
  132.  
  133. }
  134. }
  135. static void Main(string[] args)
  136. {
  137. Dataset DATA = new Dataset("CSV.txt");
  138. Dataset CLONE = (Dataset)DATA.Clone();
  139. Print(DATA);
  140. Console.WriteLine();
  141. Print(CLONE);
  142.  
  143.  
  144. Dataset lista = new Dataset();
  145. matrixgenerator generatormatrica = matrixgenerator.GetInstance();
  146.  
  147. double[][] randmat = generatormatrica.creatematrix(5, 4);
  148.  
  149. for (int i = 0; i < randmat.Length; i++)
  150. {
  151. for (int j = 0; j < randmat[i].Length; j++)
  152. {
  153. Console.Write(randmat[i][j] +" ");
  154. }
  155. Console.WriteLine();
  156. }
  157. }
  158.  
  159. }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement