Advertisement
k_vychodilova

zprg2010_02

Oct 20th, 2016
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.08 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 Vycho_20._10
  8. {//referencni typ tridy
  9.  
  10.     class Student
  11.     {   //public - aby bylo umozneno zmenit hodnotu
  12.         public int OsobniCislo;
  13.         public int Rocnik;
  14.         public string Jmeno;
  15.         public string Prijmeni;
  16.         public double Test1;
  17.         public double Test2;
  18.         public double Test3;
  19.  
  20.         //konstruktor
  21.         public Student(int osobniCislo, string jmeno, string prijmeni, int rocnik)
  22.         {
  23.             OsobniCislo = osobniCislo;
  24.             Jmeno = jmeno;
  25.             Prijmeni = prijmeni;
  26.             Rocnik = rocnik;
  27.  
  28.         }
  29.         public void ZmenVysledkyTestu(double test1, double test2, double test3)
  30.         {
  31.             Test1 = test1;
  32.             Test2 = test2;
  33.             Test3 = test3;
  34.  
  35.         }
  36.         public bool SplnilPodminky()
  37.         {
  38.             bool splnil = false;
  39.             //vrati true pokud jsou všechny testy nad 15 bodu
  40.             if ((Test1 > 15) && (Test2 > 15) && (Test3 > 15))
  41.             {
  42.                 splnil = true;
  43.             }
  44.  
  45.             return splnil;
  46.         }
  47.         public double VratSumuTestu()
  48.         {
  49.             Test1 + Test2 + Test3;
  50.  
  51.         }
  52.        
  53.     }
  54.  
  55.     class Program
  56.     {
  57.         static void Main(string[] args)
  58.         {
  59.             //System.IO.StreamReader sr = new System.IO.StreamReader()
  60.             //reference
  61.  
  62.             Student st1 = null;
  63.             //new vytvoreni objektu v pameti
  64.             st1 = new Student(1,"Jakub","Kolac",5);
  65.             st1.Test1 = 18;
  66.             st1.Test2 = 17;
  67.             st1.Test3 = 16;
  68.            bool splnil = st1.SplnilPodminky();
  69.            Console.WriteLine($"{st1.Prijmeni} splnil: {splnil}");
  70.  
  71.             Student st2 = null;
  72.             st2 = new Student(2, "Josef", "Novak", 4);
  73.             st2.Test1 = 12;
  74.             st2.Test1 = 15;
  75.             st2.Test3 = 14;
  76.             st2.ZmenVysledkyTestu(16, 15, 47);
  77.            
  78.             splnil = st2.SplnilPodminky();
  79.  
  80.             //vytvoření pole
  81.             List<Student> studenti = new List<Student>():
  82.             studenti.Add(st1);
  83.             studenti.Add(st2);
  84.  
  85.             foreach (var student in studenti)
  86.             {
  87.                 Console.WriteLine($"{student.Prijmeni} splnil: {student.SplnilPodminky()}");
  88.  
  89.             }
  90.  
  91.             for (int i = 0; i < studenti.Count(); i++)
  92.             {
  93.                 var student = studenti[i];
  94.                 Console.WriteLine($"{student.Prijmeni} splnil: {student.SplnilPodminky()}");
  95.             }
  96.             Student max = studenti.First();
  97.             for (int i = 1; i < studenti.Count(); i++)
  98.             {
  99.                 var aktualni = studenti[i];
  100.                 if (aktualni.VratSumuTestu() > max.VratSumuTestu())
  101.                 {
  102.                     max = aktualni;
  103.                 }
  104.  
  105.  
  106.             }
  107.  
  108.  
  109.  
  110.             Console.WriteLine($"{st2.Prijmeni} splnil: {splnil}");
  111.             Console.ReadKey();
  112.  
  113.  
  114.  
  115.         }
  116.     }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement