Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11.  
  12. namespace chart
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20. static int k = 0;
  21. public static double[,] odczyt (){
  22. string dane;
  23. double[,] tab = new double[4, 2];
  24. FileStream zapis;
  25. zapis = new FileStream("D://zad3.txt", FileMode.Truncate);
  26. StreamWriter sw = new StreamWriter(zapis);
  27.  
  28.  
  29. Random r = new Random();
  30. string srr;
  31.  
  32. for (int i = 0; i < 4; i++)
  33. {
  34. for (int j = 0; j < 2; j++)
  35. {
  36. tab[i, j] = r.NextDouble() * 13;
  37. tab[i, j] = Math.Round(tab[i, j], 2);
  38. srr = (tab[i, j].ToString()).Replace(",", ".");
  39.  
  40. Console.Write(srr + " ");
  41. sw.Write(srr + " ");
  42.  
  43. }
  44.  
  45. Console.WriteLine();
  46. sw.WriteLine();
  47. }
  48. sw.Close();
  49.  
  50.  
  51.  
  52. FileStream odczyt = new FileStream("D://zad3.txt", FileMode.Open);
  53. StreamReader sr = new StreamReader(odczyt);
  54.  
  55. Console.WriteLine("Odczytujemy dane z zapisu");
  56.  
  57. string[] str2;
  58.  
  59. while ((dane = sr.ReadLine()) != null)
  60. {
  61. k++;
  62.  
  63. }
  64. double[,] tab2 = new double[k, 2];
  65. sr.Close();
  66. odczyt = new FileStream("D://zad3.txt", FileMode.Open);
  67. sr = new StreamReader(odczyt);
  68. string dane2;
  69. for (int i = 0; i < k; i++)
  70. {
  71.  
  72. dane2 = sr.ReadLine();
  73. str2 = dane2.Split(' ');
  74. dane2 = str2[0].Replace(".", ",");
  75.  
  76.  
  77. tab2[i, 0] = double.Parse(dane2);
  78. Console.Write(tab2[i, 0] + " ");
  79. dane2 = str2[1].Replace(".", ",");
  80. tab2[i, 1] = double.Parse(dane2);
  81. Console.Write(tab2[i, 1] + " ");
  82.  
  83.  
  84. Console.WriteLine();
  85.  
  86. }
  87. sr.Close();
  88.  
  89. Console.ReadLine();
  90. return tab2;
  91. }
  92. double a =12.34;
  93. double b = 23.67;
  94. double[,] tab = odczyt();
  95. private void button1_Click(object sender, EventArgs e)
  96. {
  97. for (int i = 0; i < k; i++)
  98. {
  99. this.chart1.Series["punkty"].Points.AddXY(tab[i,0], tab[i,1]);
  100.  
  101. }
  102.  
  103. }
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement