The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 2 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
It is for my Intro to Computer Programming Class. Â I have written the code for the highest, lowest, and average scores. I cant figure out how to write the code for median and standard deviation. I know how to calculate them on pen and paper but writing a code for them is difficult for me. Â I have provided a copy of what I have so far.Please help.
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 Final_Project
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private double Total(double[]dArray)
{
double total = 0;
double finaltotal;
for (int index = 0; index {
total += dArray[index];
}
return total;
}
private double Average(double[]dArray)
{
double total = 0;
double average;
for (int index = 0; index {
total += dArray[index];
}
average = total / dArray.Length;
return average;
}
private double Highest(double[]dArray)
{
double highest = dArray[0];
for (int index = 1; index {
if (dArray[index] > highest)
{
highest = dArray[index];
}
}
return highest;Â
}
private double Lowest(double[]dArray)
{
double lowest = dArray[0];
for (int index = 1; index {
if (dArray[index] {
lowest = dArray[index];
}
}
return lowest;
}
private void buttonGetScores_Click(object sender, EventArgs e)
{
try
{
const int size = 11;
double[] scores = new double[size];
int index = 0;
double highestScores;
double lowestScores;
double averageScores;
double totalScores;
StreamReader inputFile;
inputFile = File.OpenText("Testscores.txt");
while (!inputFile.EndOfStream && index {
scores[index] = int.Parse(inputFile.ReadLine());
index++;
}
inputFile.Close();
foreach (int value in scores)
{
listBoxScores.Items.Add(value);
}
highestScores = Highest(scores);
lowestScores = Lowest(scores);
averageScores = Average(scores);
totalScores = Total(scores);
labelHigh.Text = highestScores.ToString();
labelLow.Text = lowestScores.ToString();
labelAvg.Text = averageScores.ToString("n1");
}
catch (Exception ex)
{
MessageBox.Show("Invalid Number");
}
}
private void buttonExit_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
Â
Â
Â
Â
Final Project Create an application that reads a file called Test Scores.txt with 11 scores. Place the data in an
array or list and display the content of the array or list in a listbox.
Write methods that accept an array or list and returns lowest score, highest score, median score,
average score and the standard deviation of the scores.
Using the methods you created calculate the lowest score, highest score, median score, average
score and the standard deviation of the scores. Display those values in the appropriate labels.
Note: the median is calculated differently if your data is odd or even. Ensure that your method
can handle an even or odd number of data items.
-----------