Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @file Program.cs
- * @brief Program na převod arabských čísel na římské
- *@author Jakub Beneš, Jakub Anděl, Tomáš Guzma
- * @ Program převádí celé arabské číslo na římské
- */
- using System;
- using System.Collections.Generic;
- namespace RimskeCislice
- {
- class Program
- {
- class Riman
- {
- public List<string> cislaRimska = new List<string>();
- public int M;
- public int D;
- public int C;
- public int L;
- public int X;
- public int V;
- public int I;
- public int cislo;
- public Riman(int M, int D, int C, int L, int X, int V, int I)
- {
- this.M = M;
- this.D = D;
- this.C = C;
- this.L = L;
- this.X = X;
- this.V = V;
- this.I = I;
- }
- public int Tisice()
- {
- this.M = this.cislo / 1000;
- for (int i = 0; i < this.M; i++)
- {
- cislaRimska.Add("M");
- }
- return this.D;
- }
- public int Petset()
- {
- this.D = this.cislo / 500;
- for (int i = 0; i < this.D; i++)
- {
- cislaRimska.Add("D");
- }
- return this.D;
- }
- public int Sto()
- {
- this.C = this.cislo / 100;
- for (int i = 0; i< this.C; i++)
- {
- if (this.C != 4)
- {
- cislaRimska.Add("C");
- }
- else if (this.C == 4 && this.D == 1) ///x900
- {
- this.C = this.C - 4;
- cislaRimska.Remove("D");
- cislaRimska.Add("CM");
- }
- else if (this.C == 4 && this.D == 0) ///x400
- {
- this.C = this.C - 4;
- cislaRimska.Add("CD");
- }
- }
- return this.C;
- }
- public int Padesat()
- {
- this.L = this.cislo / 50;
- for (int i = 0; i < this.L; i++)
- {
- cislaRimska.Add("L");
- }
- return this.L;
- }
- public int Deset()
- {
- this.X = this.cislo / 10;
- ///for cyklus pro 10 a vyjímky
- for (int i = 0; i < this.X; i++)
- {
- if (this.X != 4)
- {
- cislaRimska.Add("X");
- }
- else if (this.X == 4 && this.L == 1)
- {
- this.X = this.X - 4;
- cislaRimska.Remove("L");
- cislaRimska.Add("XC"); ///x90
- }
- else if (this.X == 4 && this.L == 0)
- {
- this.X = this.X - 4;
- cislaRimska.Add("XL"); ///x40
- }
- }
- return this.X;
- }
- public int Pet()
- {
- this.V = cislo / 5;
- ///for cyklus pro 5
- for (int i = 0; i < this.V; i++)
- {
- cislaRimska.Add("V");
- }
- return this.V;
- }
- public int Jednotky()
- {
- this.I = this.cislo / 1;
- ///For cyklus pro 1 a vyjímky
- for (int i = 0; i < this.I; i++)
- {
- if (this.I != 4)
- {
- cislaRimska.Add("I");
- }
- else if (this.I == 4 && this.V != 1)
- {
- this.I = this.I - 4; ///když I=4, pak IV=4
- cislaRimska.Add("IV");
- }
- else if (this.I == 4 && this.V == 1) ///když I = 4, tak V=1 tak IX=9
- {
- this.I = this.I - 4;
- cislaRimska.Remove("V");
- cislaRimska.Add("IX");
- }
- }
- return this.I;
- }
- }
- static void Main(string[] args)
- {
- Riman r = new Riman(0, 0, 0, 0, 0, 0, 0);
- ///načítání dat s ošetřením chybného vstupu
- while (true)
- {
- try
- {
- Console.WriteLine("Zadej číslo: ");
- r.cislo = Convert.ToInt32(Console.ReadLine());
- break;
- }
- catch
- {
- Console.WriteLine("Špatně zadané číslo.");
- }
- }
- r.Tisice();
- r.cislo = r.cislo % 1000;
- r.Petset();
- r.cislo = r.cislo % 500;
- r.Sto();
- r.cislo = r.cislo % 100;
- r.Padesat();
- r.cislo = r.cislo % 50;
- r.Deset();
- r.cislo = r.cislo % 10;
- r.Pet();
- r.cislo = r.cislo % 5;
- r.Jednotky();
- r.cislo = r.cislo % 1;
- Console.WriteLine(string.Join("", r.cislaRimska));
- Console.WriteLine("Stiskněte Enter pro ukončení");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement