Advertisement
Gillito

Untitled

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