Calculate Mean, Variance and Standard Deviation. Allow the user to print only Mean or Variance or Standard Deviation or all print all using check boxes.
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 Question3
{
    public partial class Form1 : Form
    {
        int a, b, c;
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            double sumOfSquares = 0.0;
            
            if (checkBox1.Checked)
            {
                if (textBox2.Text == string.Empty && textBox3.Text == string.Empty)
                {
                    a = Convert.ToInt16(textBox1.Text);
                    textBox4.Text = (Convert.ToString(a));
                    textBox4.Show();
                }
                else if (textBox3.Text == string.Empty)
                {
                    a = Convert.ToInt16(textBox1.Text);
                    b = Convert.ToInt16(textBox2.Text);
                    a = (a + b) / 2;
                    textBox4.Text = Convert.ToString(a);
                    textBox4.Show();
                    //----------------------------
                    if (checkBox2.Checked)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            sumOfSquares += Math.Pow((2 - a), 2.0);
                        }
                        textBox5.Text = Convert.ToString(sumOfSquares);
                        textBox5.Show();
                    }
                    if (checkBox3.Checked)
                    {
                        textBox6.Text= Convert.ToString( Math.Sqrt(sumOfSquares));
                        textBox6.Show();
                    }
                }
                else if( textBox2.Text != string.Empty && textBox3.Text != string.Empty && textBox1.Text != string.Empty)
                {
                    a = Convert.ToInt16(textBox1.Text);
                    b = Convert.ToInt16(textBox2.Text);
                    c = Convert.ToInt16(textBox3.Text);
                    a = (a + b + c) / 3;
                    textBox4.Text = Convert.ToString(a);
                    textBox4.Show();
                    //--------------------------
                    
                    if (checkBox2.Checked)
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            sumOfSquares += Math.Pow((3 - a), 2.0);
                        }
                        textBox5.Text = Convert.ToString(sumOfSquares);
                        textBox5.Show();
                    }
                    if (checkBox3.Checked)
                    {
                        textBox6.Text = Convert.ToString(Math.Sqrt(sumOfSquares));
                        textBox6.Show();
                    }
                }
            }
        }
        private void textBox3_TextChanged(object sender, EventArgs e)
        {
        }
        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); textBox5.Clear(); textBox6.Clear();
        }
        private void button3_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}



Post A Comment:
0 comments: