Advertisement
Xsufu

Классы С# №1

Sep 6th, 2020 (edited)
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.54 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _1 {
  4.  
  5.     class tovar {
  6.         string art;    //артикуль
  7.         string name;   //наименование
  8.         decimal cost;  //цена
  9.         byte nds;      //НДС
  10.         int count;     //счётчик объектов
  11.  
  12.         public tovar() {
  13.             count++;
  14.             art = " ";
  15.             name = " ";
  16.             cost = 0;
  17.             nds = 20;
  18.         }
  19.  
  20.         public void input() {  //заполнение объекта
  21.             Console.Write("Введите наименование продукта: ");
  22.             name = Console.ReadLine();
  23.             Console.Write("Артикул: ");
  24.             art = Console.ReadLine();
  25.             Console.Write("Цена за товар: ");
  26.             cost = Convert.ToDecimal(Console.ReadLine());
  27.             Console.Write("НДС: ");
  28.             nds = Convert.ToByte(Console.ReadLine());
  29.         }
  30.  
  31.         public void print() {  //печать объекта
  32.             Console.WriteLine($"Наименование продукта: {name}");
  33.             Console.WriteLine($"Артикуль: {art}");
  34.             Console.WriteLine($"Цена товара: {cost}");
  35.             Console.WriteLine($"НДС: {nds}%");
  36.         }
  37.        
  38.         //замена отдельного элемента объкта
  39.         public void setName(string name) => this.name = name;
  40.         public void serArt(string art) => this.art = art;
  41.         public void setCost(decimal cost) => this.cost = cost;
  42.         public void setNds(byte nds) => this.nds = nds;
  43.  
  44.         //установление всего
  45.         public void setAll(string name, string art, decimal cost, byte nds) {
  46.             this.name = name;
  47.             this.art = art;
  48.             this.cost = cost;
  49.             this.nds = nds;
  50.         }
  51.  
  52.         public string getName() {
  53.             return name;
  54.         }
  55.  
  56.         public string getArt() {
  57.             return art;
  58.         }
  59.  
  60.         public decimal getCost() {
  61.             return cost;
  62.         }
  63.  
  64.         public byte getNds() {
  65.             return nds;
  66.         }
  67.  
  68.         public decimal fullPrice() {  //цена с учётом НДС
  69.             cost = Convert.ToInt32(cost);
  70.             cost = cost + (cost * nds)/100;
  71.             return cost;
  72.         }
  73.  
  74.         public decimal sell(int sk) {  //цена с учётом НДС и скидки
  75.             decimal sellPrice;
  76.             sellPrice = fullPrice() - (sk * fullPrice() / 100);
  77.             return sellPrice;
  78.         }
  79.     }
  80.  
  81.     class Program {
  82.         static void Main(string[] args) {
  83.            
  84.             int n; //длина массива товаров
  85.             Console.Write("Введите количество товаров: ");
  86.             n = Convert.ToInt32(Console.ReadLine());
  87.             tovar[] tn = new tovar[n]; //массив товаров
  88.             for (int i = 0; i<n; i++) {    //считывание и вывод массива товаров
  89.                 tn[i] = new tovar();
  90.                 tn[i].input();
  91.                 tn[i].print();
  92.             }
  93.  
  94.             decimal max = 0;
  95.             foreach (var i in tn) {
  96.                 if (i.getCost() > max)
  97.                     max = i.getCost();
  98.             }
  99.             Console.WriteLine($"Цена самого дорогого товара: {max}");
  100.            
  101.  
  102.             tovar water = new tovar();
  103.             water.input();
  104.             Console.WriteLine($"Цена с цчётом НДС: {water.fullPrice()}");
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement