Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Vycho_20._10
- {//referencni typ tridy
- class Student
- { //public - aby bylo umozneno zmenit hodnotu
- public int OsobniCislo;
- public int Rocnik;
- public string Jmeno;
- public string Prijmeni;
- public double Test1;
- public double Test2;
- public double Test3;
- //konstruktor
- public Student(int osobniCislo, string jmeno, string prijmeni, int rocnik)
- {
- OsobniCislo = osobniCislo;
- Jmeno = jmeno;
- Prijmeni = prijmeni;
- Rocnik = rocnik;
- }
- public void ZmenVysledkyTestu(double test1, double test2, double test3)
- {
- Test1 = test1;
- Test2 = test2;
- Test3 = test3;
- }
- public bool SplnilPodminky()
- {
- bool splnil = false;
- //vrati true pokud jsou všechny testy nad 15 bodu
- if ((Test1 > 15) && (Test2 > 15) && (Test3 > 15))
- {
- splnil = true;
- }
- return splnil;
- }
- public double VratSumuTestu()
- {
- Test1 + Test2 + Test3;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- //System.IO.StreamReader sr = new System.IO.StreamReader()
- //reference
- Student st1 = null;
- //new vytvoreni objektu v pameti
- st1 = new Student(1,"Jakub","Kolac",5);
- st1.Test1 = 18;
- st1.Test2 = 17;
- st1.Test3 = 16;
- bool splnil = st1.SplnilPodminky();
- Console.WriteLine($"{st1.Prijmeni} splnil: {splnil}");
- Student st2 = null;
- st2 = new Student(2, "Josef", "Novak", 4);
- st2.Test1 = 12;
- st2.Test1 = 15;
- st2.Test3 = 14;
- st2.ZmenVysledkyTestu(16, 15, 47);
- splnil = st2.SplnilPodminky();
- //vytvoření pole
- List<Student> studenti = new List<Student>():
- studenti.Add(st1);
- studenti.Add(st2);
- foreach (var student in studenti)
- {
- Console.WriteLine($"{student.Prijmeni} splnil: {student.SplnilPodminky()}");
- }
- for (int i = 0; i < studenti.Count(); i++)
- {
- var student = studenti[i];
- Console.WriteLine($"{student.Prijmeni} splnil: {student.SplnilPodminky()}");
- }
- Student max = studenti.First();
- for (int i = 1; i < studenti.Count(); i++)
- {
- var aktualni = studenti[i];
- if (aktualni.VratSumuTestu() > max.VratSumuTestu())
- {
- max = aktualni;
- }
- }
- Console.WriteLine($"{st2.Prijmeni} splnil: {splnil}");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement