Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[C++] Program that converts roman numerals to decimals using classes. Can someone fix my program? It's saying a library can't be found, and the program

[C++] Program that converts roman numerals to decimals using classes. Can someone fix my program? It's saying a library can't be found, and the program isn't excuting correctly. This is what I'm trying to accomplish;

image text in transcribed

image text in transcribed

This what the error message I'm getting looks like, and how it looks when I run it.

image text in transcribed

And this is my code. I have labelled the lines were the errors are found when I run it. Also, it isn't executing properly.. I also pasted the code in pastebin if it makes it easier to read since it has the lines labelled. http://pastebin.com/7mEBbgsF

[code]

#include //program header file

using namespace std;

class romanType

{

public:

romanType(string = "");

void setRoman(string);

void convertToDecimal();

void printRoman();

void printDecimal();

private:

string roman;

int decimal;

}; //end of the class definition of romantype.

#include //implements romantTypeImp.cpp

#include "romanType.h" //error message here, says library cannot be found.

using namespace std;

romanType::romanType(string myRoman)

{

roman = myRoman;

decimal = 0;

} //end constructor myromanType

void romanType::setRoman(string myRoman)

{

roman = myRoman;

decimal = 0;

}//end of function

void romanType::convertToDecimal()

{

char romans[7] = { 'M', 'D', 'C', 'L', 'X', 'V', 'I' };

int decimals[7] = { 1000, 5000, 100, 50, 10, 5, 1 };

int j, pos;

size_t len = roman.length();

//processing the numeral

for (unsigned int i = 0; i

{

for (pos = 0; pos

if (roman.at(i) == romans[pos])

break;

//checks for the validity of the roman letter.

if (pos

{

for (j = 0; j

if (roman.at(i + 1) == romans[j])

break; //performs operations on the decimal avlue respectively to j and pos

if (j == pos)

decimal += decimals[pos];

else decimal -= decimals[pos];

} //end of if

} //end of for

for (j = 0; j

if (roman.at(len - 1) == romans[j])

break;

decimal += decimals[j]; //adds decimal value of the roman letter to the decimal number.

}//end of void func

void romanType::printRoman()

{

cout

}//end

void romanType::printDecimal()

{

cout

}

//main program right here

#include

#include "romanType.h"//error message on this line, says the library cannot be found.

using namespace std;

int main()

{

cout

romanType r;

string rns[3] = { "CCCLIX", "MCXIV," "MDCLXVI" };

for (int i = 0; i

{

r.setRoman(rns[i]); //set roman numeral string

r.convertToDecimal(); //converts to dec

r.printRoman(); //prints

r.printDecimal();//prints it's decimal form here

}//endl

cout

system("pause");

return 0;

}

Write a program that converts a number entered in Roman numerals to a decimal. Your program should consist of a class, say, romanType. An object of type romanType should do the following: a. Store the number as a Roman numeral b. Convert and store the number into decimal form c. Print the number as a Roman numeral or decimal number as requested by the user

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago