Advertisement
AIwinter

5 lab

Feb 23rd, 2022
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.57 KB | None | 0 0
  1. using System;
  2. using System.ComponentModel;
  3. using System.IO;
  4. using System.Windows.Forms;
  5. using System.Windows.Forms.DataVisualization.Charting;
  6.  
  7. namespace Tabulation
  8. {
  9.     public partial class Form1 : Form
  10.     {
  11.         public Form1()
  12.         {
  13.             InitializeComponent();
  14.         }
  15.  
  16.         private void Form1_Load(object sender, EventArgs e)
  17.         {
  18.  
  19.         }
  20.  
  21.         private void textBox1_TextChanged(object sender, EventArgs e)
  22.         {
  23.  
  24.         }
  25.  
  26.         private void textBox2_TextChanged(object sender, EventArgs e)
  27.         {
  28.  
  29.         }
  30.  
  31.         private void textBox3_TextChanged(object sender, EventArgs e)
  32.         {
  33.  
  34.         }
  35.  
  36.         private void button1_Click(object sender, EventArgs e)
  37.         {
  38.             if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
  39.             {
  40.                 MessageBox.Show("Заполни все пустые поля", "Постой");
  41.                 return;
  42.             }
  43.  
  44.             string Path = Application.StartupPath + @"\OUTPUT.txt";
  45.  
  46.             double a = Convert.ToDouble(textBox1.Text);
  47.             double b = Convert.ToDouble(textBox3.Text);
  48.             double h = Convert.ToDouble(textBox2.Text);
  49.  
  50.             if (a>b)
  51.             {
  52.                 MessageBox.Show("Некорректное значение a или b", "Постой");
  53.                 return;
  54.             }
  55.  
  56.             double y;
  57.  
  58.             FileStream file = new FileStream(Path, FileMode.OpenOrCreate);
  59.             StreamWriter stream = new StreamWriter(file);
  60.  
  61.             stream.WriteLine("Тагирова Валерия \n!     X       !      Y       !");
  62.  
  63.             // График
  64.             this.chart1.Series[0].Points.Clear();
  65.             while (a<=b)
  66.             {
  67.                 if (a >= 0)
  68.                 {
  69.                     y = Math.Round(Math.Pow(a, 6.5) / Math.Exp(Math.Cos(a)), 3);
  70.                     stream.WriteLine("!     " + a + "       !      " + y + "       !");
  71.                     this.chart1.Series[0].Points.AddXY(a, y);
  72.                 }
  73.                 else
  74.                 {
  75.                     stream.WriteLine("!     " + a + "       !      -       !");
  76.                 }
  77.                 a = Math.Round(a + h, 3);
  78.             }
  79.  
  80.             chart1.SaveImage(Application.StartupPath + @"\OUTPUT.png", ChartImageFormat.Png);
  81.  
  82.             stream.Close();
  83.             file.Close();
  84.         }
  85.  
  86.         private void textBox1_KeyPress(object sender, KeyPressEventArgs e) //a
  87.         {
  88.             if (Char.IsNumber(e.KeyChar) || e.KeyChar == ',' || e.KeyChar == '\b' || e.KeyChar == '-') return;
  89.             else
  90.                 e.Handled = true;
  91.         }
  92.  
  93.         private void textBox2_KeyPress(object sender, KeyPressEventArgs e) //h
  94.         {
  95.             if (Char.IsNumber(e.KeyChar) || e.KeyChar == ',' || e.KeyChar == '\b') return;
  96.             else
  97.                 e.Handled = true;
  98.         }
  99.  
  100.         private void textBox3_KeyPress(object sender, KeyPressEventArgs e) //b
  101.         {
  102.             if (Char.IsNumber(e.KeyChar) || e.KeyChar == ',' || e.KeyChar == '\b' || e.KeyChar == '-') return;
  103.             else
  104.                 e.Handled = true;
  105.         }
  106.  
  107.         private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
  108.         {
  109.  
  110.         }
  111.  
  112.         private void chart1_Click(object sender, EventArgs e)
  113.         {
  114.  
  115.         }
  116.  
  117.         private void label3_Click(object sender, EventArgs e)
  118.         {
  119.  
  120.         }
  121.  
  122.         private void label2_Click(object sender, EventArgs e)
  123.         {
  124.  
  125.         }
  126.     }
  127.  
  128.  
  129. }
  130.  
  131.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement