Advertisement
Gillito

Untitled

Jun 5th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 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.             {
  19.                 Console.WriteLine("{0} {1}", result.Firstname, result.Lastname);
  20.                 for (int i = 0; i < result.Rating.Length; i++)
  21.                     Console.Write (result.Rating[i] + " ");
  22.             }
  23.             else
  24.                 Console.WriteLine("Поиск не дал результата");
  25.         }
  26.  
  27.         private static Journal CreateJournal()
  28.         {
  29.             Journal journal = new Journal();
  30.             journal.Addstudent("John", "Smith", Rand());
  31.             journal.Addstudent("Han", "Solo", Rand());
  32.             journal.Addstudent("Johny", "Cash", Rand());
  33.             journal.Addstudent("Axel", "Foley", Rand());
  34.             return journal;
  35.         }
  36.  
  37.         public static int[] Rand()
  38.         {
  39.              int[] rand = new int[5];
  40.              Random rnd = new Random();
  41.              for (int i = 0; i < rand.Length; i++)
  42.                 rand[i] = rnd.Next(1,5);
  43.              return rand;
  44.         }
  45.        
  46.     }
  47.  
  48.     class Journal
  49.     {
  50.         private List<Student> students = new List<Student>();
  51.  
  52.         public void Addstudent(string studentFname, string studentLname, int[] rate)
  53.         {
  54.             Student student = new Student();
  55.  
  56.             student.Firstname = studentFname;
  57.             student.Lastname = studentLname;
  58.             student.Rating = rate;
  59.             students.Add(student);
  60.         }
  61.  
  62.         public Student Search(string searchfirstname)
  63.         {
  64.             foreach (Student i in students)
  65.                 if (i.Firstname == searchfirstname)
  66.                     return i;
  67.             return null;
  68.         }
  69.  
  70.         public List <Student> Searchstudents(string searchfirstname)
  71.         {
  72.             List<Student> Searchresult = new List<Student>();
  73.             foreach (Student i in students)
  74.             {
  75.                 if (i.Firstname == searchfirstname)
  76.                     Searchresult.Add(i);
  77.             }
  78.             return Searchresult;
  79.         }
  80.     }
  81.  
  82.     public class Student
  83.     {
  84.         public string Firstname;
  85.         public string Lastname;
  86.         public int[] Rating;
  87.  
  88.         public double Calc()
  89.         {
  90.         int sum = 0;
  91.         for (int i = 0; i < Rating.Length; i++)
  92.             sum += Rating[i];
  93.         return sum / Rating.Length;
  94.         }
  95.     }
  96.  
  97.    
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement