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;
- KLASA ZA 2:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication10
- {
- class matrixgenerator
- {
- private static matrixgenerator instance;
- private Random generator;
- private matrixgenerator()
- {
- this.generator = new Random();
- }
- public static matrixgenerator GetInstance()
- {
- if (instance == null)
- {
- instance = new matrixgenerator();
- }
- return instance;
- }
- public int NextInt()
- {
- return this.generator.Next();
- }
- public int NextInt(int upperBound)
- {
- return this.generator.Next(upperBound);
- }
- public int NextInt(int lowerBound, int upperBound)
- {
- return this.generator.Next(lowerBound, upperBound);
- }
- public double[][] creatematrix(int broj_redaka,int broj_stupaca)
- {
- double[][] matrix = new double[broj_redaka][];
- for (int i = 0; i < 5; i++)
- {
- matrix[i] = new double[broj_stupaca];
- }
- for(int i=0;i<broj_redaka;i++)
- {
- for(int j=0;j<broj_stupaca;j++)
- {
- matrix[i][j] = this.generator.NextDouble();
- }
- }
- return matrix;
- }
- }
- }
- KLASA ZA 1:
- namespace ConsoleApplication10
- {
- class Dataset : Prototype
- {
- private List<List<string>> data; //list of lists of strings
- public Dataset()
- {
- this.data = new List<List<string>>();
- }
- public Dataset(string filePath) : this()
- {
- this.LoadDataFromCSV(filePath);
- }
- public void LoadDataFromCSV(string filePath)
- {
- using (System.IO.StreamReader reader = new System.IO.StreamReader(filePath))
- {
- string line;
- while ((line = reader.ReadLine()) != null)
- {
- List<string> row = new List<string>();
- string[] items = line.Split(',');
- foreach (string item in items)
- {
- row.Add(item);
- }
- this.data.Add(row);
- }
- }
- }
- public IList<List<string>> GetData()
- {
- return
- new System.Collections.ObjectModel.ReadOnlyCollection<List<string>>(data);
- }
- public void ClearData()
- {
- this.data.Clear();
- }
- public Prototype Clone()
- {
- Dataset lista = new Dataset();
- for(int i=0;i<this.data.Count;i++)
- {
- lista.data.Add(new List<string>());
- for(int j=0;j<data[i].Count;j++)
- lista.data[i].Add(this.data[i][j]);
- }
- return (Prototype)this.MemberwiseClone();
- return lista;
- }
- }
- }
- MAIN:
- namespace ConsoleApplication10
- {
- class Program
- {
- public static void Print(Dataset DATA)
- {
- for (int i = 0; i < DATA.GetData().Count; i++)
- {
- for (int j = 0; j < DATA.GetData()[i].Count; j++)
- {
- Console.Write(DATA.GetData()[i][j] + ", ");
- }
- Console.WriteLine();
- }
- }
- static void Main(string[] args)
- {
- Dataset DATA = new Dataset("CSV.txt");
- Dataset CLONE = (Dataset)DATA.Clone();
- Print(DATA);
- Console.WriteLine();
- Print(CLONE);
- Dataset lista = new Dataset();
- matrixgenerator generatormatrica = matrixgenerator.GetInstance();
- double[][] randmat = generatormatrica.creatematrix(5, 4);
- for (int i = 0; i < randmat.Length; i++)
- {
- for (int j = 0; j < randmat[i].Length; j++)
- {
- Console.Write(randmat[i][j] +" ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement