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 ConsoleApp1
- {
- internal class Zaleczenie2019
- {
- private static void Poczatek()
- {
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.Write("*** *** Wyporzyczalnia filmow *** ***\n");
- Console.Write("Wykonal ");
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write("Nazwisko\n");
- Console.ResetColor();
- Console.Write("\n");
- }
- private static void Menu()
- {
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.Write("***************** MENU ************************ \n");
- Console.ForegroundColor = ConsoleColor.Green;
- Console.Write("\t m - wyswietli MENU;\n");
- Console.Write("\t k - konczy program;\n");
- Console.Write("\t c - oczysc console;\n");
- Console.WriteLine("");
- Console.WriteLine("\t w - wyswietli tabielu;");
- Console.WriteLine("\trc - losowy czas trwania 100 - 200 1;");
- Console.WriteLine("\tnk - najkrotszy film;");
- Console.WriteLine("\tnd - najdluzszy film;");
- Console.WriteLine("\t l - laczny czas trwania wszystkich filmow;");
- Console.WriteLine("\tsc - sredni czas trwania filma;");
- Console.WriteLine("\ts>= - szukaj filmu dluzsze oznaczenego czasu;");
- Console.WriteLine("\t v - wariancja czasu trwania filma;");
- Console.WriteLine("\tsk - sredni koszt wyporzuczania filma;");
- Console.WriteLine("\tsr - szukaj rezysera;");
- Console.WriteLine("\tsf - szukaj filmu;");
- Console.WriteLine("\t z - zmien;");
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.Write("*********************************************** \n");
- Console.Write("\n");
- Console.ResetColor();
- }
- private static string Wykonaj()
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.Write("Wykonaj: ");
- Console.ForegroundColor = ConsoleColor.Red;
- string result = Console.ReadLine();
- Console.ResetColor();
- return result;
- }
- private static void drukuj(string s, double[] tabCen)
- {
- string text = "------------";
- Console.WriteLine(text + s + text);
- for (int i = 0; i < tabCen.Length; i++)
- {
- Console.WriteLine($"tab[{i}]={tabCen[i]}");
- }
- string text2 = text;
- Console.WriteLine(text2 + text2 + text2);
- Console.WriteLine();
- }
- private static void minmax(double[] tabCenaZl, double[] mm)
- {
- mm[0] = tabCenaZl[0];
- mm[1] = tabCenaZl[0];
- for (int i = 1; i < tabCenaZl.Length; i++)
- {
- if (mm[0] > tabCenaZl[i])
- {
- mm[0] = tabCenaZl[i];
- }
- if (mm[1] < tabCenaZl[i])
- {
- mm[1] = tabCenaZl[i];
- }
- }
- }
- private static void tabBTRUE(bool[] tabB)
- {
- for (int i = 0; i < tabB.Length; i++)
- {
- tabB[i] = true;
- }
- }
- private static void sukaj(double liczba, double[] tabCasM, bool[] tabB)
- {
- int num = tabCasM.Length;
- if (num != tabB.Length)
- {
- Console.WriteLine("dane nie warigodne");
- if (num > tabB.Length)
- {
- num = tabB.Length;
- }
- }
- for (int i = 0; i < num; i++)
- {
- if (liczba == tabCasM[i])
- {
- tabB[i] = true;
- }
- if (liczba != tabCasM[i])
- {
- tabB[i] = false;
- }
- }
- }
- private static void sukajM(double liczba, double[] tabCasM, bool[] tabB)
- {
- int num = tabCasM.Length;
- if (num != tabB.Length)
- {
- Console.WriteLine("dane nie warigodne");
- if (num > tabB.Length)
- {
- num = tabB.Length;
- }
- }
- for (int i = 0; i < num; i++)
- {
- if (liczba <= tabCasM[i])
- {
- tabB[i] = true;
- }
- if (liczba > tabCasM[i])
- {
- tabB[i] = false;
- }
- }
- }
- private static void rand(Random rnd, double[] tabCasM)
- {
- for (int i = 0; i < tabCasM.Length; i++)
- {
- tabCasM[i] = rnd.Next(100, 200);
- }
- }
- private static void sukaj(string liczba, string[] tabProdukt, bool[] tabB)
- {
- int num = tabProdukt.Length;
- if (num != tabB.Length)
- {
- Console.WriteLine("dane nie warigodne");
- if (num > tabB.Length)
- {
- num = tabB.Length;
- }
- }
- for (int i = 0; i < num; i++)
- {
- if (liczba == tabProdukt[i])
- {
- tabB[i] = true;
- }
- if (liczba != tabProdukt[i])
- {
- tabB[i] = false;
- }
- }
- }
- private static void drukuj(string s, int[] tabCen)
- {
- string text = "------------";
- Console.WriteLine(text + s + text);
- for (int i = 0; i < tabCen.Length; i++)
- {
- Console.WriteLine($"tab[{i}]={tabCen[i]}");
- }
- string text2 = text;
- Console.WriteLine(text2 + text2 + text2);
- Console.WriteLine();
- }
- private static void drukuj(string s, string[] tabMarok)
- {
- string text = "------------";
- Console.WriteLine(text + s + text);
- for (int i = 0; i < tabMarok.Length; i++)
- {
- Console.WriteLine($"tab[{i}]={tabMarok[i]}");
- }
- string text2 = text;
- Console.WriteLine(text2 + text2 + text2);
- Console.WriteLine();
- }
- private static void drukuj(string[] tabProdukt, string[] tabRezyser, double[] tabCenaZl, double[] tabCasM, bool[] tabB, string s)
- {
- bool flag = true;
- int num = tabProdukt.Length;
- if (num != tabRezyser.Length)
- {
- Console.WriteLine("dane nie warigodne");
- if (num > tabRezyser.Length)
- {
- num = tabRezyser.Length;
- }
- }
- if (num != tabCenaZl.Length)
- {
- Console.WriteLine("dane nie warigodne");
- if (num > tabCenaZl.Length)
- {
- num = tabCenaZl.Length;
- }
- }
- if (num != tabCasM.Length)
- {
- Console.WriteLine("dane nie warigodne");
- if (num > tabCasM.Length)
- {
- num = tabCasM.Length;
- }
- }
- if (num != tabB.Length)
- {
- Console.WriteLine("dane nie warigodne");
- if (num > tabB.Length)
- {
- num = tabB.Length;
- }
- }
- string text = "Lp.";
- string text2 = " Produkt";
- string text3 = " Rezyser";
- string text4 = " Cena";
- string text5 = "Czas";
- string text6 = " [ZPL]";
- string text7 = "[min]";
- string text8 = "";
- Console.WriteLine("-----------------------------------------------------------");
- Console.WriteLine("{0,-3} | {1,-15} | {2,-12} | {3,-10} | {4,-5} |", text, text2, text3, text4, text5);
- Console.WriteLine("{0,-3} | {1,-15} | {2,-12} | {3,-10} | {4,-5} |", text8, text8, text8, text6, text7);
- Console.WriteLine("-----------------------------------------------------------");
- for (int i = 0; i < num; i++)
- {
- if (tabB[i])
- {
- if (tabProdukt[i].Length > 13)
- {
- tabProdukt[i] = tabProdukt[i].Substring(0, 13);
- }
- if (tabRezyser[i].Length > 10)
- {
- tabRezyser[i] = tabRezyser[i].Substring(0, 10);
- }
- Console.WriteLine("{0,3} | {1,-15} | {2,-12} | {3,10:C2} | {4,5} |", i + 1, tabProdukt[i], tabRezyser[i], tabCenaZl[i], tabCasM[i]);
- flag = false;
- }
- }
- if (flag)
- {
- Console.WriteLine($"BLAD {s}");
- }
- Console.WriteLine("-----------------------------------------------------------");
- Console.WriteLine();
- }
- private static void drukuj1(string[] tabProdukt, string[] tabRezyser, double[] tabCenaZl, double[] tabCasM, bool[] tabB, string s)
- {
- bool flag = true;
- int num = tabProdukt.Length;
- if (num != tabRezyser.Length)
- {
- Console.WriteLine("dane nie warigodne");
- if (num > tabRezyser.Length)
- {
- num = tabRezyser.Length;
- }
- }
- if (num != tabCenaZl.Length)
- {
- Console.WriteLine("dane nie warigodne");
- if (num > tabCenaZl.Length)
- {
- num = tabCenaZl.Length;
- }
- }
- if (num != tabCasM.Length)
- {
- Console.WriteLine("dane nie warigodne");
- if (num > tabCasM.Length)
- {
- num = tabCasM.Length;
- }
- }
- if (num != tabB.Length)
- {
- Console.WriteLine("dane nie warigodne");
- if (num > tabB.Length)
- {
- num = tabB.Length;
- }
- }
- string text = "Lp.";
- string text2 = " Produkt";
- string text3 = " Rezyser";
- string text4 = " Cena";
- string text5 = "Czas";
- string text6 = " [ZPL]";
- string text7 = "[min]";
- string text8 = "";
- Console.WriteLine("-----------------------------------------------------------");
- Console.WriteLine("{0,-3} | {1,-15} | {3,-10} | {4,-5} | {2,-12} |", text, text2, text3, text4, text5);
- Console.WriteLine("{0,-3} | {1,-15} | {3,-10} | {4,-5} | {2,-12} |", text8, text8, text8, text6, text7);
- Console.WriteLine("-----------------------------------------------------------");
- for (int i = 0; i < num; i++)
- {
- if (tabB[i])
- {
- if (tabProdukt[i].Length > 13)
- {
- tabProdukt[i] = tabProdukt[i].Substring(0, 13);
- }
- if (tabRezyser[i].Length > 10)
- {
- tabRezyser[i] = tabRezyser[i].Substring(0, 10);
- }
- Console.WriteLine("{0,3} | {1,-15} | {3,10:C2} | {4,5} | {2,-12} |", i + 1, tabProdukt[i], tabRezyser[i], tabCenaZl[i], tabCasM[i]);
- flag = false;
- }
- }
- if (flag)
- {
- Console.WriteLine($"BLAD {s}");
- }
- Console.WriteLine("-----------------------------------------------------------");
- Console.WriteLine();
- }
- private static double laczny(double[] tabCasM)
- {
- double num = 0.0;
- int num2 = tabCasM.Length;
- for (int i = 0; i < num2; i++)
- {
- num += tabCasM[i];
- }
- return num;
- }
- private static double sredni(double[] tabCasM)
- {
- double num = 0.0;
- double num2 = 0.0;
- int num3 = tabCasM.Length;
- for (int i = 0; i < num3; i++)
- {
- num += tabCasM[i];
- num2 += 1.0;
- }
- return num / num2;
- }
- private static double wariancja(double[] tabCasM)
- {
- double num = 0.0;
- double num2 = 0.0;
- double num3 = 0.0;
- int num4 = tabCasM.Length;
- for (int i = 0; i < num4; i++)
- {
- num += tabCasM[i];
- num2 += 1.0;
- }
- num3 = num / num2;
- num = 0.0;
- num2 = 0.0;
- for (int j = 0; j < num4; j++)
- {
- num += (tabCasM[j] - num3) * (tabCasM[j] - num3);
- num2 += 1.0;
- }
- return num / num2;
- }
- private static void Main(string[] args)
- {
- Random rnd = new Random(1);
- Poczatek();
- bool flag = true;
- Menu();
- string[] array = new string[5]
- {
- "Krzyzacy",
- "Pan Tadeusz",
- "Vabank",
- "Mis",
- "Seksmisija"
- };
- string[] array2 = new string[5]
- {
- "Ford",
- "Wajda",
- "Machulski",
- "Bareja",
- "Machulski"
- };
- double[] array3 = new double[5]
- {
- 15.5,
- 14.0,
- 15.5,
- 17.0,
- 18.0
- };
- bool[] tabB = new bool[5]
- {
- true,
- true,
- true,
- true,
- true
- };
- double[] array4 = new double[5]
- {
- 185.0,
- 155.0,
- 155.0,
- 120.0,
- 120.0
- };
- double[] array5 = new double[2];
- do
- {
- switch (Wykonaj())
- {
- case "m":
- Menu();
- break;
- case "k":
- flag = false;
- break;
- case "p":
- drukuj("Produkt (nazwe filmu)", array);
- break;
- case "r":
- drukuj("Rezyser", array2);
- break;
- case "zl":
- drukuj("Koszt wyporzuczania (zl)", array3);
- break;
- case "d":
- drukuj("Dlugosc filmu (minuty)", array4);
- break;
- case "rc":
- tabBTRUE(tabB);
- rand(rnd, array4);
- break;
- case "w":
- tabBTRUE(tabB);
- drukuj1(array, array2, array3, array4, tabB, "");
- break;
- case "nk":
- minmax(array4, array5);
- Console.WriteLine($"Najkrutszy film trwa {array5[0]} min");
- tabBTRUE(tabB);
- sukaj(array5[0], array4, tabB);
- Console.WriteLine("Najkrutszy filmy");
- drukuj1(array, array2, array3, array4, tabB, "BRAK");
- break;
- case "nd":
- minmax(array4, array5);
- Console.WriteLine($"Najdluzszy film trwa {array5[1]} min");
- tabBTRUE(tabB);
- sukaj(array5[1], array4, tabB);
- Console.WriteLine("Najdluzszy filmy");
- drukuj1(array, array2, array3, array4, tabB, "BRAK");
- break;
- case "l":
- Console.WriteLine($"Laczny czas trwania wszystkich filmow {laczny(array4)} min");
- break;
- case "sc":
- Console.WriteLine($"Sredni czas trwania filma {sredni(array4)} min");
- break;
- case "v":
- Console.WriteLine($"wariancja={wariancja(array4)}, odchylenie standardowe={Math.Sqrt(wariancja(array4)):0.00} ");
- break;
- case "sk":
- Console.WriteLine($"Sredni koszt wyporzuczania filma {sredni(array3)} zl");
- break;
- case "sr":
- {
- Console.Write("Podaj nazwisko rezysera: ");
- string text2 = Console.ReadLine();
- Console.WriteLine($"Szykamy filmy rezysera {text2}");
- tabBTRUE(tabB);
- sukaj(text2, array2, tabB);
- drukuj1(array, array2, array3, array4, tabB, "BRAK filmow rerzysera " + text2);
- break;
- }
- case "sf":
- {
- Console.Write("Podaj nazwe filmu: ");
- string text = Console.ReadLine();
- Console.WriteLine($"Szykamy filmu {text}");
- tabBTRUE(tabB);
- sukaj(text, array, tabB);
- drukuj1(array, array2, array3, array4, tabB, "BRAK filmu " + text);
- break;
- }
- case "s>=":
- Console.Write("Podaj min czas trwania filmu: ");
- if (!double.TryParse(Console.ReadLine(), out double result4))
- {
- Console.WriteLine("Bledna wartosc");
- break;
- }
- Console.WriteLine($"Szykamy filmu dluzszego (>=) {result4} min");
- tabBTRUE(tabB);
- sukajM(result4, array4, tabB);
- drukuj1(array, array2, array3, array4, tabB, "BRAK filmu dluzszego " + result4 + " minut");
- break;
- case "z":
- {
- Console.Write("Zmieniamy pozicje ");
- string s = Console.ReadLine();
- double result = 0.0;
- double result2 = 0.0;
- if (!int.TryParse(s, out int result3))
- {
- Console.WriteLine("Bledna wartosc");
- break;
- }
- if (result3 - 1 < 0)
- {
- Console.WriteLine("Bledna wartosc");
- break;
- }
- if (result3 - 1 >= array.Length)
- {
- Console.WriteLine("Bledna wartosc");
- break;
- }
- Console.Write("Produkt ");
- array[result3 - 1] = Console.ReadLine();
- Console.Write("Rezyser ");
- array2[result3 - 1] = Console.ReadLine();
- bool flag2 = true;
- bool flag3 = true;
- do
- {
- if (!flag2)
- {
- Console.Write("Cena (liczba>=0) ");
- }
- if (flag2)
- {
- Console.Write("Cena ");
- flag2 = false;
- }
- s = Console.ReadLine();
- }
- while (!double.TryParse(s, out result) | (result < 0.0));
- array3[result3 - 1] = result;
- do
- {
- if (!flag3)
- {
- Console.Write("Czas (liczba>0) ");
- }
- if (flag3)
- {
- Console.Write("Czas ");
- flag3 = false;
- }
- s = Console.ReadLine();
- }
- while (!double.TryParse(s, out result2) | (result2 <= 0.0));
- array4[result3 - 1] = result2;
- break;
- }
- case "c":
- Console.Clear();
- break;
- default:
- Console.WriteLine("-- BlÄ…d - element menu nie istneje --\n");
- break;
- }
- }
- while (flag);
- Console.Write("Konec. Nacisni dowolny klawisz");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement