Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Autobazar
  9. {
  10. class Program
  11. {
  12. struct TBazar
  13. {
  14. public string vyrobce;
  15. public string model;
  16. public int rokVyroby;
  17. public string prevodovka;
  18. }
  19. static TBazar Add()
  20. {
  21. TBazar auto;
  22. Console.WriteLine("Zadejte vyrobce");
  23. auto.vyrobce = Console.ReadLine();
  24. Console.WriteLine("Zadejte model");
  25. auto.model = Console.ReadLine();
  26. Console.WriteLine("Zadej rok vyroby");
  27. auto.rokVyroby = int.Parse(Console.ReadLine());
  28. Console.WriteLine("Zadej typ prevodovky");
  29. auto.prevodovka = Console.ReadLine();
  30. return auto;
  31. }
  32.  
  33. static void vypisAuto(TBazar[] auta, int i)
  34. {
  35. Console.WriteLine("{0}\t {1}\t {2}\t {3}", auta[i].vyrobce, auta[i].model, auta[i].rokVyroby, auta[i].prevodovka);
  36. }
  37.  
  38. static TBazar[] Smazat(TBazar[] auta, int pocet, int i)
  39. {
  40. for (int y = i; y < pocet - 1; y++)
  41. {
  42. auta[y] = auta[y + 1];
  43. }
  44. return auta;
  45. }
  46. static void Smazat2(ref TBazar[] auta, int pocet, int i)
  47. {
  48. for (int y = i; y < pocet - 1; y++)
  49. {
  50. auta[y] = auta[y + 1];
  51. }
  52. }
  53.  
  54. static int Nacti(ref TBazar[] auta)
  55. {
  56. int pocet = 0;
  57. using (StreamReader sr = new StreamReader(@"soubor.txt"))
  58. {
  59. string radek;
  60. string[] pole = new string[4];
  61. while (!(sr.EndOfStream))
  62. {
  63. radek = sr.ReadLine();
  64. pole = radek.Split(';');
  65. auta[pocet].vyrobce = pole[0];
  66. auta[pocet].model = pole[1];
  67. auta[pocet].rokVyroby = int.Parse(pole[2]);
  68. auta[pocet].prevodovka = pole[3];
  69. pocet++;
  70. }
  71. return pocet;
  72. }
  73. }
  74. static void Uloz(TBazar[] auta, int pocet)
  75. {
  76. using (StreamWriter sw = new StreamWriter(@"soubor.txt"))
  77. {
  78. for (int i = 0; i < pocet; i++)
  79. {
  80. sw.WriteLine("{0}; {1}; {2}; {3}", auta[i].vyrobce, auta[i].model, auta[i].rokVyroby, auta[i].prevodovka);
  81. }
  82. sw.Flush();
  83. }
  84. }
  85.  
  86. static void Main(string[] args)
  87. {
  88. TBazar[] auta = new TBazar[1000];
  89. int pocet = 0, i;
  90. int cislo;
  91. do
  92. {
  93. Console.Clear();
  94. Console.WriteLine("Autobazar Speedy Cars, s. r. o.");
  95. Console.WriteLine("---------------------------------");
  96. Console.WriteLine("Pridat auto [1]");
  97. Console.WriteLine("Odstranit auto [2]");
  98. Console.WriteLine("Zatim nic [3]");
  99. Console.WriteLine("Ulozit do souboru [4]");
  100. Console.WriteLine("Vypsat auto [5]");
  101. Console.WriteLine("Nacist auta [6]");
  102. Console.WriteLine("Ukoncit program [0]");
  103. Console.Write("Vase volba: ");
  104. cislo = Console.ReadKey().KeyChar;
  105.  
  106. switch (cislo)
  107. {
  108. case '1':
  109. Console.Clear();
  110. Console.WriteLine("Autobazar Speedy Cars, s. r. o.");
  111. Console.WriteLine("---------------------------------");
  112. Console.WriteLine("Pridat auto");
  113. auta[pocet] = Add();
  114. pocet++;
  115. break;
  116. case '2':
  117. Console.Clear();
  118. Console.WriteLine("Autobazar Speedy Cars, s. r. o.");
  119. Console.WriteLine("---------------------------------");
  120. Console.WriteLine("Odstranit auto");
  121. Console.WriteLine("Zadejte index: ");
  122. i = int.Parse(Console.ReadLine());
  123. auta = Smazat(auta, pocet, i);
  124. pocet--;
  125. Console.ReadKey();
  126. break;
  127. case '3':
  128. Console.Clear();
  129. Console.WriteLine("Autobazar Speedy Cars, s. r. o.");
  130. Console.WriteLine("---------------------------------");
  131. Console.WriteLine("Zatim nic");
  132. Console.ReadKey();
  133. break;
  134. case '4':
  135. Console.Clear();
  136. Console.WriteLine("Autobazar Speedy Cars, s. r. o.");
  137. Console.WriteLine("---------------------------------");
  138. Console.WriteLine("Ulozit do souboru");
  139. Uloz(auta, pocet);
  140. Console.WriteLine("Ulozeno");
  141. Console.ReadKey();
  142. break;
  143. case '5':
  144. Console.Clear();
  145. Console.WriteLine("Autobazar Speedy Cars, s. r. o.");
  146. Console.WriteLine("---------------------------------");
  147. Console.WriteLine("Vypsat auto");
  148. for (int y = 0; y < pocet; y++)
  149. {
  150. vypisAuto(auta, y);
  151. }
  152. Console.ReadKey();
  153. break;
  154. case '6':
  155. Console.Clear();
  156. Console.WriteLine("Autobazar Speedy Cars, s. r. o.");
  157. Console.WriteLine("---------------------------------");
  158. Console.WriteLine("Nacist auta");
  159. pocet = Nacti(ref auta);
  160. Console.WriteLine("Hotovo");
  161. Console.ReadKey();
  162. break;
  163.  
  164. case '0':
  165. break;
  166.  
  167.  
  168. default:
  169. Console.Clear();
  170. Console.WriteLine("Spatna volba");
  171. Console.ReadKey();
  172. break;
  173. }
  174.  
  175. }
  176. while (cislo != '0');
  177. Console.WriteLine();
  178.  
  179.  
  180.  
  181. }
  182.  
  183.  
  184.  
  185. }
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement