コード例 #1
0
ファイル: Main.cs プロジェクト: AditiAnand8/PeopleYear
         public static void Main(string[] args)
            {
                
                int yearWithMostalive = 1900;
                int highestAlive = 0;
             
                var listOfPeople = new People().GetPopleFromTextFile();
            
                for (int i = 1900; i <= 2000; i++)
                {
                    int totalAliveinYear = 0;
                    foreach (var person in listOfPeople)
                    {
                        if (i >= person.Birth && i <= person.end)
                            totalAliveinYear = totalAliveinYear + 1;
                    }

                    if (totalAliveinYear > highestAlive)
                    {
                        highestAlive = totalAliveinYear;
                        yearWithMostalive = i;
                    }
                }             
              
                Console.Write("Highest alive is {0} in the year {1}. Enter", highestAlive, yearWithMostalive);

                Application.Run(new chart(highestAlive, yearWithMostalive));
            }
コード例 #2
0
ファイル: chart.cs プロジェクト: AditiAnand8/PeopleYear
        private void chart1_Load(object sender, EventArgs e)
        {
           
            var listOfPeople = new People().GetPopleFromTextFile();
            var list = new List<int>();
          // chart1.BackColor=System.Drawing.Color.Black; 
            chart1.Titles.Add("People Alive");
            foreach (var person in listOfPeople)
            {
                 list.Add(person.end);
                // Add point.
                
            }
            chart1.Series.Clear();
            var series1 = new System.Windows.Forms.DataVisualization.Charting.Series
            {
                Name = "Age",
                Color = System.Drawing.Color.Green,
                IsVisibleInLegend = true,
                IsXValueIndexed = true,
                ChartType = SeriesChartType.Bar
            };
              this.chart1.Series.Add(series1);
          
            foreach (var person in listOfPeople)
            {
                int age = person.end - person.Birth;

                series1.Points.AddXY(person.end, age);
                              
            }
     
        }
コード例 #3
0
ファイル: People.cs プロジェクト: AditiAnand8/PeopleYear
     public List<People> GetPopleFromTextFile() {
     string line;
     var list = new List<People>();
     using (StreamReader reader = new StreamReader("important.txt"))
     {
         while ((line = reader.ReadLine()) != null)
         {
             string[] ls = line.Split(',');
             var person = new People(Convert.ToInt32(ls[0]), Convert.ToInt32(ls[1]));
             list.Add(person);
         }
     }
     return list;
 }