Advertisement
Gillito

Untitled

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