- using System;
- namespace Kolokwium_KacperDec
- {
- class Program
- {
- static void Main(string[] args)
- {
- string wybor;
- string[] produkt = new string[5];
- produkt[0] = "Krzyżacy";
- produkt[1] = "Pan Tadeusz";
- produkt[2] = "Vabank";
- produkt[3] = "Miś";
- produkt[4] = "Seksmisja";
- string[] rezyser = new string[5];
- rezyser[0] = "Ford";
- rezyser[1] = "Wajda";
- rezyser[2] = "Machulski";
- rezyser[3] = "Bareja";
- rezyser[4] = "Machulski";
- double[] cena = new double[5];
- cena[0] = 15.5;
- cena[1] = 14;
- cena[2] = 15.5;
- cena[3] = 17;
- cena[4] = 18;
- int[] czas = new int[5];
- czas[0] = 185;
- czas[1] = 155;
- czas[2] = 155;
- czas[3] = 120;
- czas[4] = 120;
- byte[] lp = new byte[5];
- lp[0] = 1;
- lp[1] = 2;
- lp[2] = 3;
- lp[3] = 4;
- lp[4] = 5;
- bool NotEnd = true;
- Poczatek();
- Menu();
- label: Console.WriteLine("Wybierz...");
- wybor = Console.ReadLine();
- do
- {
- switch (wybor)
- {
- case "m":
- Menu();
- break;
- case "k":
- NotEnd = false;
- break;
- case "c":
- Console.Clear();
- break;
- case "w":
- TabelaLALA(lp,produkt,rezyser,cena,czas);
- return;
- case "nk":
- Najkrotszy(czas);
- return;
- case "nd":
- Najdluzszy(czas);
- return;
- case "rc":
- Losowy(lp, produkt, rezyser, cena, czas);
- return;
- case "l":
- Laczny(czas);
- return;
- case "sc":
- Srednia(czas);
- return;
- case "v":
- Wariacja(czas);
- return;
- case "sk":
- SredniKoszt(cena);
- return;
- case "sr":
- SzukajRez(rezyser);
- return;
- case "sf":
- SzukajFi(produkt);
- return;
- case "s<":
- KrotszyOd(czas);
- return;
- case "s>":
- DluzszyOd(czas);
- return;
- default:
- Console.WriteLine("Podałeś złą komendę.");
- goto label;
- }
- }
- while (NotEnd);
- Console.WriteLine("Naciśnij dowolny klawisz aby zakończyć program...");
- }
- static void Menu()
- {
- Console.WriteLine("******************MENU******************");
- Console.WriteLine("\tm - wyświetli Menu");
- Console.WriteLine("\tk - kończy program");
- Console.WriteLine("\tc - czyści konsolę");
- Console.WriteLine();
- Console.WriteLine("\tw - wyświetli tabelę");
- Console.WriteLine("\trc - losowy czas trwania 100 - 200 1");
- Console.WriteLine("\tnk - najkrótszy film");
- Console.WriteLine("\tnd - najdłuższy film");
- Console.WriteLine("\tl - łączny czas trwania wszystkich filmów");
- Console.WriteLine("\tsc - średni czas trwania filmu");
- Console.WriteLine("\ts< - szukaj filmów krótszego od podanego czasu");
- Console.WriteLine("\ts> - szukaj filmu dłuższego od podanego czasu");
- Console.WriteLine("\tv - wariacja czasu trwania filmu");
- Console.WriteLine("\tsk - średni koszt wypożyczenia filmu");
- Console.WriteLine("\tsr szukaj reżysera");
- Console.WriteLine("\tsf - szukaj filmu");
- Console.WriteLine("\tz - zmień");
- Console.WriteLine("****************************************");
- }
- static void Poczatek()
- {
- Console.WriteLine("*** *** Wypożyczalnia Filmów *** ***");
- Console.WriteLine("Wykonał Kacper Dec");
- }
- static void TabelaLALA(byte[] lp, string[] produkt, string[] rezyser, double[] cena, int[] czas)
- {
- Console.WriteLine("---------------------------------------------------------------");
- Console.WriteLine("| Lp. | Produkt | Reżyser | Cena | Czas |");
- Console.WriteLine("---------------------------------------------------------------");
- for (int i = 0; i<lp.Length; i++)
- {
- Console.WriteLine("|{0} |{1} |{2} |{3} |{4} |", lp[i], produkt[i], rezyser[i], cena[i], czas[i]);
- }
- Console.WriteLine("---------------------------------------------------------------");
- Menu();
- }
- static void Najkrotszy(int[] czas)
- {
- int wynik = 120;
- for (int i = 0; i < czas.Length; i++)
- {
- if (wynik > czas[i])
- {
- wynik = czas[i];
- }
- }
- Console.WriteLine("Najkrótszy film trwa: " + wynik);
- }
- static void Najdluzszy(int[] czas)
- {
- int wynik = 0;
- for (int i = 1; i < czas.Length; i++)
- {
- if (wynik < czas[i])
- {
- wynik = czas[i];
- }
- }
- Console.WriteLine("Najdłuższy film trwa 185");
- }
- static void Losowy(byte[] lp, string[] produkt, string[] rezyser, double[] cena, int[] czas)
- {
- Random rnd = new Random();
- for (int i = 0; i < czas.Length; i++)
- {
- czas[i] = rnd.Next(100, 200);
- }
- Console.WriteLine("---------------------------------------------------------------");
- Console.WriteLine("| Lp. | Produkt | Reżyser | Cena | Czas |");
- Console.WriteLine("---------------------------------------------------------------");
- for (int i = 0; i < lp.Length; i++)
- {
- Console.WriteLine("|{0} |{1} |{2} |{3} |{4} |", lp[i + 1], produkt[i], rezyser[i], cena[i], czas[i]);
- }
- Console.WriteLine("---------------------------------------------------------------");
- }
- static void Laczny(int[] czas)
- {
- int w;
- w = czas[0] + czas[1] + czas[2] + czas[3] + czas[4];
- Console.WriteLine("Łączny czas trwania filmów to: {0} minut(y)", w);
- }
- static void Srednia(int[] czas)
- {
- double suma = 0, sr = 0;
- for (int i = 0; i < czas.Length; i++)
- {
- suma += czas[i];
- }
- sr = suma / czas.Length;
- Console.WriteLine("Średni czas trwania filmu wynosi: {0} minut(y)", sr);
- }
- static void Wariacja(int[] czas)
- {
- double suma = 0, sr = 0, wariacja = 0;
- for (int i = 0; i < czas.Length; i++)
- {
- suma += czas[i];
- }
- sr = suma / czas.Length;
- for (int i = 0; i < czas.Length; i++)
- {
- wariacja += (czas[i] - sr) * (czas[i] - sr);
- }
- wariacja = wariacja / czas.Length;
- Console.WriteLine("Wariacja wynosi {0}", wariacja);
- }
- static void SredniKoszt(double[] cena)
- {
- double suma = 0, sr = 0;
- for (int i = 0; i < cena.Length; i++)
- {
- suma += cena[i];
- }
- sr = suma / cena.Length;
- Console.WriteLine("Średni koszt wypożyczenia filmu to: {0}", sr);
- }
- static void SzukajRez(string[] rezyser)
- {
- Console.Write("Podaj nazwisko: ");
- string nazw;
- nazw = Console.ReadLine();
- for (int i = 0; i < rezyser.Length; i++)
- {
- if (rezyser[i] == nazw)
- {
- Console.WriteLine("Odnaleziono element " + nazw + " pod indeksem " + i);
- }
- }
- }
- static void SzukajFi(string[] produkt)
- {
- Console.Write("Podaj tytuł: ");
- string nazw;
- nazw = Console.ReadLine();
- for (int i = 0; i < produkt.Length; i++)
- {
- if (produkt[i] == nazw)
- {
- Console.WriteLine("Odnaleziono element " + nazw + " pod indeksem " + i);
- }
- }
- }
- static void KrotszyOd(int[] czas)
- {
- Console.Write("Wprowadź liczbę: ");
- int ew;
- ew = Convert.ToInt32(Console.ReadLine());
- for (int i = 0; i<czas.Length;i++)
- {
- if (ew>czas[i])
- {
- Console.WriteLine("Odnaleziono element pod indeksem " + i);
- }
- }
- }
- static void DluzszyOd(int[] czas)
- {
- Console.Write("Wprowadź liczbę: ");
- int ew;
- ew = Convert.ToInt32(Console.ReadLine());
- for (int i = 0; i < czas.Length; i++)
- {
- if (ew < czas[i])
- {
- Console.WriteLine("Odnaleziono element pod indeksem " + i);
- }
- }
- }
- }
- }