Advertisement
Gillito

Untitled

Jun 5th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication32
  8. {
  9.     public class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Journal journal = CreateJournal();
  14.            
  15.             Console.WriteLine("кого искать?");
  16.             Student result = journal.Search(Console.ReadLine());
  17.             if (result != null)
  18.                 Console.WriteLine("{0} {1} {2}", result.Firstname, result.Lastname, result.Rating);
  19.             else
  20.                 Console.WriteLine("Поиск не дал результата");
  21.         }
  22.  
  23.         private static Journal CreateJournal()
  24.         {
  25.             Journal journal = new Journal();
  26.             journal.Addstudent("John", "Smith", new int[] {5,4,4,5,3});
  27.             journal.Addstudent("Han", "Solo", new int[] {5,5,5,4,5});
  28.             journal.Addstudent("Johny", "Cash", new int[] {3,3,5,3,4});
  29.             journal.Addstudent("Axel", "Foley", new int[] {4,5,4,5,5});
  30.             return journal;
  31.         }
  32.     }
  33.  
  34.     class Journal
  35.     {
  36.         private List<Student> students = new List<Student>();
  37.  
  38.         public void Addstudent(string studentFname, string studentLname, int[] rate)
  39.         {
  40.             Student student = new Student();
  41.  
  42.             student.Firstname = studentFname;
  43.             student.Lastname = studentLname;
  44.             student.Rating = rate;
  45.             students.Add(student);
  46.         }
  47.  
  48.         public Student Search(string searchfirstname)
  49.         {
  50.             foreach (Student i in students)
  51.                 if (i.Firstname == searchfirstname)
  52.                     return i;
  53.             return null;
  54.         }
  55.  
  56.         public List <Student> Searchstudents(string searchfirstname)
  57.         {
  58.             List<Student> Searchresult = new List<Student>();
  59.             foreach (Student i in students)
  60.             {
  61.                 if (i.Firstname == searchfirstname)
  62.                     Searchresult.Add(i);
  63.             }
  64.             return Searchresult;
  65.         }
  66.     }
  67.  
  68.     public class Student
  69.     {
  70.         public string Firstname;
  71.         public string Lastname;
  72.         public int[] Rating = new int[5];
  73.  
  74.         public static double Calc(int[] calcRate)
  75.         {
  76.         int sum = 0;
  77.         for (int i = 0; i < calcRate.Length; i++)
  78.             sum += calcRate[i];
  79.         return sum / calcRate.Length;
  80.         }
  81.     }
  82.  
  83.    
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement