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

visual C# please in windows forms You will find a file named USPopulation.txt at

ID: 3607369 • Letter: V

Question

visual C# please in windows forms

You will find a file named USPopulation.txt attached above. The file contains the midyear population of the United States, in thousands, during the years 1950 through 1990. The first line in the file contains the population for 1950, the second line contains the population for 1951, and so forth.

Create an application that reads the file's contents into an array or a List. The application should display the following data:

The average annual change in population during the time period

The year with the greatest increase in population during the time period

The year with the least increase in population during the time period

There are many ways to display the results. But I want to address a specific question about the last two bullet points: If the population in the file is the mid-year population, then is the year with the greatest increase (or lowest increase) the first or second year since the measurement happens in the middle of the year? Here are results from the Key so you can see one way to display the information:

Notice that the increase listed for 1951 is the increase from midyear 1950 to midyear 1951. Consequently, the largest increase will be the increase from 1954 to 1955 as this image shows:

here is the data

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

Explanation / Answer

Here is the C# code for the problem.

using System;
using System.Collections.Generic;
using System.IO;
class Solution {
  
static void Main(String[] args) {
string line;  

// Read the file Contents line by line
System.IO.StreamReader file = new System.IO.StreamReader(@"USPopulation.txt");  
int a = int.Parse(file.ReadLine());  
int[] arr = new int[50];
int counter =0;
while((line = file.ReadLine()) != null){
//Parsing the string to integer
int x = int.Parse(line);
arr[counter]= x;
counter++;
}  

file.Close();  
// Initialize the difference variables
int maxdiff=0;
int mindiff=arr[1]-arr[0];
int avg=0;
for(counter=0;counter<49;counter++){
int c = arr[counter+1]-arr[counter];
avg = avg +c;
if(maxdiff<c)
maxdiff= c;
if(mindiff>c&&c>0)
mindiff = c;
}
avg = avg/50;
Console.Write("Average annual change in population in thousands ="+avg);
Console.Write("Maximum increase in popluation in thousands ="+ maxdiff);
Console.Write("Least increase in population in thousands ="+ mindiff);
}
}   

As you've mentioned, the change shall be calculated by subtracting the mid-year populations of US. Using this change we'll determine what is the largest and least increase in the population.