Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 22.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8.  
  9. namespace ConsoleApp1
  10. {
  11.     internal class Zaleczenie2019
  12.     {
  13.         private static void Poczatek()
  14.         {
  15.             Console.ForegroundColor = ConsoleColor.Cyan;
  16.             Console.Write("*** ***  Wyporzyczalnia filmow  *** ***\n");
  17.             Console.Write("Wykonal ");
  18.             Console.ForegroundColor = ConsoleColor.Red;
  19.             Console.Write("Nazwisko\n");
  20.             Console.ResetColor();
  21.             Console.Write("\n");
  22.         }
  23.  
  24.         private static void Menu()
  25.         {
  26.             Console.ForegroundColor = ConsoleColor.Cyan;
  27.             Console.Write("***************** MENU ************************ \n");
  28.             Console.ForegroundColor = ConsoleColor.Green;
  29.             Console.Write("\t m - wyswietli MENU;\n");
  30.             Console.Write("\t k - konczy program;\n");
  31.             Console.Write("\t c - oczysc console;\n");
  32.             Console.WriteLine("");
  33.             Console.WriteLine("\t w - wyswietli tabielu;");
  34.             Console.WriteLine("\trc - losowy czas trwania 100 - 200 1;");
  35.             Console.WriteLine("\tnk - najkrotszy film;");
  36.             Console.WriteLine("\tnd - najdluzszy film;");
  37.             Console.WriteLine("\t l - laczny czas trwania wszystkich filmow;");
  38.             Console.WriteLine("\tsc - sredni czas trwania filma;");
  39.             Console.WriteLine("\ts>= - szukaj filmu dluzsze oznaczenego czasu;");
  40.             Console.WriteLine("\t v - wariancja czasu trwania filma;");
  41.             Console.WriteLine("\tsk - sredni koszt wyporzuczania filma;");
  42.             Console.WriteLine("\tsr - szukaj rezysera;");
  43.             Console.WriteLine("\tsf - szukaj filmu;");
  44.             Console.WriteLine("\t z - zmien;");
  45.             Console.ForegroundColor = ConsoleColor.Cyan;
  46.             Console.Write("*********************************************** \n");
  47.             Console.Write("\n");
  48.             Console.ResetColor();
  49.         }
  50.  
  51.         private static string Wykonaj()
  52.         {
  53.             Console.ForegroundColor = ConsoleColor.Yellow;
  54.             Console.Write("Wykonaj:  ");
  55.             Console.ForegroundColor = ConsoleColor.Red;
  56.             string result = Console.ReadLine();
  57.             Console.ResetColor();
  58.             return result;
  59.         }
  60.  
  61.         private static void drukuj(string s, double[] tabCen)
  62.         {
  63.             string text = "------------";
  64.             Console.WriteLine(text + s + text);
  65.             for (int i = 0; i < tabCen.Length; i++)
  66.             {
  67.                 Console.WriteLine($"tab[{i}]={tabCen[i]}");
  68.             }
  69.             string text2 = text;
  70.             Console.WriteLine(text2 + text2 + text2);
  71.             Console.WriteLine();
  72.         }
  73.  
  74.         private static void minmax(double[] tabCenaZl, double[] mm)
  75.         {
  76.             mm[0] = tabCenaZl[0];
  77.             mm[1] = tabCenaZl[0];
  78.             for (int i = 1; i < tabCenaZl.Length; i++)
  79.             {
  80.                 if (mm[0] > tabCenaZl[i])
  81.                 {
  82.                     mm[0] = tabCenaZl[i];
  83.                 }
  84.                 if (mm[1] < tabCenaZl[i])
  85.                 {
  86.                     mm[1] = tabCenaZl[i];
  87.                 }
  88.             }
  89.         }
  90.  
  91.         private static void tabBTRUE(bool[] tabB)
  92.         {
  93.             for (int i = 0; i < tabB.Length; i++)
  94.             {
  95.                 tabB[i] = true;
  96.             }
  97.         }
  98.  
  99.         private static void sukaj(double liczba, double[] tabCasM, bool[] tabB)
  100.         {
  101.             int num = tabCasM.Length;
  102.             if (num != tabB.Length)
  103.             {
  104.                 Console.WriteLine("dane nie warigodne");
  105.                 if (num > tabB.Length)
  106.                 {
  107.                     num = tabB.Length;
  108.                 }
  109.             }
  110.             for (int i = 0; i < num; i++)
  111.             {
  112.                 if (liczba == tabCasM[i])
  113.                 {
  114.                     tabB[i] = true;
  115.                 }
  116.                 if (liczba != tabCasM[i])
  117.                 {
  118.                     tabB[i] = false;
  119.                 }
  120.             }
  121.         }
  122.  
  123.         private static void sukajM(double liczba, double[] tabCasM, bool[] tabB)
  124.         {
  125.             int num = tabCasM.Length;
  126.             if (num != tabB.Length)
  127.             {
  128.                 Console.WriteLine("dane nie warigodne");
  129.                 if (num > tabB.Length)
  130.                 {
  131.                     num = tabB.Length;
  132.                 }
  133.             }
  134.             for (int i = 0; i < num; i++)
  135.             {
  136.                 if (liczba <= tabCasM[i])
  137.                 {
  138.                     tabB[i] = true;
  139.                 }
  140.                 if (liczba > tabCasM[i])
  141.                 {
  142.                     tabB[i] = false;
  143.                 }
  144.             }
  145.         }
  146.  
  147.         private static void rand(Random rnd, double[] tabCasM)
  148.         {
  149.             for (int i = 0; i < tabCasM.Length; i++)
  150.             {
  151.                 tabCasM[i] = rnd.Next(100, 200);
  152.             }
  153.         }
  154.  
  155.         private static void sukaj(string liczba, string[] tabProdukt, bool[] tabB)
  156.         {
  157.             int num = tabProdukt.Length;
  158.             if (num != tabB.Length)
  159.             {
  160.                 Console.WriteLine("dane nie warigodne");
  161.                 if (num > tabB.Length)
  162.                 {
  163.                     num = tabB.Length;
  164.                 }
  165.             }
  166.             for (int i = 0; i < num; i++)
  167.             {
  168.                 if (liczba == tabProdukt[i])
  169.                 {
  170.                     tabB[i] = true;
  171.                 }
  172.                 if (liczba != tabProdukt[i])
  173.                 {
  174.                     tabB[i] = false;
  175.                 }
  176.             }
  177.         }
  178.  
  179.         private static void drukuj(string s, int[] tabCen)
  180.         {
  181.             string text = "------------";
  182.             Console.WriteLine(text + s + text);
  183.             for (int i = 0; i < tabCen.Length; i++)
  184.             {
  185.                 Console.WriteLine($"tab[{i}]={tabCen[i]}");
  186.             }
  187.             string text2 = text;
  188.             Console.WriteLine(text2 + text2 + text2);
  189.             Console.WriteLine();
  190.         }
  191.  
  192.         private static void drukuj(string s, string[] tabMarok)
  193.         {
  194.             string text = "------------";
  195.             Console.WriteLine(text + s + text);
  196.             for (int i = 0; i < tabMarok.Length; i++)
  197.             {
  198.                 Console.WriteLine($"tab[{i}]={tabMarok[i]}");
  199.             }
  200.             string text2 = text;
  201.             Console.WriteLine(text2 + text2 + text2);
  202.             Console.WriteLine();
  203.         }
  204.  
  205.         private static void drukuj(string[] tabProdukt, string[] tabRezyser, double[] tabCenaZl, double[] tabCasM, bool[] tabB, string s)
  206.         {
  207.             bool flag = true;
  208.             int num = tabProdukt.Length;
  209.             if (num != tabRezyser.Length)
  210.             {
  211.                 Console.WriteLine("dane nie warigodne");
  212.                 if (num > tabRezyser.Length)
  213.                 {
  214.                     num = tabRezyser.Length;
  215.                 }
  216.             }
  217.             if (num != tabCenaZl.Length)
  218.             {
  219.                 Console.WriteLine("dane nie warigodne");
  220.                 if (num > tabCenaZl.Length)
  221.                 {
  222.                     num = tabCenaZl.Length;
  223.                 }
  224.             }
  225.             if (num != tabCasM.Length)
  226.             {
  227.                 Console.WriteLine("dane nie warigodne");
  228.                 if (num > tabCasM.Length)
  229.                 {
  230.                     num = tabCasM.Length;
  231.                 }
  232.             }
  233.             if (num != tabB.Length)
  234.             {
  235.                 Console.WriteLine("dane nie warigodne");
  236.                 if (num > tabB.Length)
  237.                 {
  238.                     num = tabB.Length;
  239.                 }
  240.             }
  241.             string text = "Lp.";
  242.             string text2 = "    Produkt";
  243.             string text3 = "  Rezyser";
  244.             string text4 = "   Cena";
  245.             string text5 = "Czas";
  246.             string text6 = "   [ZPL]";
  247.             string text7 = "[min]";
  248.             string text8 = "";
  249.             Console.WriteLine("-----------------------------------------------------------");
  250.             Console.WriteLine("{0,-3} | {1,-15} | {2,-12} | {3,-10} | {4,-5} |", text, text2, text3, text4, text5);
  251.             Console.WriteLine("{0,-3} | {1,-15} | {2,-12} | {3,-10} | {4,-5} |", text8, text8, text8, text6, text7);
  252.             Console.WriteLine("-----------------------------------------------------------");
  253.             for (int i = 0; i < num; i++)
  254.             {
  255.                 if (tabB[i])
  256.                 {
  257.                     if (tabProdukt[i].Length > 13)
  258.                     {
  259.                         tabProdukt[i] = tabProdukt[i].Substring(0, 13);
  260.                     }
  261.                     if (tabRezyser[i].Length > 10)
  262.                     {
  263.                         tabRezyser[i] = tabRezyser[i].Substring(0, 10);
  264.                     }
  265.                     Console.WriteLine("{0,3} | {1,-15} | {2,-12} | {3,10:C2} | {4,5} |", i + 1, tabProdukt[i], tabRezyser[i], tabCenaZl[i], tabCasM[i]);
  266.                     flag = false;
  267.                 }
  268.             }
  269.             if (flag)
  270.             {
  271.                 Console.WriteLine($"BLAD {s}");
  272.             }
  273.             Console.WriteLine("-----------------------------------------------------------");
  274.             Console.WriteLine();
  275.         }
  276.  
  277.         private static void drukuj1(string[] tabProdukt, string[] tabRezyser, double[] tabCenaZl, double[] tabCasM, bool[] tabB, string s)
  278.         {
  279.             bool flag = true;
  280.             int num = tabProdukt.Length;
  281.             if (num != tabRezyser.Length)
  282.             {
  283.                 Console.WriteLine("dane nie warigodne");
  284.                 if (num > tabRezyser.Length)
  285.                 {
  286.                     num = tabRezyser.Length;
  287.                 }
  288.             }
  289.             if (num != tabCenaZl.Length)
  290.             {
  291.                 Console.WriteLine("dane nie warigodne");
  292.                 if (num > tabCenaZl.Length)
  293.                 {
  294.                     num = tabCenaZl.Length;
  295.                 }
  296.             }
  297.             if (num != tabCasM.Length)
  298.             {
  299.                 Console.WriteLine("dane nie warigodne");
  300.                 if (num > tabCasM.Length)
  301.                 {
  302.                     num = tabCasM.Length;
  303.                 }
  304.             }
  305.             if (num != tabB.Length)
  306.             {
  307.                 Console.WriteLine("dane nie warigodne");
  308.                 if (num > tabB.Length)
  309.                 {
  310.                     num = tabB.Length;
  311.                 }
  312.             }
  313.             string text = "Lp.";
  314.             string text2 = "    Produkt";
  315.             string text3 = "  Rezyser";
  316.             string text4 = "   Cena";
  317.             string text5 = "Czas";
  318.             string text6 = "   [ZPL]";
  319.             string text7 = "[min]";
  320.             string text8 = "";
  321.             Console.WriteLine("-----------------------------------------------------------");
  322.             Console.WriteLine("{0,-3} | {1,-15} | {3,-10} | {4,-5} | {2,-12} |", text, text2, text3, text4, text5);
  323.             Console.WriteLine("{0,-3} | {1,-15} | {3,-10} | {4,-5} | {2,-12} |", text8, text8, text8, text6, text7);
  324.             Console.WriteLine("-----------------------------------------------------------");
  325.             for (int i = 0; i < num; i++)
  326.             {
  327.                 if (tabB[i])
  328.                 {
  329.                     if (tabProdukt[i].Length > 13)
  330.                     {
  331.                         tabProdukt[i] = tabProdukt[i].Substring(0, 13);
  332.                     }
  333.                     if (tabRezyser[i].Length > 10)
  334.                     {
  335.                         tabRezyser[i] = tabRezyser[i].Substring(0, 10);
  336.                     }
  337.                     Console.WriteLine("{0,3} | {1,-15} | {3,10:C2} | {4,5} | {2,-12} |", i + 1, tabProdukt[i], tabRezyser[i], tabCenaZl[i], tabCasM[i]);
  338.                     flag = false;
  339.                 }
  340.             }
  341.             if (flag)
  342.             {
  343.                 Console.WriteLine($"BLAD {s}");
  344.             }
  345.             Console.WriteLine("-----------------------------------------------------------");
  346.             Console.WriteLine();
  347.         }
  348.  
  349.         private static double laczny(double[] tabCasM)
  350.         {
  351.             double num = 0.0;
  352.             int num2 = tabCasM.Length;
  353.             for (int i = 0; i < num2; i++)
  354.             {
  355.                 num += tabCasM[i];
  356.             }
  357.             return num;
  358.         }
  359.  
  360.         private static double sredni(double[] tabCasM)
  361.         {
  362.             double num = 0.0;
  363.             double num2 = 0.0;
  364.             int num3 = tabCasM.Length;
  365.             for (int i = 0; i < num3; i++)
  366.             {
  367.                 num += tabCasM[i];
  368.                 num2 += 1.0;
  369.             }
  370.             return num / num2;
  371.         }
  372.  
  373.         private static double wariancja(double[] tabCasM)
  374.         {
  375.             double num = 0.0;
  376.             double num2 = 0.0;
  377.             double num3 = 0.0;
  378.             int num4 = tabCasM.Length;
  379.             for (int i = 0; i < num4; i++)
  380.             {
  381.                 num += tabCasM[i];
  382.                 num2 += 1.0;
  383.             }
  384.             num3 = num / num2;
  385.             num = 0.0;
  386.             num2 = 0.0;
  387.             for (int j = 0; j < num4; j++)
  388.             {
  389.                 num += (tabCasM[j] - num3) * (tabCasM[j] - num3);
  390.                 num2 += 1.0;
  391.             }
  392.             return num / num2;
  393.         }
  394.  
  395.         private static void Main(string[] args)
  396.         {
  397.             Random rnd = new Random(1);
  398.             Poczatek();
  399.             bool flag = true;
  400.             Menu();
  401.             string[] array = new string[5]
  402.             {
  403.                 "Krzyzacy",
  404.                 "Pan Tadeusz",
  405.                 "Vabank",
  406.                 "Mis",
  407.                 "Seksmisija"
  408.             };
  409.             string[] array2 = new string[5]
  410.             {
  411.                 "Ford",
  412.                 "Wajda",
  413.                 "Machulski",
  414.                 "Bareja",
  415.                 "Machulski"
  416.             };
  417.             double[] array3 = new double[5]
  418.             {
  419.                 15.5,
  420.                 14.0,
  421.                 15.5,
  422.                 17.0,
  423.                 18.0
  424.             };
  425.             bool[] tabB = new bool[5]
  426.             {
  427.                 true,
  428.                 true,
  429.                 true,
  430.                 true,
  431.                 true
  432.             };
  433.             double[] array4 = new double[5]
  434.             {
  435.                 185.0,
  436.                 155.0,
  437.                 155.0,
  438.                 120.0,
  439.                 120.0
  440.             };
  441.             double[] array5 = new double[2];
  442.             do
  443.             {
  444.                 switch (Wykonaj())
  445.                 {
  446.                     case "m":
  447.                         Menu();
  448.                         break;
  449.                     case "k":
  450.                         flag = false;
  451.                         break;
  452.                     case "p":
  453.                         drukuj("Produkt (nazwe filmu)", array);
  454.                         break;
  455.                     case "r":
  456.                         drukuj("Rezyser", array2);
  457.                         break;
  458.                     case "zl":
  459.                         drukuj("Koszt wyporzuczania (zl)", array3);
  460.                         break;
  461.                     case "d":
  462.                         drukuj("Dlugosc filmu (minuty)", array4);
  463.                         break;
  464.                     case "rc":
  465.                         tabBTRUE(tabB);
  466.                         rand(rnd, array4);
  467.                         break;
  468.                     case "w":
  469.                         tabBTRUE(tabB);
  470.                         drukuj1(array, array2, array3, array4, tabB, "");
  471.                         break;
  472.                     case "nk":
  473.                         minmax(array4, array5);
  474.                         Console.WriteLine($"Najkrutszy film trwa {array5[0]} min");
  475.                         tabBTRUE(tabB);
  476.                         sukaj(array5[0], array4, tabB);
  477.                         Console.WriteLine("Najkrutszy filmy");
  478.                         drukuj1(array, array2, array3, array4, tabB, "BRAK");
  479.                         break;
  480.                     case "nd":
  481.                         minmax(array4, array5);
  482.                         Console.WriteLine($"Najdluzszy film trwa {array5[1]} min");
  483.                         tabBTRUE(tabB);
  484.                         sukaj(array5[1], array4, tabB);
  485.                         Console.WriteLine("Najdluzszy filmy");
  486.                         drukuj1(array, array2, array3, array4, tabB, "BRAK");
  487.                         break;
  488.                     case "l":
  489.                         Console.WriteLine($"Laczny czas trwania wszystkich filmow {laczny(array4)} min");
  490.                         break;
  491.                     case "sc":
  492.                         Console.WriteLine($"Sredni czas trwania filma {sredni(array4)} min");
  493.                         break;
  494.                     case "v":
  495.                         Console.WriteLine($"wariancja={wariancja(array4)}, odchylenie standardowe={Math.Sqrt(wariancja(array4)):0.00}  ");
  496.                         break;
  497.                     case "sk":
  498.                         Console.WriteLine($"Sredni koszt wyporzuczania filma {sredni(array3)} zl");
  499.                         break;
  500.                     case "sr":
  501.                         {
  502.                             Console.Write("Podaj nazwisko rezysera:  ");
  503.                             string text2 = Console.ReadLine();
  504.                             Console.WriteLine($"Szykamy filmy rezysera {text2}");
  505.                             tabBTRUE(tabB);
  506.                             sukaj(text2, array2, tabB);
  507.                             drukuj1(array, array2, array3, array4, tabB, "BRAK filmow rerzysera " + text2);
  508.                             break;
  509.                         }
  510.                     case "sf":
  511.                         {
  512.                             Console.Write("Podaj nazwe filmu:  ");
  513.                             string text = Console.ReadLine();
  514.                             Console.WriteLine($"Szykamy filmu {text}");
  515.                             tabBTRUE(tabB);
  516.                             sukaj(text, array, tabB);
  517.                             drukuj1(array, array2, array3, array4, tabB, "BRAK filmu " + text);
  518.                             break;
  519.                         }
  520.                     case "s>=":
  521.                         Console.Write("Podaj min czas trwania filmu:  ");
  522.                         if (!double.TryParse(Console.ReadLine(), out double result4))
  523.                         {
  524.                             Console.WriteLine("Bledna wartosc");
  525.                             break;
  526.                         }
  527.                         Console.WriteLine($"Szykamy filmu dluzszego (>=) {result4} min");
  528.                         tabBTRUE(tabB);
  529.                         sukajM(result4, array4, tabB);
  530.                         drukuj1(array, array2, array3, array4, tabB, "BRAK filmu dluzszego " + result4 + " minut");
  531.                         break;
  532.                     case "z":
  533.                         {
  534.                             Console.Write("Zmieniamy pozicje ");
  535.                             string s = Console.ReadLine();
  536.                             double result = 0.0;
  537.                             double result2 = 0.0;
  538.                             if (!int.TryParse(s, out int result3))
  539.                             {
  540.                                 Console.WriteLine("Bledna wartosc");
  541.                                 break;
  542.                             }
  543.                             if (result3 - 1 < 0)
  544.                             {
  545.                                 Console.WriteLine("Bledna wartosc");
  546.                                 break;
  547.                             }
  548.                             if (result3 - 1 >= array.Length)
  549.                             {
  550.                                 Console.WriteLine("Bledna wartosc");
  551.                                 break;
  552.                             }
  553.                             Console.Write("Produkt ");
  554.                             array[result3 - 1] = Console.ReadLine();
  555.                             Console.Write("Rezyser ");
  556.                             array2[result3 - 1] = Console.ReadLine();
  557.                             bool flag2 = true;
  558.                             bool flag3 = true;
  559.                             do
  560.                             {
  561.                                 if (!flag2)
  562.                                 {
  563.                                     Console.Write("Cena (liczba>=0) ");
  564.                                 }
  565.                                 if (flag2)
  566.                                 {
  567.                                     Console.Write("Cena ");
  568.                                     flag2 = false;
  569.                                 }
  570.                                 s = Console.ReadLine();
  571.                             }
  572.                             while (!double.TryParse(s, out result) | (result < 0.0));
  573.                             array3[result3 - 1] = result;
  574.                             do
  575.                             {
  576.                                 if (!flag3)
  577.                                 {
  578.                                     Console.Write("Czas (liczba>0) ");
  579.                                 }
  580.                                 if (flag3)
  581.                                 {
  582.                                     Console.Write("Czas ");
  583.                                     flag3 = false;
  584.                                 }
  585.                                 s = Console.ReadLine();
  586.                             }
  587.                             while (!double.TryParse(s, out result2) | (result2 <= 0.0));
  588.                             array4[result3 - 1] = result2;
  589.                             break;
  590.                         }
  591.                     case "c":
  592.                         Console.Clear();
  593.                         break;
  594.                     default:
  595.                         Console.WriteLine("-- BlÄ…d - element menu nie istneje --\n");
  596.                         break;
  597.                 }
  598.             }
  599.             while (flag);
  600.             Console.Write("Konec. Nacisni dowolny klawisz");
  601.             Console.ReadKey();
  602.         }
  603.     }
  604. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement