Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. struct Komputer
  2. {
  3. public double Cena;
  4. public string Marka;
  5. }
  6. class Program
  7. {
  8. const int N = 100;
  9. void Op_N(Komputer[] Tab, ref int ile)
  10. {
  11. string str;
  12. if (ile == N)
  13. {
  14. Console.WriteLine("Tablica pełna.");
  15. return;
  16. }
  17. Console.Write("\nPodaj markę komputera : "); Tab[ile].Marka = Console.ReadLine();
  18. Console.Write("\nPodaj cenę komputera : ");
  19. str = Console.ReadLine();
  20. Tab[ile++].Cena = double.Parse(str);
  21. }
  22. void Op_W(Komputer[] Tab, ref int ile)
  23. {
  24. int licz;
  25. for (licz = 0; licz < ile; ++licz)
  26. Console.WriteLine("{0}. M : {1}, C : {2}",
  27. licz, Tab[licz].Marka, Tab[licz].Cena);
  28. }
  29. void Op_U(Komputer[] Tab, ref int ile)
  30. {
  31. int licz;
  32. string str;
  33. Console.Write("\nPodaj numer komputera : ");
  34. str = Console.ReadLine();
  35. licz = int.Parse(str);
  36. if (licz < 0 || licz >= ile)
  37. {
  38. Console.WriteLine("Błędny numer komputera.");
  39. return;
  40. }
  41. Tab[licz] = Tab[ile-- - 1];
  42. }
  43. void Op_S(Komputer[] Tab, ref int ile)
  44. {
  45. int licz;
  46. double Suma = 0;
  47. for (licz = 0; licz < ile; ++licz)
  48. Suma += Tab[licz].Cena;
  49. Console.WriteLine("Suma cen wszystkich komputerów : {0}", Suma);
  50. }
  51. void Dzialanie()
  52. {
  53. Komputer[] TabKomp = new Komputer[N];
  54. int ile = 0;
  55. bool dalej = true;
  56. char opcja;
  57. string str;
  58. while (dalej)
  59. {
  60. Console.Write("\nWybierz opcję [N,W,U,S,Q] : ");
  61. str = Console.ReadLine();
  62. opcja = str[0];
  63. switch (opcja & 0x5F)
  64. {
  65. case 'N':
  66. Op_N(TabKomp, ref ile);
  67. break;
  68. case 'W':
  69. Op_W(TabKomp, ref ile);
  70. break;
  71. case 'U':
  72. Op_U(TabKomp, ref ile);
  73. break;
  74. case 'S':
  75. Op_S(TabKomp, ref ile);
  76. break;
  77. case 'Q':
  78. dalej = false;
  79. break;
  80. default:
  81. Console.WriteLine("Zła opcja");
  82. break;
  83. }
  84. }
  85. }
  86. static void Main(string[] args)
  87. {
  88. new Program().Dzialanie();
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement