Main
#include <iostream>
#include <cstring>
#include "RomanType.h"
using namespace std;
int main()
{
char str[SIZE];
int dec;
RomanType myrom;
cout << "Enter a number in roman form:";
cin >> str;
myrom.getrom(str);
myrom.print();
return 0;
}
RomanType.h
#ifndef ROMANTYPE_H
#define ROMANTYPE_H
const int SIZE = 15;
class RomanType
{
public:
void getrom(char str[]); // store roman number
int getnum(char str[]); //convert in decimal form and store it
void print() const;
RomanType();
RomanType(char str[]);
protected:
private:
char rom[SIZE];
int num;
};
#endif // ROMANTYPE_H
RomanType.cpp
#include "RomanType.h"
#include <cstring>
#include <iostream>
RomanType::RomanType()
{
rom[] = '\0'; //ctor
num = 0;
}
RomanType::RomanType(char str[])
{
strcpy(rom, str);
num = 0;
}
void RomanType::getrom(char str[])
{
strcpy(rom, str);
}
int RomanType::getnum(char str[])
{
for(int i=0, i<SIZE, i++)
{
switch (rom[i])
{
case 'M':
num =+ 1000;
break;
case 'D':
num =+ 500;
break;
case 'C':
num =+ 100;
break;
case 'L':
num =+ 50;
break;
case 'X':
num =+ 10;
break;
case 'V':
num =+ 5;
break;
case 'I':
num =+ 1;
break;
}
}
void RomanType::print() const
{
cout << num;
cout << rom
}
}