Programování 2 Informatici 18.03.2026 Program hodiny: poradi volani konstruktoru pri dedeni; properties; indexers; pretizeni opertoru; prace se soubory 0. Constructor Calling .... The Clash - London Calling 1. Let's have a classes A, B, C: class A is parental, class B inherits from A class and class C inherits from B class. 1.1. Demonstrate/Explore the ordering of calling constructors in process of instantiation of the C class. 3. Properties: setters and getters https://ksvi.mff.cuni.cz/~dingle/2024-5/prog_2/notes_4.html https://ksvi.mff.cuni.cz/~dingle/2023-4/prog_2/notes_4.html/ priklad v sekci properties: - kde se vzala promenna value? k cemu je? a musi se jmenovat "value"? OOP_inherit.txt ... 3.2 Extend class Animal for properties: a) age: not negative integer number; minimal/default value = 0 , b) weight: positive double Proc properties? - encapsulation (nesahej mi na me ... get of my cloud ... rolling stones); security view: control check - odvozeni veliciny (dry code) napr. vime velikost pole _n a z ni odvodime isEmpty, a nemusim si pamatoval dve hodnoty, coz zvysuje komplexitu a muze zpusobit inkonsistenci - idea: "filtr pred vlozenim" - a value je voe musi jmenovat value 5. Pretezovani operatoru a indexery https://ksvi.mff.cuni.cz/~dingle/2023-4/prog_2/notes_4.html/ 5.1 Polynomials https://ksvi.mff.cuni.cz/~dingle/2023-4/prog_2/exercises_4.html Design and implement a C# class Polynomial representing a polynomial of a single variable. Your class should include the following: - a constructor that takes a variable number of arguments of type double, yielding a polynomial with those coefficients. For example: new Polynomial(1.0, 4.0, 5.0) should yield the polynomial x2 + 4x + 5. - a property degree that returns the degree of a polynomial. For example, the polynomial above has degree 2. - indexer that allow changes coeficients of polynom one by one - an overloaded operator + that adds two polynomials - an overloaded operator - that subtracts two polynomials - an overloaded operator * that multiplies two polynomials, or a polynomial and a scalar - a method that evaluates a polynomial for a given value of x - a method that returns the first derivative of a polynomial - a method asString() that yields a string such as "x^2 + 4x + 5" - a static method Parse() that parses a string such as "x^2 + 4x + 5", yielding a polynomial. 7. File / std IO https://ksvi.mff.cuni.cz/~dingle/2023-4/prog_2/notes_3.html/ - StreamReader, StreamWriter from System.IO namespace - reading all lines: while (Console.ReadLine() is string line) { ... do something with line ... } - closing files with 'using': using (StreamWriter sr = new StreamWriter(filename)) { ... use sr here ... } 3.3 Příklad wc: napište obdobu Unix utility wc počítající počet: a) řádků "-l", b) slov "-w", c) písmen "-c", (nedelat: d) není li zadán parametr výpisu, jen jmeno souboru, vytiskne vše) v souboru dle zadaného parametru, obé (parametr, co počítáme i název souboru) zadané z příkazové řádky https://cs.wikipedia.org/wiki/Wc_(Unix) https://www.geeksforgeeks.org/wc-command-linux-examples/ -l : vytiskne počet řádek -c : vytiskne počet bytů -m : vytiskne počet znaků -L : vytiskne délku nejdelší řádky -w : vytiskne počet slov Příklad: wc -l "to_nechces_cist.txt"