Advertisement
Gillito

Untitled

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