Advertisement
Guest User

Římské čísla + třídy

a guest
Nov 19th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.71 KB | None | 0 0
  1. /**
  2.  * @file Program.cs
  3. * @brief Program na převod arabských čísel na římské
  4. *@author  Jakub Beneš, Jakub Anděl, Tomáš Guzma
  5. * @ Program převádí celé arabské číslo na římské
  6. */
  7.  
  8.  
  9. using System;
  10. using System.Collections.Generic;
  11.  
  12. namespace RimskeCislice
  13. {
  14.     class Program
  15.     {
  16.        
  17.         class Riman
  18.         {
  19.             public List<string> cislaRimska = new List<string>();
  20.             public int M;
  21.             public int D;
  22.             public int C;
  23.             public int L;
  24.             public int X;
  25.             public int V;
  26.             public int I;
  27.             public int cislo;
  28.  
  29.             public Riman(int M, int D, int C, int L, int X, int V, int I)
  30.             {
  31.                 this.M = M;
  32.                 this.D = D;
  33.                 this.C = C;
  34.                 this.L = L;
  35.                 this.X = X;
  36.                 this.V = V;
  37.                 this.I = I;
  38.             }
  39.             public int Tisice()
  40.             {
  41.                 this.M = this.cislo / 1000;
  42.                 for (int i = 0; i < this.M; i++)
  43.                 {
  44.                     cislaRimska.Add("M");
  45.                 }
  46.                 return this.D;
  47.             }
  48.             public int Petset()
  49.             {
  50.                 this.D = this.cislo / 500;
  51.                 for (int i = 0; i < this.D; i++)
  52.                 {
  53.                     cislaRimska.Add("D");
  54.                 }
  55.                 return this.D;
  56.             }
  57.             public int Sto()
  58.             {
  59.                 this.C = this.cislo / 100;
  60.                 for (int i = 0; i< this.C; i++)
  61.             {
  62.                 if (this.C != 4)
  63.                 {
  64.                     cislaRimska.Add("C");
  65.                 }
  66.                 else if (this.C == 4 && this.D == 1) ///x900
  67.                 {
  68.                     this.C = this.C - 4;
  69.                     cislaRimska.Remove("D");
  70.                     cislaRimska.Add("CM");
  71.                 }
  72.                 else if (this.C == 4 && this.D == 0) ///x400
  73.                 {
  74.                     this.C = this.C - 4;
  75.                     cislaRimska.Add("CD");
  76.                 }
  77.                 }
  78.                 return this.C;
  79.             }
  80.             public int Padesat()
  81.             {
  82.                 this.L = this.cislo / 50;
  83.                 for (int i = 0; i < this.L; i++)
  84.                 {
  85.                     cislaRimska.Add("L");
  86.                 }
  87.                 return this.L;
  88.             }
  89.             public int Deset()
  90.             {
  91.                 this.X = this.cislo / 10;
  92.                 ///for cyklus pro 10 a vyjímky
  93.                 for (int i = 0; i < this.X; i++)
  94.                 {
  95.                     if (this.X != 4)
  96.                     {
  97.                         cislaRimska.Add("X");
  98.                     }
  99.                     else if (this.X == 4 && this.L == 1)
  100.                     {
  101.                         this.X = this.X - 4;
  102.                         cislaRimska.Remove("L");
  103.                         cislaRimska.Add("XC");   ///x90
  104.                     }
  105.                     else if (this.X == 4 && this.L == 0)
  106.                     {
  107.                         this.X = this.X - 4;
  108.                         cislaRimska.Add("XL");  ///x40
  109.                     }
  110.                 }
  111.                 return this.X;
  112.             }
  113.             public int Pet()
  114.             {
  115.                 this.V = cislo / 5;
  116.                 ///for cyklus pro 5
  117.                 for (int i = 0; i < this.V; i++)
  118.                 {
  119.                     cislaRimska.Add("V");
  120.                 }
  121.                 return this.V;
  122.             }
  123.             public int Jednotky()
  124.             {
  125.                 this.I = this.cislo / 1;
  126.                 ///For cyklus pro 1 a vyjímky
  127.                 for (int i = 0; i < this.I; i++)
  128.                 {
  129.                     if (this.I != 4)
  130.                     {
  131.                         cislaRimska.Add("I");
  132.                     }
  133.                     else if (this.I == 4 && this.V != 1)
  134.                     {
  135.                         this.I = this.I - 4;              ///když I=4, pak IV=4
  136.                         cislaRimska.Add("IV");
  137.                     }
  138.                     else if (this.I == 4 && this.V == 1) ///když I = 4, tak V=1 tak IX=9
  139.                     {
  140.                         this.I = this.I - 4;
  141.                         cislaRimska.Remove("V");
  142.                         cislaRimska.Add("IX");
  143.  
  144.                     }
  145.  
  146.  
  147.                 }
  148.                 return this.I;
  149.             }
  150.         }
  151.         static void Main(string[] args)
  152.         {
  153.             Riman r = new Riman(0, 0, 0, 0, 0, 0, 0);
  154.  
  155.            
  156.             ///načítání dat s ošetřením chybného vstupu
  157.             while (true)
  158.             {
  159.                 try
  160.                 {
  161.                     Console.WriteLine("Zadej číslo: ");
  162.                     r.cislo = Convert.ToInt32(Console.ReadLine());
  163.                     break;
  164.                 }
  165.                 catch
  166.                 {
  167.                     Console.WriteLine("Špatně zadané číslo.");
  168.                 }
  169.             }
  170.  
  171.             r.Tisice();
  172.             r.cislo = r.cislo % 1000;
  173.             r.Petset();
  174.             r.cislo = r.cislo % 500;
  175.             r.Sto();
  176.             r.cislo = r.cislo % 100;
  177.             r.Padesat();
  178.             r.cislo = r.cislo % 50;
  179.             r.Deset();
  180.             r.cislo = r.cislo % 10;
  181.             r.Pet();
  182.             r.cislo = r.cislo % 5;
  183.             r.Jednotky();
  184.             r.cislo = r.cislo % 1;
  185.            
  186.  
  187.             Console.WriteLine(string.Join("", r.cislaRimska));
  188.             Console.WriteLine("Stiskněte Enter pro ukončení");
  189.             Console.ReadLine();
  190.         }
  191.     }
  192. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement