Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Money
  7. {
  8.     class Money
  9.     {
  10.         int rubles;//рубли
  11.         int kopeks;//копейки
  12.         int value;//вспомогательные копейки
  13.  
  14.         // свойства
  15.         // Количество рублей
  16.         public int Rubles
  17.         { get { return value / 100; } }
  18.  
  19.         // Количество копеек
  20.         public int Kopeks
  21.         { get { return (int)(value % 100); } }
  22.  
  23.         public Money(double value)
  24.         {
  25.             this.value = (int)Math.Round(100 * value, 2);
  26.         }
  27.  
  28.         public Money(int rubles, int kopeks)
  29.         {
  30.             if (kopeks < 0 || kopeks > 99)
  31.                 throw new ArgumentException();
  32.             if (rubles >= 0)
  33.                 value = 100 * rubles + kopeks;
  34.             else
  35.                 value = 100 * rubles - kopeks;
  36.         }
  37.  
  38.         // Вспомогательный конструктор
  39.         private Money(int kopeks)
  40.         {
  41.             this.value = kopeks;
  42.         }
  43.  
  44.         public void Init() //инициализация
  45.         {
  46.             Console.WriteLine("Введите рубли");
  47.             rubles = Convert.ToInt32(Console.ReadLine());
  48.             Console.WriteLine("Введите копейки");
  49.             kopeks = Convert.ToInt32(Console.ReadLine());
  50.         }
  51.  
  52.     }
  53.     class Program
  54.     {
  55.         static void Main(string[] args)
  56.         {
  57.             Money rub = new Money(100);
  58.             Money kop = new Money(10);
  59.             Console.WriteLine("У вас " + rub.Rubles + "руб.  " + kop.Kopeks + "коп.");
  60.             Console.ReadLine();
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement