Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need help with a C# application in Visual Studio i am given a txt file that cont

ID: 3684110 • Letter: N

Question

need help with a C# application in Visual Studio i am given a txt file that contains mid-year population from 1950-1990 the first line of the file contains 1950 2nd = 1950 etc...

create an application that reads the file's contents into an array or List.

The application should display the following data: avg annual chg in population during same time period year with greatest and least increase in population

I need help with the designer as well. I can't figure out how to import a txt file into the application so that it can be read and then the math parts

151868

153982

156393

158956

161884

165069

168088

171187

174149

177135

179979

182992

185771

188483

191141

193526

195576

197457

199399

201385

203984

206827

209284

211357

213342

215465

217563

219760

222095

224567

227225

229466

231664

233792

235825

237924

240133

242289

244499

246819

249623

try

{

StreamReader inputFile;

string numbers;

inputFile = File.OpenText("Number List.txt");

numbersListbox.Items.Clear();

while (!inputFile.EndOfStream)

{

numbers = inputFile.ReadLine();

numbersListbox.Items.Add(numbers);

}

inputFile.Close();

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

}

Explanation / 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;
using System.IO;

namespace population_avg_inc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
int[] a= new int[100];
int sum=0, i, min,max;
try
{
StreamReader inputFile;
string numbers;

inputFile = File.OpenText("Number List.txt");
numberListbox.Items.Clear();

while (!inputFile.EndOfStream)
{
numbers = inputFile.ReadLine();

numberListbox.Items.Add(numbers);
}

inputFile.Close();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
for (i = 0; i < numberListbox.Items.Count ; i++)
{
a[i] = numberListbox.Items.IndexOf (i + 1) - numberListbox.Items.IndexOf (i);
sum = sum + a[i];
}
textBox1.Text = ( sum / numberListbox.Items.Count ).ToString ();
min = a[0];
for (i = 0; i < numberListbox.Items.Count - 1; i++)
{
if (a[i] < min)
min = a[i];
}
max = a[0];
for (i = 0; i < numberListbox.Items.Count - 1; i++)
{
if (a[i] >max)
max = a[i];
}
textBox2.Text = max.ToString() ;
textBox3.Text = min.ToString ();

}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{
Close();
}
}
}