Otóż muszę napisać taki oto konwerter używając wcześniej napisanego kodu:
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
int Roman2Arabic(string Roman)
{
int Number = 0;
for(int i = 0; i <= 24; i++)
{
if(Roman[i] == 'I' && Roman[i+1] == 'V')
{
Number+=4;
i++;
}
else if(Roman[i] == 'I' && Roman[i+1] == 'X')
{
Number+=9;
i++;
}
else if(Roman[i] == 'X' && Roman[i+1] == 'L')
{
Number+=40;
i++;
}
else if(Roman[i] == 'X' && Roman[i+1] == 'C')
{
Number+=90;
i++;
}
else if(Roman[i] == 'C' && Roman[i+1] == 'D')
{
Number+=400;
i++;
}
else if(Roman[i] == 'C' && Roman[i+1] == 'M')
{
Number+=900;
i++;
}
else if(Roman[i] == 'I')
{
Number++;
}
else if(Roman[i] == 'V')
{
Number+=5;
}
else if(Roman[i] == 'X')
{
Number+=10;
}
else if(Roman[i] == 'L')
{
Number+=50;
}
else if(Roman[i] == 'C')
{
Number+=100;
}
else if(Roman[i] == 'D')
{
Number+=500;
}
else if(Roman[i] == 'M')
{
Number+=1000;
}
else if(!(Roman[i]))
{
break;
}
}
return Number;
}
int main(int argc, char *argv[])
{
string Roman;
cout<<"Podaj rzymska liczbe: ";
cin>>Roman;
cout<<"Jest to arabska liczba: "
<<Roman2Arabic(Roman);
system("PAUSE");
return EXIT_SUCCESS;
}
Napisać to samo tylko że z użyciem klas. Moja klasa wygląda tak:
class Roman2Arabic
{
private:
string Roman; // Liczba rzymska
string Number; // Liczba arabska
public:
void read ()
{
cout<<"Podaj liczbe Rzymska: ";
cin>>Roman;
}
void write ()
{
cout<<"Podana liczba jako arabska liczba to: "
<<Roman2Arabic(Roman);
}
Następnie mam
int Roman2Arabic(string Roman)
I dalej mam pętle.
Proszę o "wyjaśnienie" mi zasady "zbudowania" tej klasy i wskazanie jak poprawnie umieścić pętlę i wskazywanie wyniku aby program działał poprawnie, gdyż z przykładowych programów (każdy jest inaczej skonstruowany) niczego nie mogę wywnioskować.
Pozdrawiam