In: Computer Science
Write a program, using C#, windows forms, that will find the mean and standard deviation of a number of data points. The ONE PROGRAM should allow the user to enter data manually OR via a text file. The program should be very easy to use.
I will also need a step by step how to set up window for the answer. Please and thank you!!
Program:
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;
namespace Find_Mean_StandardDeviation
{
public partial class Form1 : Form
{
double[] points;
public Form1()
{
InitializeComponent();
}
private void btn_GenerateNumbers_Click(object sender, EventArgs
e)
{
lstPoints.Items.Clear();
int num;
num = Convert.ToInt32(txtNum.Text );
//generate 1 to N numbers
Random rand = new Random();
points = new double[num];
//Generating numbers from 0 and 100
for (int i = 0; i < num; i++)
{
points[i] = rand.Next(100); //storing generated numbers in the
array
}
for (int i = 0; i < points.Length; i++)
{
lstPoints.Items.Add(points[i]); //adding all points to listbox
(lstPoint) from the array
}
}
private void btn_calculate_Click(object sender, EventArgs
e)
{
double sum = 0.0, sumSD = 0, mean, v, SD;
//Calculating mean
for (int i = 0; i < points.Length ; i++)
{
sum=sum+points[i];
}
mean = sum / points.Length; //getting mean
txtMean.Text = Math.Round(mean,2).ToString();
//calculating standard deviation
for (int i = 0; i < points.Length; i++)
{
sumSD = sumSD + Math.Pow((points[i]-mean ),2);
}
v = sumSD / points.Length;
SD = Math.Sqrt(v);
txtSD.Text = Math.Round(SD,2).ToString();
}
}
}
Output:
