Question: This is my question Write a program that converts a number entered in Roman numerals to a positive integer. Your program should consist of a
This is my question
Write a program that converts a number entered in Roman numerals to a positive integer. Your program should consist of a class, say, romanType. An object of type romanType should do the following:
Store the number as a Roman numeral.
Convert and store the number as a positive integer.
Print the number as a Roman numeral or positive integer as requested by the user. The integer values of the Roman numerals are: M 1000 D 500 C 100 L 50 X 10 V 5 I 1
Test your program using the following Roman numerals: MCXIV, CCCLIX, and MDCLXVI.
This is my Code:
#include
using namespace std;
class romanType
{
public:
void print(char[]);
void set(char*);
private:
string romanInt[7];
};
void romanType::print(char Romannumeral[8])
{
char romanInt[7]={'M','D','C','L','X','V','I'};
int equivalentValue[7]={1000,500,100,50,10,5,1};
int length=0,x=0,y=0,total=0;
int value[10];
for(int x=0;x<=7;x++)
{
if(Romannumeral[x]!='\0')
{
length++;
}
else
{
x=7;
}
}
for(int x=0;x { for(int y=0;y<7;y++) { if(Romannumeral[x]==romanInt[y]) { value[x]=equivalentValue[y]; break; } } } for(int x=0;x { if(value[x] total+=value[x+1]-value[x]; else total+=value[x]; } cout<<"Equivalent Value is:"< } void romanType::set(char *romanNumber) { int i; for(i=0;i<8;i++) romanNumber[i]=toupper(romanNumber[i]); print(romanNumber); } int main() { romanType rome; char romanNumber[8]; cout<<"Enter a roman number which you want to convert: "; gets(romanNumber); rome.set(romanNumber); system("pause"); return 0; } This is my errors: Test Contents What am I missing?/root/sandbox184c0bd3/codevolve-test-7a38d1cb.cpp: In member function virtual void Roman_1_Test::TestBody(): /root/sandbox184c0bd3/codevolve-test-7a38d1cb.cpp:5:3: error: romanType was not declared in this scope romanType roman; ^ /root/sandbox184c0bd3/codevolve-test-7a38d1cb.cpp:7:5: error: roman was not declared in this scope roman.setRoman("CXIIV"); ^ /root/sandbox184c0bd3/codevolve-test-7a38d1cb.cpp:9:5: error: cout was not declared in this scope cout << "The equivalent of the Roman numeral " ^ /root/sandbox184c0bd3/codevolve-test-7a38d1cb.cpp:9:5: note: suggested alternative: In file included from /usr/include/gtest/internal/gtest-port.h:211:0, from /usr/include/gtest/internal/gtest-internal.h:40, from /usr/include/gtest/gtest.h:58, from /root/sandbox184c0bd3/codevolve-test-7a38d1cb.cpp:1: /usr/include/c++/5/iostream:61:18: note: std::cout extern ostream cout; /// Linked to standard output ^ /root/sandbox184c0bd3/codevolve-test-7a38d1cb.cpp:12:13: error: endl was not declared in this scope cout << endl; ^ /root/sandbox184c0bd3/codevolve-test-7a38d1cb.cpp:12:13: note: suggested alternative: In file included from /usr/include/gtest/gtest.h:55:0, from /root/sandbox184c0bd3/codevolve-test-7a38d1cb.cpp:1: /usr/include/c++/5/ostream:590:5: note: std::endl endl(basic_ostream<_CharT, _Traits>& __os) ^ make[2]: *** [CMakeFiles/runTests.dir/codevolve-test-7a38d1cb.cpp.o] Error 1 make[1]: *** [CMakeFiles/runTests.dir/all] Error 2 make: *** [all] Error 2 TEST(Roman, 1) { testing::internal::CaptureStdout(); romanType roman; roman.setRoman("CXIIV"); cout << "The equivalent of the Roman numeral " << "CXIIV" << " is "; roman.printPositiveInteger(); cout << endl; roman.setRoman("IIIVX"); cout << "The equivalent of the Roman numeral " << "IIIVX" << " is "; roman.printPositiveInteger(); cout << endl; roman.setRoman("MMXVII"); cout << "The equivalent of the Roman numeral " << "MMXVII" << " is "; roman.printPositiveInteger(); cout << endl; std::string output = testing::internal::GetCapturedStdout(); ASSERT_EQ(output, "The equivalent of the Roman numeral CXIIV is 115 The equivalent of the Roman numeral IIIVX is 6 The equivalent of the Roman numeral MMXVII is 2017 "); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
