Write a class to represent Roman numerals. a. The class should have two constructors.: (1) A default constructor (2) A constructor that takes a string as a paramter (i.e., string representing a roman numeral) b. This class should have the following member functions, in addition to the above constructors: (1) set - sets the member variable to the values in the function parameter (2) print - print the converted integer value (3) convert the roman number string to a positive integer (4) print the roman number string c. This class should have two PRIVATE member variables: (1) string to hold the roman numeral string (2) integer to hold the converted value 3. Create: a. a class definition file (*.h) b. a class implementation file (*.cpp) c. a client program to test your class (*.cpp) d. a project for these code files 4. The client program should: a. create a roman numeral object using the default constructor b. convert the roman number to the integer equivalent c. output (cout) the roman number entered and the equivalent integer value d. create a roman numeral object using the overloaded constructor e. convert the roman number to the integer equivalent f. output (cout) the roman number entered and the equivalent integer value g. create an array of the roman class of size 3 h. read, from the console, three roman numerals into the array, in a loop i. convert each array component into the equivalent integer value, in a separate loop j. output (cout) the roman number entered and the equivalent integer value for each component of the array. May be in the conversion loop. For this program, enter only valid roman numerals that convert to integers less than or equal to 3999 Test with the values MCXIV, CCCLIX, MDCLXVI Continuing to get a compiling error for this code:  "fatal error: Roman.h: no such file or directory" // Chapter 10 Lab - Roman Numerals // Meredith Petersen // February 23 2020 // CSC 210 Spring 2020 using namespace std; int main() { class Roman{ // Returning value of Roman numeral public: int value(char r) { if (r == 'I') return 1; if (r == 'V') return 5; if (r == 'X') return 10; if (r == 'L') return 50; if (r == 'C') return 100; if (r == 'D') return 500; if (r == 'M') return 1000; return -1; } }; #include "Roman.h" using namespace std; class RomanImplementation{ private: string str; int convertedValue; void setConvertedValue(int convertedValue){ this->convertedValue=convertedValue; } public: RomanImplementation(){ } RomanImplementation(string str){ setStr(str); } void setStr(string str){ this->str=str; } void printValue(){ cout<<"Roman to integer is "<= s2) { // If the value of the current symbol is greater than or equal to the next symbol res = res + s1; } else { res = res + s2 - s1; i++; // If the value of the current symbol is less than the next symbol } } else { res = res + s1; i++; } } setConvertedValue(res); } }; roman_test.cpp #include "roman_implementation.cpp" // Main int main() { // Considering inputs given are valid cout<<"Create a roman numeral object using the default constructor\n"; RomanImplementation romanImplementation1; romanImplementation1.setStr("MCMLIII"); romanImplementation1.romanToInteger() ; romanImplementation1.printValue(); romanImplementation1.printRomanString(); cout<<"Create a roman numeral object using the overloaded constructor\n"; RomanImplementation romanImplementation2("MMMCCCIII"); romanImplementation2.romanToInteger() ; romanImplementation2.printValue(); romanImplementation2.printRomanString(); cout<<"Create an array of the roman class of size 3\nInput strings\n"; RomanImplementation romanImplementation3[3]; string str[3]; for(int i=0;i<3;i++){ cin>>str[i]; } for(int i=0;i<3;i++){ romanImplementation3[i].setStr(str[i]); romanImplementation3[i].romanToInteger() ; romanImplementation3[i].printValue(); romanImplementation3[i].printRomanString(); } return 0; }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter6: User-defined Functions
Section: Chapter Questions
Problem 33SA
icon
Related questions
Question

PLEASE HELP (AGAIN): Perhaps I am simply in the dark about how to use .h files. I have no file to add. These are the instructions: 

1. Write a class to represent Roman numerals.
a. The class should have two constructors.:
(1) A default constructor
(2) A constructor that takes a string as a paramter (i.e., string
representing a roman numeral)
b. This class should have the following member functions, in addition
to the above constructors:
(1) set - sets the member variable to the values in the function
parameter
(2) print - print the converted integer value
(3) convert the roman number string to a positive integer
(4) print the roman number string
c. This class should have two PRIVATE member variables:
(1) string to hold the roman numeral string
(2) integer to hold the converted value
3. Create:
a. a class definition file (*.h)
b. a class implementation file (*.cpp)
c. a client program to test your class (*.cpp)
d. a project for these code files
4. The client program should:
a. create a roman numeral object using the default constructor
b. convert the roman number to the integer equivalent
c. output (cout) the roman number entered and the equivalent integer
value
d. create a roman numeral object using the overloaded constructor
e. convert the roman number to the integer equivalent
f. output (cout) the roman number entered and the equivalent integer
value
g. create an array of the roman class of size 3
h. read, from the console, three roman numerals into the array, in a
loop
i. convert each array component into the equivalent integer value, in
a separate loop
j. output (cout) the roman number entered and the equivalent integer
value for each component of the array.
May be in the conversion loop.
For this program, enter only valid roman numerals that convert to integers
less than or equal to 3999
Test with the values MCXIV, CCCLIX, MDCLXVI



Continuing to get a compiling error for this code: 

"fatal error: Roman.h: no such file or directory"

// Chapter 10 Lab - Roman Numerals
// Meredith Petersen
// February 23 2020
// CSC 210 Spring 2020

using namespace std;

int main()
{
class Roman{


// Returning value of Roman numeral
public:
int value(char r)
{
if (r == 'I')
return 1;
if (r == 'V')
return 5;
if (r == 'X')
return 10;
if (r == 'L')
return 50;
if (r == 'C')
return 100;
if (r == 'D')
return 500;
if (r == 'M')
return 1000;

return -1;
}
};

#include "Roman.h"

using namespace std;
class RomanImplementation{

private:
string str;
int convertedValue;

void setConvertedValue(int convertedValue){
this->convertedValue=convertedValue;
}
public:
RomanImplementation(){
}
RomanImplementation(string str){
setStr(str);
}
void setStr(string str){
this->str=str;
}
void printValue(){
cout<<"Roman to integer is "<<convertedValue<<endl;
}
void printRomanString(){
cout<<"Roman string is "<<str<<endl;
}

void romanToInteger()
{
// Setting result
int res = 0;
Roman roman;

for (int i=0; i<str.length(); i++)
{

// Obtaining value of symbol s[i]
int s1 = roman.value(str[i]);

if (i+1 < str.length())

{
// Obtaining value of symbol s[i+1]
int s2 = roman.value(str[i+1]);

// Comparing both values
if (s1 >= s2)
{
// If the value of the current symbol is greater than or equal to the next symbol
res = res + s1;
}
else
{
res = res + s2 - s1;
i++;
// If the value of the current symbol is less than the next symbol
}
}
else
{
res = res + s1;
i++;
}
}
setConvertedValue(res);
}
};

roman_test.cpp

#include "roman_implementation.cpp"

// Main
int main()
{
// Considering inputs given are valid

cout<<"Create a roman numeral object using the default constructor\n";

RomanImplementation romanImplementation1;
romanImplementation1.setStr("MCMLIII");
romanImplementation1.romanToInteger() ;
romanImplementation1.printValue();
romanImplementation1.printRomanString();

cout<<"Create a roman numeral object using the overloaded constructor\n";

RomanImplementation romanImplementation2("MMMCCCIII");
romanImplementation2.romanToInteger() ;
romanImplementation2.printValue();
romanImplementation2.printRomanString();

cout<<"Create an array of the roman class of size 3\nInput strings\n";

RomanImplementation romanImplementation3[3];
string str[3];
for(int i=0;i<3;i++){
cin>>str[i];
}
for(int i=0;i<3;i++){

romanImplementation3[i].setStr(str[i]);
romanImplementation3[i].romanToInteger() ;
romanImplementation3[i].printValue();
romanImplementation3[i].printRomanString();
}
return 0;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning