Question: romanType.h ---------------------------------------- #pragma once #include using std::string; class romanType { public : //constructors romanType(); romanType( const string& r); //accessors string getRoman() const ; //mutators void

 romanType.h ---------------------------------------- #pragma once #include using std::string; class romanType { public://constructors romanType(); romanType(const string& r); //accessors string getRoman() const; //mutators void setRoman(const

romanType.h

----------------------------------------

#pragma once

#include

using std::string;

class romanType

{

public:

//constructors

romanType();

romanType(const string& r);

//accessors

string getRoman() const;

//mutators

void setRoman(const string& r);

//custom methods

int romanToDecimal() const;

protected:

//shared custom methods

static const int n_atoms = 8;

static int indexToDecimalAtom(int index);

static int decimalAtomToIndex(int Decimal_atom);

static char indexToRomanAtom(int index);

static int romanAtomToIndex(char atom);

private:

//data

string roman;

romanType.cpp

----------------------------------------

#include "romanType.h"

//constructors

romanType::romanType()

{

roman = "I";

}

romanType::romanType(const string& new_roman)

{

setRoman(new_roman);

}

//accessors

string romanType::getRoman() const

{

return roman;

}

//mutators

void romanType::setRoman(const string& new_roman)

{

roman = new_roman;

}

//custom methods

int romanType::romanToDecimal() const

{

int decimal = 0;

int pos = roman.length() - 1;

int maximum = indexToDecimalAtom(romanAtomToIndex(roman[pos]));

decimal += maximum;

for (pos = pos - 1; pos >= 0; pos--)

{

int number = indexToDecimalAtom(romanAtomToIndex(roman[pos]));

if (number > maximum)

{

maximum = number;

decimal += maximum;

}

else if (number == maximum)

decimal += number;

else

decimal -= number;

}

return decimal;

}

int romanType::indexToDecimalAtom(int index)

{

int decimalAtom;

switch (index)

{

case 0:

decimalAtom = 0;

break;

case 1:

decimalAtom = 1;

break;

case 2:

decimalAtom = 5;

break;

case 3:

decimalAtom = 10;

break;

case 4:

decimalAtom = 50;

break;

case 5:

decimalAtom = 100;

break;

case 6:

decimalAtom = 500;

break;

case 7:

decimalAtom = 1000;

break;

default:

decimalAtom = 0;

}

return decimalAtom;

}

char romanType::indexToRomanAtom(int index)

{

char romanAtom;

switch (index)

{

case 0:

romanAtom = '\0';

break;

case 1:

romanAtom = 'I';

break;

case 2:

romanAtom = 'V';

break;

case 3:

romanAtom = 'X';

break;

case 4:

romanAtom = 'L';

break;

case 5:

romanAtom = 'C';

break;

case 6:

romanAtom = 'D';

break;

case 7:

romanAtom = 'M';

break;

default:

romanAtom = '\0';

}

return romanAtom;

}

int romanType::decimalAtomToIndex(int atom)

{

int index;

switch (atom)

{

case 0:

index = 0;

break;

case 1:

index = 1;

break;

case 5:

index = 2;

break;

case 10:

index = 3;

break;

case 50:

index = 4;

break;

case 100:

index = 5;

break;

case 500:

index = 6;

break;

case 1000:

index = 7;

break;

default:

index = 0;

}

return index;

}

int romanType::romanAtomToIndex(char atom)

{

int index;

switch (atom)

{

case '\0':

index = 0;

break;

case 'I':

index = 1;

break;

case 'V':

index = 2;

break;

case 'X':

index = 3;

break;

case 'L':

index = 4;

break;

case 'C':

index = 5;

break;

case 'D':

index = 6;

break;

case 'M':

index = 7;

break;

default:

index = 0;

}

return index;

}

};

main-3.cpp

----------------------------------------

#include

#include

#include

#include

#include

#include

#include "romanType.h"

using std::cout;

using std::ifstream;

using std::istringstream;

using std::ofstream;

using std::endl;

using std::string;

using std::system;

int main()

{

string roman_numbers_file_name = "roman_numbers.txt";

string decimal_numbers_file_name = "decimal_numbers.txt";

string roman;

romanType r;

ifstream spring(roman_numbers_file_name.c_str());

ofstream sink(decimal_numbers_file_name.c_str());

while (getline(spring, roman))

{

r.setRoman(roman);

sink

}

spring.close();

sink.close();

system("pause");

return 0;

}

roman_numbers.txt is provided to us, but too long to upload all of it.

-----------------------------------------

I II III IV V VI VII VIII IX X XI XII XIII XIV XV XVI XVII XVIII XIX XX XXI XXII XXIII XXIV XXV XXVI

romanType.h romanType.cpp main.cpp roman numbers.txt The file roman_numbers.txt, contains, in order, the roman numerals from I to MMMMCMXCIX. The program translates each roman number in the file to its decimal number. Add the following array definitions to romanType.h static const char roman_atoms[n_atoms); static const int decimal_atoms[n_atoms); Add the following array initializations to romanType.cpp const char romanType::roman_atoms[romanType::n_atoms] = {"\OTV.X"L)CD"M'}; const int romanType::decimal_atoms[romanType::n_atoms] = {0,1,5,10,50,100,500,1000); Replace all or almost all of the switch statements in romanType.cpp with statements that read array elements , write array elements, or search arrays. simple class rubric Criteria Ratings Pts class rubric 10 pts Full Marks O pts No Marks 1) the program solves the problem 2) the program uses constructors, destructors appropriately 3) the program uses mutators appropriately 4) the program uses accessors appropriately 5) the program uses custom methods appropriately 10 pts 1. Data is almost always private. 2. No error message in constructors. The proper way to handle errors in constructors is to throw exceptions. Since we cannot throw exceptions, we replace bad values with good ones. 3. Avoid the "this" pointer. You can avoid it by using parameter names and local variable names that are not the same as class member names. 4. Constructors and mutators should not be interactive

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!