Attached is a text file containing abbreviations for the months of the year and
ID: 3778704 • Letter: A
Question
Attached is a text file containing abbreviations for the months of the year and the projected sales in each month for a new model of motorcycle. ABC Motorcycle Company in Chicago is launching this new motorcycle in January 2017. They have hired you as a consultant.
Read the text file into your program when the program begins and store the information in parallel arrays. Create a function to calculate the mean and another one to calculate the standard deviation.
Create a subroutine that will display on the user interface (not a message box) the mean, standard deviation, month(s) with the highest expected sales and the lowest expected sales (along with the sales projection).
Create your user interface so that the user may change the projected sales for any month and recalculate/redisplay the information in the paragraph above.
Write a memo to ABC Company (2 page limit) explaining your interpretation of the original monthly projections.
Turn in a hard copy of your algorithm, vb code file, and memo. Submit all of these plus your .exe file
This is using microsoft visual studio.
ABCPgm5.txt Jan 9 feb 7 mar 10 apr 8 may 7 Jun 12 jul 10 aug 11 Sep 12 oct 10 nov 14 dec 16 2012046 0 971871111111Explanation / Answer
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CalculateData
{
public partial class DataCalculator : Form
{
List<double> data;
public DataCalculator()
{
InitializeComponent();
}
private void loadData(object sender, EventArgs e)
{
data = new List<double>();
System.IO.StreamReader file =
new System.IO.StreamReader("data.txt");
while((line = file.ReadLine()) != null)
{
String temp = line.split(" ");
data.add(Double.parseDouble(temp[1]);
}
file.Close();
}
void displayData()
{
lbxValues.Items.Clear();
for (int i = 0; i < data.Count; i++)
lbxValues.Items.Add(data[i]);
}
private void btnAdd_Click(object sender, EventArgs e)
{
// calculating values and adding to GUI
double value = 0.00;
double sumForMean = 0.00, totalSum = 0.00, mean = 0.00;
double standardDeviation = 0.00;
// check for user entered empty string
if (txtValue.Text.Length == 0)
{
MessageBox.Show("Emoty value", "Standard Deviation");
return;
}
try
{
// fetching user entered value
value = double.Parse(txtValue.Text);
data.Add(value);
displayData();
txtValue.Text = "";
txtValue.Focus();
}
catch (FormatException)
{
MessageBox.Show("invalid entry.",
"Standard Deviation");
}
// sum to mean
for (int i = 0; i < data.Count; i++)
sumForMean += data[i];
// Calculate mean
mean = sumForMean / data.Count;
// total for standard deviation
for (int i = 0; i < data.Count; i++)
totalSum += Math.Pow(data[i] - mean, 2);
// Calculate standard deviation
standardDeviation = Math.Sqrt(totalSum / (data.Count - 1));
// Display data
txtCount.Text = data.Count.ToString();
txtSum.Text = sumForMean.ToString("F");
txtMean.Text = mean.ToString("F");
txtStandardDeviation.Text = standardDeviation.ToString("F");
}
private void btnClear_Click(object sender, EventArgs e)
{
data.Clear();
lbxValues.Items.Clear();
txtValue.Text = "";
txtCount.Text = "";
txtSum.Text = "";
txtMean.Text = "";
txtStandardDeviation.Text = "";
txtValue.Focus();
}
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.