Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.17 KB | None | 0 0
  1. #pragma once
  2. #include "RomaNumber.h"
  3. #include <string>
  4. #include <string.h>
  5. #include <stdio.h>
  6. #include <iostream>
  7. using namespace std;
  8. ////////////////////////////////////////////
  9.  
  10. RomaNumber::RomaNumber()
  11. {
  12.     normalne_cislo = 0;
  13.     rimske_cislo= '\0';
  14. }
  15.  
  16. RomaNumber::RomaNumber(char *in)
  17. {
  18.     normalne_cislo = doArab(in);
  19.     rimske_cislo = in;
  20. }
  21.  
  22.  
  23. const char* RomaNumber::doRoma(int c)
  24. {
  25.  
  26.     string a;
  27. if(c<0){
  28.     c = c*(-1);
  29.     a.append("-");
  30.     }
  31.  
  32. while (c >= 1000)
  33. {
  34.     a.append("M");
  35.     c -= 1000;
  36. }
  37. if (c >= 900)
  38. {
  39.     a.append("CM");
  40.     c -= 900;
  41. }
  42. if (c >= 500)
  43. {
  44.     a.append("D");
  45.     c -= 500;
  46. }
  47. if (c >= 400)
  48. {
  49.     a.append("CD");
  50.     c -= 400;
  51. }
  52. while (c >= 100)
  53. {
  54.     a.append("C");
  55.     c -= 100;
  56. }
  57. if (c >= 90)
  58. {
  59.     a.append("XC");
  60.     c -= 90;
  61. }
  62. if (c >= 50)
  63. {
  64.     a.append("L");
  65.     c -= 50;
  66. }
  67. if (c >= 40)
  68. {
  69.     a.append("XL");
  70.     c -= 40;
  71. }
  72. while (c >= 10)
  73. {
  74.     a.append("X");
  75.     c -= 10;
  76. }
  77. if (c >= 9)
  78. {
  79.     a.append("IX");
  80.     c -= 9;
  81. }
  82. if (c >= 5)
  83. {
  84.     a.append("V");
  85.     c -= 5;
  86. }
  87. if (c >= 4)
  88. {
  89.     a.append("IV");
  90.     c -= 4;
  91. }
  92. while (c >= 1)
  93. {
  94.     a.append("I");
  95.     c -= 1;
  96. }
  97.     const char *x  = a.c_str();
  98.     //printf("%s",x);
  99.     return x;
  100. }
  101.  
  102.  
  103.  
  104. int RomaNumber::doArab(const char *x){
  105.  
  106.  
  107.      int dlzka = strlen(x);
  108.      int cislo = 0;
  109.      int poc = 0;
  110.      int predSum = 0;
  111.      int sum = 0;
  112.      int posun =0;
  113.     if(x[0]== '-'){
  114.         posun++;
  115.  
  116.     }
  117.      for (poc = dlzka; poc >= posun; poc--)
  118.          {
  119.              if (x[poc] == 'M' || x[poc] == 'm')
  120.                  cislo = 1000;
  121.              else if (x[poc] == 'D' || x[poc] == 'd')
  122.                  cislo = 500;
  123.              else if (x[poc] == 'C' || x[poc] == 'c')
  124.                  cislo = 100;
  125.              else if (x[poc] == 'L' || x[poc] == 'l')
  126.                  cislo = 50;
  127.              else if (x[poc] == 'X' || x[poc] == 'x')
  128.                  cislo = 10;
  129.              else if (x[poc] == 'V' || x[poc] == 'v')
  130.                  cislo = 5;
  131.              else if (x[poc] == 'I' || x[poc] == 'i')
  132.                  cislo = 1;
  133.              else
  134.                  cislo = 0;
  135.  
  136.              if (predSum > cislo)
  137.                  sum = predSum - cislo;
  138.              else
  139.                  sum = sum + cislo;
  140.              predSum = cislo;
  141.         }
  142.     if(x[0]== '-'){
  143.         sum = sum*-1;
  144.  
  145.     }
  146.  
  147.     return sum;
  148.  
  149.  
  150. }
  151.  
  152. void RomaNumber::oprint(RomaNumber num)
  153. {
  154.  
  155.     //cout << num.doRoma(getValue(num));
  156.  
  157.  
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement