Programming Language: C++ I need the codes for extRomanType.cpp, extRomanType.h, main.cpp, romanType.cpp, romanType.h // I will definitely rate and give thumbs up. Here are the initial codes, this might help in building the program.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Programming Language: C++

I need the codes for extRomanType.cpp, extRomanType.h, main.cpp, romanType.cpp, romanType.h

// I will definitely rate and give thumbs up.

Here are the initial codes, this might help in building the program.

main.cpp

#include <iostream> 

#include "extRomanType.h"
 
using namespace std;
 
int main()
{
    extRomanType num1("XXXIV");
    extRomanType num2("XV");
    extRomanType num3;

    cout << "Num1 = " << num1 << endl;
    cout << "Num2 = " << num2 << endl;
    cout << "Num1 + Num2 = " << num1+num2 << endl;
    cout << "Num1 * Num2 = " << num1*num2 << endl;

    cout << "Num1 - Num2 = " << num1 - num2 << endl;
    cout << "Num2 - Num1 = " << num2 - num1 << endl;

    cout << "Enter two numbers in Roman format: ";
    cin >> num1 >> num2;
    cout << endl;

    cout << "Num1 = " << num1 << endl;
    cout << "Num2 = " << num2 << endl;

    num3 = num2 * num1;
  cout << "Num3 = " << num3 << "  ";
 //   num3.romanToPositiveInteger();
 //   num3.printDecimal();
    cout << endl;

    cout << "--num3: " << --num3 << "  ";
 //   num3.romanToPositiveInteger();
 //   num3.printDecimal();
    cout << endl;

    cout << "++num3: " << ++num3 << "  ";
  //  num3.romanToPositiveInteger();
 //   num3.printDecimal();
    cout << endl;

    cout << "Num1 = " << num1 << endl;
    cout << "Num2 = " << num2 << endl;
    cout << "Num1 + Num2 = " << num1 + num2 << endl;
    cout << "Num1 * Num2 = " << num1 * num2 << endl;
    cout << "Num1 / Num2 = " << num1 / num2 << endl;

    cout << "Num1 - Num2 = " << num1 - num2 << endl;
    cout << "Num2 - Num1 = " << num2 - num1 << endl;


    return 0;
}
 
romanType.h
 
//Roman Num Header file
  
#include <string> 
using namespace std;

class romanType
{
public:
    void setRoman(string);
    void romanToPositiveInteger();
    void printPositiveInteger() const;
    void printRoman() const;
    romanType();
    romanType(string);

private:
    string romanNum;
    int num;
};
 
romanType.cpp
 
 
//Roman Number Implementation file

#include <iostream> 
#include <string>
#include "romanType.h"
 
using namespace std;

void romanType::printPositiveInteger() const
{
    cout << num;
}

void romanType::printRoman() const
{
    cout << romanNum;
}

void romanType::setRoman(string rString)
{
    romanNum = rString;
    romanToPositiveInteger();
}

void romanType::romanToPositiveInteger()
{
    int sum = 0;
    int length =  romanNum.length();
    int i;
  
  int previous = 1000;

    for (i = 0; i < length; i++)
    {
         switch (romanNum[i])
         {
         case 'M': 
            sum += 1000;
            if (previous < 1000)
                sum -=  2 * previous;
            previous = 1000;
            break;
         case 'D': 
             sum += 500;
            if (previous < 500)
                sum -= 2 * previous;
            previous = 500;
            break;
         case 'C': 
             sum += 100;
            if (previous < 100)
                sum -= 2 * previous;
            previous = 100;
            break;
         case 'L': 
             sum += 50;
            if (previous < 50)
                sum -= 2 * previous;
            previous = 50;
            break;
         case 'X': 
             sum += 10;
            if (previous < 10)
                sum -= 2 * previous;
            previous = 10;
            break;;
         case 'V': 
             sum += 5;
            if (previous < 5)
                sum -= 2 * previous;
        previous = 5;
            break;
         case 'I': 
            sum += 1;
            previous = 1;
        }
    }

    num = sum;
}

romanType::romanType()
{
    romanNum = 'I';
    num = 1;
}

romanType::romanType(string rString)
{
    romanNum = rString;
    romanToPositiveInteger();
}
Arithmetic with Roman Numerals
Instructions
In programming Exercise 6 in Chapter 10, we defined a class romanType to implement Roman
numbers in a program. In that exercise, we also implemented a function,
romanToPositiveInteger , to convert a Roman number into its equivalent positive integer.
Modify the definition of the class romanType so that the member variables are declared as
protected . Furthermore, overload the stream insertion and stream extraction operators for easy
input and output. The stream insertion operator outputs the Roman number in the Roman format.
Also, include a member function, positiveIntegerToRoman , that converts a positive integer to
an equivalent Roman number format. Write the definition of the member function
positiveIntegerToRoman
For simplicity, we assume that only the letter I can appear in front of another letter and that it
appears only in front of the letters V and X. For example, 4 is represented as IV, 9 is represented as
IX, 39 is represented as XXXIX, and 49 is represented as XXXXIX. Also, 40 willI be represented as
XXXX, 190 will be represented as CLXXXX, and so on.
1/2
<>
Transcribed Image Text:Arithmetic with Roman Numerals Instructions In programming Exercise 6 in Chapter 10, we defined a class romanType to implement Roman numbers in a program. In that exercise, we also implemented a function, romanToPositiveInteger , to convert a Roman number into its equivalent positive integer. Modify the definition of the class romanType so that the member variables are declared as protected . Furthermore, overload the stream insertion and stream extraction operators for easy input and output. The stream insertion operator outputs the Roman number in the Roman format. Also, include a member function, positiveIntegerToRoman , that converts a positive integer to an equivalent Roman number format. Write the definition of the member function positiveIntegerToRoman For simplicity, we assume that only the letter I can appear in front of another letter and that it appears only in front of the letters V and X. For example, 4 is represented as IV, 9 is represented as IX, 39 is represented as XXXIX, and 49 is represented as XXXXIX. Also, 40 willI be represented as XXXX, 190 will be represented as CLXXXX, and so on. 1/2 <>
Extending the romanType class
Instructions
Derive a class extRomanType from the class romanType to do the following: In the class
extRomanType , overload the arithmetic operators +, - , * , and / so that arithmetic
operations can be performed on Roman numbers. Also, overload the pre- and post-increment and
decrement operators as member functions of the class extRomanType .
To add (subtract, multiply, or divide) Roman numbers, add (subtract, multiply, or divide,
respectively) their positive integer representations and then convert the result to the Roman
number format. For subtraction, if the first number is smaller than the second number, output a
message saying that, "Because the first number is smaller than the second, the numbers
cannot be subtracted". Similarly, for division, the numerator must be larger than the denominator.
Use similar conventions for the increment and decrement operators.
Write a main() to test your class.
FILETREE
-~/sandbox
required files/codes
A extRomanType.cpp
A extRomanType.h
A main.cpp
A romanType.cpp
A romanType.h
Transcribed Image Text:Extending the romanType class Instructions Derive a class extRomanType from the class romanType to do the following: In the class extRomanType , overload the arithmetic operators +, - , * , and / so that arithmetic operations can be performed on Roman numbers. Also, overload the pre- and post-increment and decrement operators as member functions of the class extRomanType . To add (subtract, multiply, or divide) Roman numbers, add (subtract, multiply, or divide, respectively) their positive integer representations and then convert the result to the Roman number format. For subtraction, if the first number is smaller than the second number, output a message saying that, "Because the first number is smaller than the second, the numbers cannot be subtracted". Similarly, for division, the numerator must be larger than the denominator. Use similar conventions for the increment and decrement operators. Write a main() to test your class. FILETREE -~/sandbox required files/codes A extRomanType.cpp A extRomanType.h A main.cpp A romanType.cpp A romanType.h
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Introduction to Coding
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education