Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "RomaNumber.h"
- #include <string>
- #include <string.h>
- #include <stdio.h>
- #include <iostream>
- using namespace std;
- ////////////////////////////////////////////
- RomaNumber::RomaNumber()
- {
- normalne_cislo = 0;
- rimske_cislo= '\0';
- }
- RomaNumber::RomaNumber(char *in)
- {
- normalne_cislo = doArab(in);
- rimske_cislo = in;
- }
- const char* RomaNumber::doRoma(int c)
- {
- string a;
- if(c<0){
- c = c*(-1);
- a.append("-");
- }
- while (c >= 1000)
- {
- a.append("M");
- c -= 1000;
- }
- if (c >= 900)
- {
- a.append("CM");
- c -= 900;
- }
- if (c >= 500)
- {
- a.append("D");
- c -= 500;
- }
- if (c >= 400)
- {
- a.append("CD");
- c -= 400;
- }
- while (c >= 100)
- {
- a.append("C");
- c -= 100;
- }
- if (c >= 90)
- {
- a.append("XC");
- c -= 90;
- }
- if (c >= 50)
- {
- a.append("L");
- c -= 50;
- }
- if (c >= 40)
- {
- a.append("XL");
- c -= 40;
- }
- while (c >= 10)
- {
- a.append("X");
- c -= 10;
- }
- if (c >= 9)
- {
- a.append("IX");
- c -= 9;
- }
- if (c >= 5)
- {
- a.append("V");
- c -= 5;
- }
- if (c >= 4)
- {
- a.append("IV");
- c -= 4;
- }
- while (c >= 1)
- {
- a.append("I");
- c -= 1;
- }
- const char *x = a.c_str();
- //printf("%s",x);
- return x;
- }
- int RomaNumber::doArab(const char *x){
- int dlzka = strlen(x);
- int cislo = 0;
- int poc = 0;
- int predSum = 0;
- int sum = 0;
- int posun =0;
- if(x[0]== '-'){
- posun++;
- }
- for (poc = dlzka; poc >= posun; poc--)
- {
- if (x[poc] == 'M' || x[poc] == 'm')
- cislo = 1000;
- else if (x[poc] == 'D' || x[poc] == 'd')
- cislo = 500;
- else if (x[poc] == 'C' || x[poc] == 'c')
- cislo = 100;
- else if (x[poc] == 'L' || x[poc] == 'l')
- cislo = 50;
- else if (x[poc] == 'X' || x[poc] == 'x')
- cislo = 10;
- else if (x[poc] == 'V' || x[poc] == 'v')
- cislo = 5;
- else if (x[poc] == 'I' || x[poc] == 'i')
- cislo = 1;
- else
- cislo = 0;
- if (predSum > cislo)
- sum = predSum - cislo;
- else
- sum = sum + cislo;
- predSum = cislo;
- }
- if(x[0]== '-'){
- sum = sum*-1;
- }
- return sum;
- }
- void RomaNumber::oprint(RomaNumber num)
- {
- //cout << num.doRoma(getValue(num));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement