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 Task1
- {
- class Program
- {
- static void Main(string[] args)
- {
- /*
- Товарный учет.
- в программу можно добавлять наименование товара, его количество и цену. Доступны следующие функции:
- 1) добавить товар.
- 2) вывести список
- 3) удалить товар
- 4) посчитать сумму (количество на цену единицы)
- 5) изменить цену или количество товара
- 6) найти товар
- */
- string command = " ";
- bool b = true;
- string[] arrayNames = new string[0];
- int[] arrayCount = new int[0];
- int[] arrayPrice = new int[0];
- int j = 0;
- while (b)
- {
- Console.WriteLine("Предприятие.Торговля + Склад.v1.0\nВам доступны следующие команды:\n\nдобавить - добавить товар" +
- "\nсписок - вывести список товаров;\nудалить - удалить товар;\nнайти - поиск по названиям" +
- "\nизменить - изменить количество товара или цену за ед.\nсумма - вывести сумму \nвыход - выход из программы\n");
- Console.WriteLine("Введите команду:");
- command = Console.ReadLine();
- switch (command.ToLower())
- {
- case "добавить":
- bool c = true;
- while (c == true)
- {
- j++;
- Console.Write("Напишите название товара: ");
- string good = Console.ReadLine();
- Console.Write("Напишите количество товара: ");
- int goodCount = Convert.ToInt32(Console.ReadLine());
- Console.Write("Напишите цену за единицу товара: ");
- int goodPrice = Convert.ToInt32(Console.ReadLine());
- AddGood(ref arrayNames, good, ref arrayCount, goodCount, ref arrayPrice, goodPrice, j);
- Console.WriteLine("Ваш товар добавлен.\nХотите продолжить заводить товар?(да/нет)");
- string answer = Console.ReadLine();
- switch (answer.ToLower())
- {
- case "да":
- break;
- case "нет":
- c = false;
- break;
- }
- }
- break;
- case "список":
- ListGoods(ref arrayNames, ref arrayCount, ref arrayPrice);
- break;
- case "удалить":
- Console.WriteLine("Напишите номер товара, которое хотите удалить: ");
- int number = Convert.ToInt32(Console.ReadLine());
- DeleteGood(ref arrayNames, ref arrayCount, ref arrayPrice, number);
- break;
- case "найти":
- Console.Write("введите название товара - ");
- string toFind = Console.ReadLine();
- FindGood(arrayNames, arrayCount, arrayPrice, toFind);
- break;
- case "сумма":
- SumMoney(ref arrayNames, ref arrayCount, ref arrayPrice);
- break;
- case "изменить":
- ListGoods(ref arrayNames, ref arrayCount, ref arrayPrice);
- Console.Write("введите номер товара, который хотите изменить:");
- int n = Convert.ToInt32(Console.ReadLine());
- Console.Write("Хотите изменить 1.количество товара или 2.цену за ед. товара?(1 или 2) - ");
- int toChange = Convert.ToInt32(Console.ReadLine());
- Console.Write("введите новую сумму - ");
- int newCount = Convert.ToInt32(Console.ReadLine());
- ChangeList(ref arrayNames, ref arrayCount, ref arrayPrice, n, toChange, newCount);
- break;
- case "выход":
- b = false;
- break;
- }
- Console.WriteLine("\nдля продолжения нажмите Enter");
- Console.ReadKey();
- Console.Clear();
- }
- }
- static void AddGood(ref string[] goodNames, string name, ref int[] goodCounts, int count, ref int[] goodPrices, int price, int j)
- {
- string[] tempNames = new string[goodNames.Length + 1];
- int[] tempCount = new int[goodCounts.Length + 1];
- int[] tempPrice= new int[goodCounts.Length + 1];
- for (int i = 0; i < tempNames.Length; i++)
- {
- if (j == 1)
- {
- tempNames[0] = name;
- tempCount[0] = count;
- tempPrice[0] = price;
- }
- else if (i < tempNames.Length - 1)
- {
- tempNames[i] = goodNames[i];
- tempCount[i] = goodCounts[i];
- tempPrice[i] = goodPrices[i];
- }
- else
- {
- tempNames[i] = name;
- tempCount[i] = count;
- tempPrice[i] = price;
- }
- }
- goodNames = new string[goodNames.Length + 1];
- goodCounts = new int[goodCounts.Length + 1];
- goodPrices = new int[goodPrices.Length + 1];
- for (int i = 0; i < tempNames.Length; i++)
- {
- goodNames[i] = tempNames[i];
- goodCounts[i] = tempCount[i];
- goodPrices[i] = tempPrice[i];
- }
- Console.WriteLine();
- }
- static void ListGoods(ref string[] goodNames, ref int[] goodCounts, ref int[] goodPrices)
- {
- Console.WriteLine("Список товаров:\nназвание - количество - цена за ед. (руб)");
- for (int i = 0; i < goodNames.Length; i++)
- {
- Console.WriteLine((i + 1) + ". " + goodNames[i] + " - " + goodCounts[i] + " - " + goodPrices[i]);
- }
- }
- static void DeleteGood(ref string[] goodNames, ref int[] goodCounts, ref int[] goodPrice, int n)
- {
- string[] tempNames = new string[goodNames.Length - 1];
- int[] tempCounts = new int[goodCounts.Length - 1];
- int[] tempPrices = new int[goodCounts.Length - 1];
- Console.WriteLine("вы удалили товар №" + n);
- Console.WriteLine("Список товаров:\nназвание - количество - цена за ед. (руб)");
- for (int i = 0; i < goodNames.Length; i++)
- {
- if (i + 1 < n)
- {
- tempNames[i] = goodNames[i];
- tempCounts[i] = goodCounts[i];
- tempPrices[i] = goodPrice[i];
- }
- else if (i + 1 > n)
- {
- tempNames[i - 1] = goodNames[i];
- tempCounts[i - 1] = goodCounts[i];
- tempPrices[i - 1] = goodPrice[i];
- }
- }
- goodNames = new string[goodNames.Length - 1];
- goodCounts = new int[goodCounts.Length - 1];
- goodPrice = new int[goodPrice.Length - 1];
- for (int i = 0; i < tempNames.Length; i++)
- {
- Console.WriteLine((i + 1) + ". " + tempNames[i] + " - " + tempCounts[i]);
- goodNames[i] = tempNames[i];
- goodCounts[i] = tempCounts[i];
- tempPrices[i] = tempPrices[i];
- }
- }
- static void SumMoney(ref string[] goodName, ref int[] goodCounts, ref int[] goodPrices)
- {
- Console.WriteLine("Товар - общая сумма за товар /n");
- int totalSum = 0;
- for(int i = 0; i < goodName.Length; i++)
- {
- int goodSum = goodCounts[i] * goodPrices[i];
- totalSum += goodSum;
- Console.WriteLine((i + 1) + ". " + goodName[i] + " - " + goodSum + " руб.");
- }
- Console.WriteLine("Всего товаров на сумму: " + totalSum + " руб.");
- }
- static void ChangeList(ref string[] goodNames, ref int[] goodCount, ref int[] goodPrice, int goodNumber, int toChange, int newCount)
- {
- for(int i = 0; i < goodNames.Length; i++)
- {
- if(i == goodNumber - 1 && toChange == 1)
- {
- goodCount[i] = newCount;
- Console.WriteLine("Товар изменен\n" + (i + 1) + ". " + goodNames[i] + " - " + goodCount[i] + " - " + goodPrice[i] + " руб.");
- } else if (i == goodNumber - 1 && toChange == 2)
- {
- goodPrice[i] = newCount;
- Console.WriteLine("Товар изменен\n" + (i + 1) + ". " + goodNames[i] + " - " + goodCount[i] + " - " + goodPrice[i] + " руб.");
- }
- }
- }
- static void FindGood(string[] goodNames, int[] goodCount, int[] goodPrice, string toFind)
- {
- Console.WriteLine("Товар, который вы искали: ");
- Console.WriteLine("название - количество - цена за ед. (руб)");
- for (int i = 0; i < goodNames.Length; i++)
- {
- if (goodNames[i] == toFind)
- {
- Console.WriteLine((i + 1) + ". " + goodNames[i] + " - " + goodCount[i] + " - " + goodPrice[i]);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement