// predpisemkou1.cpp : main project file. #include "stdafx.h" using namespace System; using namespace System::Collections; public interface class Ivek { int HowOld(); }; public ref class Clovek : Ivek { public: property String^ Barva; property int Vek; Clovek() { this->Barva = "bílá"; this->Vek = 0; } Clovek(String^ Barva, int Vek) { this->Barva = Barva; this->Vek = Vek; } virtual int HowOld() { return this->Vek; } virtual String^ ToString() override { return Object::ToString() + " " + this->Barva + " " + this->Vek; } }; public ref class Zamestnanec : Clovek { public: property double Vydelek; Zamestnanec() : Clovek("bílá",0) { this->Vydelek = 0; } Zamestnanec(String^ Barva, int Vek, double Vydelek) : Clovek(Barva, Vek) { this->Vydelek = Vydelek; } virtual String^ ToString() override { return Object::ToString() + " " + this->Barva + " " + this->Vek + " " + this->Vydelek; } }; public ref class Slovnicek { private: property String^ Jazyky; public: Hashtable^ Tabulka; Slovnicek() { Tabulka = gcnew Hashtable; this->Jazyky = "Česko-anglický slovník"; } Slovnicek(String^ jazyky) { Tabulka = gcnew Hashtable; this->Jazyky = jazyky; } virtual String^ GetJazyky() { return this->Jazyky; } virtual void Pridat(String^ cesky, String^ cizacky) { this->Tabulka->Add(cesky, cizacky); } virtual void VypisSlovnik() { DictionaryEntry^ Radek; int delka; int tabulatory; int i; String^ mezera; for each (Radek in this->Tabulka) { mezera = ""; delka = Radek->Key->ToString()->Length; tabulatory = 4 - delka / 8; for (i=1;i<=tabulatory;i++) mezera += "\t"; Console::WriteLine(Radek->Key + mezera + Radek->Value); } } virtual String^ Hledani(String^ slovo) { if (this->Tabulka->ContainsKey(slovo)) return safe_cast(this->Tabulka[slovo]); else return "Slovo nenalezeno :-(."; } }; int main(array ^args) { String^ s = L"Vlastimil Dobrota: "; int a = 10; String^ r = s + a; Console::WriteLine(r + a); Clovek^ Petr = gcnew Clovek("černá",20); Console::WriteLine(Petr); Console::WriteLine(Petr->ToString()); Zamestnanec^ Jarda = gcnew Zamestnanec("šedivá",21,2100); Console::WriteLine(Jarda); Zamestnanec^ KiLLeR = gcnew Zamestnanec("bílá",20,21000); Console::WriteLine(KiLLeR); ArrayList^ Otroci = gcnew ArrayList; Otroci->Add(Jarda); Otroci->Add(KiLLeR); double NaVyplaty = 0; for each (Zamestnanec^ Zam in Otroci) { NaVyplaty += Zam->Vydelek; } Console::WriteLine(NaVyplaty); String^ veta = "vincenzo.servegame.com je ten nejlepsi server na svete."; Console::WriteLine(veta); veta = veta->Insert(8,".hacker"); Console::WriteLine(veta); veta = " " + veta + " "; Console::WriteLine(veta); veta = veta->Trim(); Console::WriteLine(veta); int mezera = veta->IndexOf(" "); String^ slovo = veta->Substring(0,mezera); Console::WriteLine(slovo); for each (int c in veta) //Tenhle blok se chova divne { char d = safe_cast(c); Console::Write(c); } Console::WriteLine(); /* ABY TO NEZDRZOVALO PRI TESTOVANI - PLNE FUNKCNI! int cis1; try { cis1 = int::Parse(Console::ReadLine()); } catch (Exception^) { Console::WriteLine("Chyba"); } double cis2; try { cis2 = safe_cast(cis1); } catch (Exception^) { Console::WriteLine("Chyba"); } Console::WriteLine(cis1 + " " + cis2); */ Zamestnanec^ Domi = gcnew Zamestnanec("bílá", 20, 15000); Console::WriteLine(Domi->ToString()); Clovek^ Vojta = gcnew Clovek; Vojta = safe_cast(Domi); Console::WriteLine(Vojta->ToString()); Console::WriteLine(Vojta->Barva + " " + Vojta->Vek); Clovek^ Bourec = gcnew Clovek; Bourec->Barva = Vojta->Barva; Bourec->Vek = Vojta->Vek; Console::WriteLine(Bourec->ToString()); Zamestnanec^ Unknown = safe_cast(Domi); Console::WriteLine(Domi->ToString()); String^ PocetMonitoru = "asi 3"; int Monitoru; bool ok = false; while (ok != true) { try { Monitoru = int::Parse(PocetMonitoru); ok = true; } catch (Exception^) { PocetMonitoru = PocetMonitoru->Substring(1); } } Console::WriteLine(Monitoru); Slovnicek^ CjAj = gcnew Slovnicek("Česko - Anglický VincEnzův slovník"); Console::WriteLine(CjAj->GetJazyky()); //Console::WriteLine(CjAj->Jazyky); //Nejde, protoze jsem v tride Slovnicek dal property Jazyky do private String^ Auto1 = "auto"; String^ Auto2 = "car"; CjAj->Pridat(Auto1, Auto2); CjAj->Pridat("kolo","bicycle"); CjAj->Pridat("počítač","computer"); CjAj->Pridat("tiskárna","printer"); CjAj->Pridat("konektivita","connectivity"); CjAj->Pridat("Co to do hajzlu bylo?!","What the fuck?!"); CjAj->VypisSlovnik(); Console::WriteLine(L"Co chcete najít?"); String^ hledani = Console::ReadLine(); Console::WriteLine(CjAj->Hledani(hledani)); return 0; }