Поиск среднего арифметического элементов файла (создать интерфейс) - C#
Формулировка задачи:
помогите пожалуйста, дан файл вещественных чисел. найти среднее арифметическое его элементов
программа есть, нужно написать для неё интерфейс
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace File14
{
class Program
{
static string test_file = "my_data.txt";
static void Main(string[] args)
{
Console.WriteLine("Данная программа предназначена для нахождения среднего арифметического в введенном пользователем файле.");
Console.WriteLine("Файл расположен в директории File14'\'File14'\'bin'\'Debug");
StreamReader sr = File.OpenText(test_file);//открытие потока на чтение
string str = sr.ReadLine();
string [] numbers = str.Split(new char [] {' ', ','});
double summ = 0;
for (int i = 0; i < numbers.Length; i++)
{
double temp = Convert.ToDouble(numbers[i]);
summ = summ + temp;
}
sr.Close();//закрытие потока на чтение
Console.WriteLine("Среднее арифметическое для полученного файла равно:{0}",summ/numbers.Length);
Console.ReadKey();
}
}
}Решение задачи: «Поиск среднего арифметического элементов файла (создать интерфейс)»
textual
Листинг программы
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button3_Click( object sender, EventArgs e )
{
if ( openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK )
{
textBox1.Text = openFileDialog1.FileName;
}
}
private void button1_Click( object sender, EventArgs e )
{
if ( textBox1.Text == string.Empty )
{
MessageBox.Show( "Не заполнено поле пути до файла." );
return;
}
Process proc = new Process();
proc.StartInfo.Arguments = textBox1.Text;
proc.StartInfo.FileName = "ConsoleApplication1.exe";
proc.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory();
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
using ( StreamReader output = proc.StandardOutput )
{
textBox2.Text = output.ReadToEnd();
}
}
private void button2_Click( object sender, EventArgs e )
{
this.Close();
}
}
}