Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace WindowsFormsApp18
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void btn_load_Click(object sender, EventArgs e)
- {
- OpenFileDialog loadDialog = new OpenFileDialog();
- loadDialog.Filter = "txt files (*.txt)|*.txt";
- if (loadDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- textBox1.Clear();
- StreamReader file = new StreamReader(loadDialog.OpenFile());
- string write;
- while((write = file.ReadLine()) != null)
- {
- textBox1.AppendText(write + "\n");
- }
- file.Close();
- }
- }
- private void btn_save_Click(object sender, EventArgs e)
- {
- SaveFileDialog saveDialog = new SaveFileDialog();
- saveDialog.Filter = "txt files (*.txt)|*.txt";
- if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
- {
- StreamWriter file = new StreamWriter(saveDialog.OpenFile());
- foreach(string text in textBox1.Lines)
- {
- file.WriteLine(text);
- file.Flush();
- }
- file.Close();
- }
- textBox1.Clear();
- }
- private void btn_calculate_Click(object sender, EventArgs e)
- {
- List<string> output = new List<string>();
- foreach(string text in textBox1.Lines)
- {
- /*if (text.Any(char.IsDigit))
- {
- output.Add(text)
- return;
- }*/
- double a, b;
- char c;
- string[] znak = text.Split(new Char[] { ' ' });
- a = Double.Parse(znak[0]);
- b = Double.Parse(znak[2]);
- c = Char.Parse(znak[1]);
- switch (c)
- {
- case '+': output.Add( a.ToString() + " + " + b.ToString() + " = " + (a + b).ToString() + "\n" ); break;
- case '*': output.Add( a.ToString() + " * " + b.ToString() + " = " + (a * b).ToString() + "\n"); break;
- case '-': output.Add( a.ToString() + " - " + b.ToString() + " = " + (a - b).ToString() + "\n"); break;
- case '/': output.Add( a.ToString() + " / " + b.ToString() + " = " + (a / b).ToString() + "\n"); break;
- case '^': output.Add( a.ToString() + " ^ " + b.ToString() + " = " + (Math.Pow(a,b)).ToString() + "\n"); break;
- }
- }
- textBox1.Clear();
- foreach(string text in output)
- {
- textBox1.AppendText(text);
- }
- }
- private void btn_transform_Click(object sender, EventArgs e)
- {
- List<string> output = new List<string>();
- foreach(string text in textBox1.Lines)
- {
- output.Add(text.ToLower());
- }
- textBox1.Clear();
- foreach(string text in output)
- {
- textBox1.AppendText(text + "\n");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement