Question: Write a new class call PrimeNumbers that uses the converted Roman numeral value from RomanType class that was created during Lab Assignment V (Lab 5

Write a new class call PrimeNumbers that uses the converted Roman numeral value from RomanType class that was created during Lab Assignment V(Lab 5 is attached below at the end). Your program will use the integer value from the RomanType class and display first X prime numbers. X is the converted Roman numeral value. Display 10 prime numbers per line.

In the RomanType class, rename your current function that print the Roman numeral as a decimal number to be called PrintOut() with no parameter. This function should be a pure virtual function now.

Prime number an integer greater than 1 is prime if the only positive divisor is 1 or itself. For instance, 2, 3, 5 and 7

are prime numbers, but 4, 6, 8 and 9 are not.

The program is to display the first X prime numbers in 10 lines, each line displays 10 prime numbers. The problem can be solved using loops:

a. Set a loop counter to 0 and initial number to be tested by 2

b. Start loop iteration and determine whether the number is prime

c. If the number is prime, display the number (on same line or next line) and increment the loop counter by 1

d. Increment the number by 1

e. Repeat steps b-d as long as the loop counter is X or less

f. The loop terminates when the loop counter is greater than X

Your PrimeNumbers class should have the following:

Member variables

(.) No Member variables (use RomanType class)

Member Functions

(.) PrintOut Print the previous statement that was in the RomanType class and follow by the output for all the prime numbers

Output should be exactly like this:

Enter a roman number: C

The equivalent of the Roman numeral 'C' is 100

Below are the first '100' Prime Number:

2 3 5 7 11 13 17 19 23 29

31 37 41 43 47 53 59 61 67 71

73 79 83 89 97 101 103 107 109 113

127 131 137 139 149 151 157 163 167 173

179 181 191 193 197 199 211 223 227 229

233 239 241 251 257 263 269 271 277 281

283 293 307 311 313 317 331 337 347 349

353 359 367 373 379 383 389 397 401 409

419 421 431 433 439 443 449 457 461 463

467 479 487 491 499 503 509 521 523 541

Would you like to enter another Roman numeral (Y = yes or N = no): N

Good Bye

Lab 5 (roman numeral is copied down below to continue from thanks)

#include #include using namespace std; class romanType

{

public: romanType(string = ""); void setRoman(string); void convertToDecimal(); void printRoman(); void printDecimal(); private: string roman; int decimal; }; romanType::romanType(string myRoman) { roman = myRoman; decimal = 0; } void romanType::setRoman(string myRoman) { roman = myRoman; decimal = 0; } void romanType::convertToDecimal() { char romans[7] = { 'M', 'D', 'C', 'L', 'X', 'V', 'I' }; int decimals[7] = { 1000, 500, 100, 50, 10, 5, 1 }; int j, pos; size_t len = roman.length();

for (unsigned int i = 0; i < len - 1; i++) {

for (pos = 0; pos < 7; pos++) if (roman.at(i) == romans[pos]) break;

if (pos < 7) {

for (j = 0; j < pos; j++) if (roman.at(i + 1) == romans[j]) break;

if (j == pos) decimal += decimals[pos]; else decimal -= decimals[pos]; } }

for (j = 0; j < 7; j++) if (roman.at(len - 1) == romans[j]) break;

decimal += decimals[j]; } void romanType::printRoman() { cout << " \tThe roman numeral is " << roman; } void romanType::printDecimal() { cout << " \tThe decimal equivalent of the " << "given roman numeral is " << decimal; }

int main() {

cout << " \tProgram that convert Roman Numeral" << " into decimal form.";

romanType r; string rns[3] = { "CCCLIX", "MCXIV", "MDCLXVI" }; for (int i = 0; i < 3; i++) {

r.setRoman(rns[i]);

r.convertToDecimal();

r.printRoman();

r.printDecimal(); } string romanNum; cout << " \tEnter Roman Number : "; cin >> romanNum; r.setRoman(romanNum); r.convertToDecimal(); r.printRoman(); r.printDecimal(); cout << " \t"; system("pause"); return 0;

}

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!