Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.76 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. namespace Task1
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. /*
  14. Товарный учет.
  15. в программу можно добавлять наименование товара, его количество и цену. Доступны следующие функции:
  16. 1) добавить товар.
  17. 2) вывести список
  18. 3) удалить товар
  19. 4) посчитать сумму (количество на цену единицы)
  20. 5) изменить цену или количество товара
  21. 6) найти товар
  22. */
  23. string command = " ";
  24. bool b = true;
  25. string[] arrayNames = new string[0];
  26. int[] arrayCount = new int[0];
  27. int[] arrayPrice = new int[0];
  28. int j = 0;
  29. while (b)
  30. {
  31. Console.WriteLine("Предприятие.Торговля + Склад.v1.0\nВам доступны следующие команды:\n\nдобавить - добавить товар" +
  32. "\nсписок - вывести список товаров;\nудалить - удалить товар;\nнайти - поиск по названиям" +
  33. "\nизменить - изменить количество товара или цену за ед.\nсумма - вывести сумму \nвыход - выход из программы\n");
  34. Console.WriteLine("Введите команду:");
  35. command = Console.ReadLine();
  36.  
  37. switch (command.ToLower())
  38. {
  39. case "добавить":
  40. bool c = true;
  41. while (c == true)
  42. {
  43. j++;
  44. Console.Write("Напишите название товара: ");
  45. string good = Console.ReadLine();
  46. Console.Write("Напишите количество товара: ");
  47. int goodCount = Convert.ToInt32(Console.ReadLine());
  48. Console.Write("Напишите цену за единицу товара: ");
  49. int goodPrice = Convert.ToInt32(Console.ReadLine());
  50. AddGood(ref arrayNames, good, ref arrayCount, goodCount, ref arrayPrice, goodPrice, j);
  51. Console.WriteLine("Ваш товар добавлен.\nХотите продолжить заводить товар?(да/нет)");
  52. string answer = Console.ReadLine();
  53. switch (answer.ToLower())
  54. {
  55. case "да":
  56. break;
  57. case "нет":
  58. c = false;
  59. break;
  60. }
  61. }
  62. break;
  63. case "список":
  64. ListGoods(ref arrayNames, ref arrayCount, ref arrayPrice);
  65. break;
  66. case "удалить":
  67. Console.WriteLine("Напишите номер товара, которое хотите удалить: ");
  68. int number = Convert.ToInt32(Console.ReadLine());
  69. DeleteGood(ref arrayNames, ref arrayCount, ref arrayPrice, number);
  70. break;
  71. case "найти":
  72. Console.Write("введите название товара - ");
  73. string toFind = Console.ReadLine();
  74. FindGood(arrayNames, arrayCount, arrayPrice, toFind);
  75. break;
  76. case "сумма":
  77. SumMoney(ref arrayNames, ref arrayCount, ref arrayPrice);
  78. break;
  79. case "изменить":
  80. ListGoods(ref arrayNames, ref arrayCount, ref arrayPrice);
  81. Console.Write("введите номер товара, который хотите изменить:");
  82. int n = Convert.ToInt32(Console.ReadLine());
  83. Console.Write("Хотите изменить 1.количество товара или 2.цену за ед. товара?(1 или 2) - ");
  84. int toChange = Convert.ToInt32(Console.ReadLine());
  85. Console.Write("введите новую сумму - ");
  86. int newCount = Convert.ToInt32(Console.ReadLine());
  87. ChangeList(ref arrayNames, ref arrayCount, ref arrayPrice, n, toChange, newCount);
  88. break;
  89. case "выход":
  90. b = false;
  91. break;
  92. }
  93. Console.WriteLine("\nдля продолжения нажмите Enter");
  94. Console.ReadKey();
  95. Console.Clear();
  96. }
  97. }
  98.  
  99. static void AddGood(ref string[] goodNames, string name, ref int[] goodCounts, int count, ref int[] goodPrices, int price, int j)
  100. {
  101. string[] tempNames = new string[goodNames.Length + 1];
  102. int[] tempCount = new int[goodCounts.Length + 1];
  103. int[] tempPrice= new int[goodCounts.Length + 1];
  104.  
  105. for (int i = 0; i < tempNames.Length; i++)
  106. {
  107. if (j == 1)
  108. {
  109. tempNames[0] = name;
  110. tempCount[0] = count;
  111. tempPrice[0] = price;
  112. }
  113. else if (i < tempNames.Length - 1)
  114. {
  115. tempNames[i] = goodNames[i];
  116. tempCount[i] = goodCounts[i];
  117. tempPrice[i] = goodPrices[i];
  118. }
  119. else
  120. {
  121. tempNames[i] = name;
  122. tempCount[i] = count;
  123. tempPrice[i] = price;
  124. }
  125. }
  126. goodNames = new string[goodNames.Length + 1];
  127. goodCounts = new int[goodCounts.Length + 1];
  128. goodPrices = new int[goodPrices.Length + 1];
  129.  
  130. for (int i = 0; i < tempNames.Length; i++)
  131. {
  132. goodNames[i] = tempNames[i];
  133. goodCounts[i] = tempCount[i];
  134. goodPrices[i] = tempPrice[i];
  135. }
  136. Console.WriteLine();
  137. }
  138.  
  139. static void ListGoods(ref string[] goodNames, ref int[] goodCounts, ref int[] goodPrices)
  140. {
  141. Console.WriteLine("Список товаров:\nназвание - количество - цена за ед. (руб)");
  142. for (int i = 0; i < goodNames.Length; i++)
  143. {
  144. Console.WriteLine((i + 1) + ". " + goodNames[i] + " - " + goodCounts[i] + " - " + goodPrices[i]);
  145. }
  146. }
  147. static void DeleteGood(ref string[] goodNames, ref int[] goodCounts, ref int[] goodPrice, int n)
  148. {
  149. string[] tempNames = new string[goodNames.Length - 1];
  150. int[] tempCounts = new int[goodCounts.Length - 1];
  151. int[] tempPrices = new int[goodCounts.Length - 1];
  152.  
  153. Console.WriteLine("вы удалили товар №" + n);
  154. Console.WriteLine("Список товаров:\nназвание - количество - цена за ед. (руб)");
  155. for (int i = 0; i < goodNames.Length; i++)
  156. {
  157.  
  158. if (i + 1 < n)
  159. {
  160. tempNames[i] = goodNames[i];
  161. tempCounts[i] = goodCounts[i];
  162. tempPrices[i] = goodPrice[i];
  163. }
  164. else if (i + 1 > n)
  165. {
  166. tempNames[i - 1] = goodNames[i];
  167. tempCounts[i - 1] = goodCounts[i];
  168. tempPrices[i - 1] = goodPrice[i];
  169. }
  170. }
  171. goodNames = new string[goodNames.Length - 1];
  172. goodCounts = new int[goodCounts.Length - 1];
  173. goodPrice = new int[goodPrice.Length - 1];
  174.  
  175. for (int i = 0; i < tempNames.Length; i++)
  176. {
  177. Console.WriteLine((i + 1) + ". " + tempNames[i] + " - " + tempCounts[i]);
  178. goodNames[i] = tempNames[i];
  179. goodCounts[i] = tempCounts[i];
  180. tempPrices[i] = tempPrices[i];
  181. }
  182. }
  183.  
  184. static void SumMoney(ref string[] goodName, ref int[] goodCounts, ref int[] goodPrices)
  185. {
  186. Console.WriteLine("Товар - общая сумма за товар /n");
  187. int totalSum = 0;
  188. for(int i = 0; i < goodName.Length; i++)
  189. {
  190. int goodSum = goodCounts[i] * goodPrices[i];
  191. totalSum += goodSum;
  192. Console.WriteLine((i + 1) + ". " + goodName[i] + " - " + goodSum + " руб.");
  193. }
  194. Console.WriteLine("Всего товаров на сумму: " + totalSum + " руб.");
  195. }
  196.  
  197. static void ChangeList(ref string[] goodNames, ref int[] goodCount, ref int[] goodPrice, int goodNumber, int toChange, int newCount)
  198. {
  199. for(int i = 0; i < goodNames.Length; i++)
  200. {
  201. if(i == goodNumber - 1 && toChange == 1)
  202. {
  203. goodCount[i] = newCount;
  204. Console.WriteLine("Товар изменен\n" + (i + 1) + ". " + goodNames[i] + " - " + goodCount[i] + " - " + goodPrice[i] + " руб.");
  205. } else if (i == goodNumber - 1 && toChange == 2)
  206. {
  207. goodPrice[i] = newCount;
  208. Console.WriteLine("Товар изменен\n" + (i + 1) + ". " + goodNames[i] + " - " + goodCount[i] + " - " + goodPrice[i] + " руб.");
  209. }
  210. }
  211. }
  212. static void FindGood(string[] goodNames, int[] goodCount, int[] goodPrice, string toFind)
  213. {
  214. Console.WriteLine("Товар, который вы искали: ");
  215. Console.WriteLine("название - количество - цена за ед. (руб)");
  216. for (int i = 0; i < goodNames.Length; i++)
  217. {
  218. if (goodNames[i] == toFind)
  219. {
  220. Console.WriteLine((i + 1) + ". " + goodNames[i] + " - " + goodCount[i] + " - " + goodPrice[i]);
  221. }
  222. }
  223. }
  224. }
  225. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement