Advertisement
solidsnake

C#HandsOnActivityOnFiles

Apr 30th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.24 KB | None | 0 0
  1. PROGRAM  
  2.  
  3.     class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             Person[] array = new Person[100];
  8.             int i = 0;
  9.             int highest = 0;
  10.             int secondHighest = 0;
  11.             int thirdHighest = 0;
  12.            
  13.             try
  14.             {
  15.                 FileStream fs = new FileStream(@"C:\Users\User_2\Desktop\metalgearsolid.txt", FileMode.Open);
  16.                 StreamReader readin = new StreamReader(fs);
  17.                 while (!readin.EndOfStream)
  18.                 {
  19.                     string init = "";
  20.                     init = readin.ReadLine();
  21.                     string[] info = init.Split(',');
  22.                     int grade = int.Parse(info[3]);
  23.                     array[i] = new Person(info[0], info[1], info[2], grade);                    
  24.                     i++;
  25.                 }
  26.  
  27.                 readin.Close();
  28.                 fs.Close();
  29.             }
  30.             catch (Exception e) { }
  31.  
  32.             for (int j = 0; j < i; j++)
  33.             {                
  34.                 if (array[j].Grade > array[highest].Grade)
  35.                 {
  36.                     highest = j;
  37.                 }
  38.             }
  39.  
  40.             for (int x = 0; x < i; x++)
  41.             {                
  42.                 if (array[x].Grade > array[secondHighest].Grade && array[x].Grade < array[highest].Grade)
  43.                 {
  44.                     secondHighest = x;
  45.                 }
  46.             }
  47.  
  48.             for (int v = 0; v < i; v++)
  49.             {
  50.                 if (array[v].Grade > array[secondHighest].Grade && array[v].Grade < array[highest].Grade && array[v].Grade < array[secondHighest].Grade)
  51.                 {
  52.                     thirdHighest = v;
  53.                 }
  54.             }
  55.  
  56.             Console.WriteLine(array[highest].Name);
  57.             Console.WriteLine(array[secondHighest].Name);
  58.             Console.WriteLine(array[thirdHighest].Name);
  59.            
  60.            
  61.             Console.ReadKey();          
  62.         }
  63.  
  64.        
  65.     }
  66.  
  67. PERSON
  68.  
  69.     class Person
  70.     {
  71.         private string name;
  72.         private string number;
  73.         public string course;
  74.         public int grade;
  75.  
  76.         public Person(string name, string number, string course, int grade)
  77.         {
  78.             this.name = name;
  79.             this.number = number;
  80.             this.course = course;
  81.             this.grade = grade;
  82.         }
  83.  
  84.         public string Name
  85.         {
  86.             get
  87.             {
  88.                 return name;
  89.             }
  90.             set
  91.             {
  92.                 name = value;
  93.             }
  94.         }
  95.  
  96.         public string Number
  97.         {
  98.             get
  99.             {
  100.                 return number;
  101.             }
  102.             set
  103.             {
  104.                 number = value;
  105.             }
  106.         }
  107.  
  108.         public string Course
  109.         {
  110.             get
  111.             {
  112.                 return course;
  113.             }
  114.             set
  115.             {
  116.                 course = value;
  117.             }        
  118.         }
  119.  
  120.         public int Grade
  121.         {
  122.             get
  123.             {
  124.                 return grade;
  125.             }
  126.             set
  127.             {
  128.                 grade = value;
  129.             }
  130.         }
  131.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement