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;
- namespace Money
- {
- class Money
- {
- int rubles;//рубли
- int kopeks;//копейки
- int value;//вспомогательные копейки
- // свойства
- // Количество рублей
- public int Rubles
- { get { return value / 100; } }
- // Количество копеек
- public int Kopeks
- { get { return (int)(value % 100); } }
- public Money(double value)
- {
- this.value = (int)Math.Round(100 * value, 2);
- }
- public Money(int rubles, int kopeks)
- {
- if (kopeks < 0 || kopeks > 99)
- throw new ArgumentException();
- if (rubles >= 0)
- value = 100 * rubles + kopeks;
- else
- value = 100 * rubles - kopeks;
- }
- // Вспомогательный конструктор
- private Money(int kopeks)
- {
- this.value = kopeks;
- }
- public void Init() //инициализация
- {
- Console.WriteLine("Введите рубли");
- rubles = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Введите копейки");
- kopeks = Convert.ToInt32(Console.ReadLine());
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Money rub = new Money(100);
- Money kop = new Money(10);
- Console.WriteLine("У вас " + rub.Rubles + "руб. " + kop.Kopeks + "коп.");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement