C++ problem: Convert your work into a class for my use based on the provided UML
ID: 3843079 • Letter: C
Question
C++ problem:
Convert your work into a class for my use based on the provided UML. I am building an interface based on the specifications I provide, so your class must match the UML exactly.
The class should behave as follows:
• constructor: Assigns the parameter to the private class member base 10 .
• GetBase10: Returns the stored decimal value.
• GetUnsignedBase2: Returns the stored decimal value as an unsigned binary string bits wide.
• GetSignedBase2: Returns the stored decimal value as a two’s complement signed binary string bits wide.
• GetBase16: Returns the stored decimal value as a signed hexadecimal value.
• SetBase10: Updates the value of the stored decimal integer member.
• SetUnsignedBase2: Updates the value of the stored decimal integer by interpreting the parameter base 2 as an unsigned binary integer.
• SetSignedBase2: Updates the value of the stored decimal integer by interpreting the parameter base 2 as an signed two’s complement binary integer.
• SetBase16: Updates the value of the stored decimal integer by interpreting the parameter base 16 as signed hexadecimal integer.
Submission directory:
1. A base converter.h file with your library includes and class declarations. 2. A base converter.cc file with your class definitions.
pkg Base Converter base 10 int Baseconverter(base 10 int) GetUnsignedBase2(bits int) string GetSignedBase2(bits int) string GetBase160 string SetUnsignedBase2(base 2 string) void Set Signed Base2(base 2 string) void Set Base16(base 16 string) voidExplanation / Answer
public class RomanToDecimal
{
public static void romanToDecimal(java.lang.String romanNumber)
{
int decimal = 0;
int lastNumber = 0;
String romanNumeral = romanNumber.toUpperCase();
for (int x = romanNumeral.length() - 1; x >= 0 ; x--)
{
char convertToDecimal = romanNumeral.charAt(x);
switch (convertToDecimal)
{
case 'M':
decimal = processDecimal(1000, lastNumber, decimal);
lastNumber = 1000;
break;
case 'D':
decimal = processDecimal(500, lastNumber, decimal);
lastNumber = 500;
break;
case 'C':
decimal = processDecimal(100, lastNumber, decimal);
lastNumber = 100;
break;
case 'L':
decimal = processDecimal(50, lastNumber, decimal);
lastNumber = 50;
break;
case 'X':
decimal = processDecimal(10, lastNumber, decimal);
lastNumber = 10;
break;
case 'V':
decimal = processDecimal(5, lastNumber, decimal);
lastNumber = 5;
break;
case 'I':
decimal = processDecimal(1, lastNumber, decimal);
lastNumber = 1;
break;
}
}
System.out.println(decimal);
}
public static int processDecimal(int decimal, int lastNumber, int lastDecimal)
{
if (lastNumber > decimal)
{
return lastDecimal - decimal;
}
else
{
return lastDecimal + decimal;
}
}
public static void main(java.lang.String args[])
{
romanToDecimal("XIV");
}
}
CONVERTING INTEGERS TO ROMAN NUMERALS:
import java.util.LinkedHashMap;
import java.util.Map;
public static String RomanNumerals(int Int)
{
LinkedHashMap<String, Integer> roman_numerals = new LinkedHashMap<String, Integer>();
roman_numerals.put("M", 1000);
roman_numerals.put("CM", 900);
roman_numerals.put("D", 500);
roman_numerals.put("CD", 400);
roman_numerals.put("C", 100);
roman_numerals.put("XC", 90);
roman_numerals.put("L", 50);
roman_numerals.put("XL", 40);
roman_numerals.put("X", 10);
roman_numerals.put("IX", 9);
roman_numerals.put("V", 5);
roman_numerals.put("IV", 4);
roman_numerals.put("I", 1);
String res = "";
for(Map.Entry<String, Integer> entry : roman_numerals.entrySet())
{
int matches = Int/entry.getValue();
res += repeat(entry.getKey(), matches);
Int = Int % entry.getValue();
}
return res;
}
public static String repeat(String s, int n)
{
if(s == null)
{
return null;
}
final StringBuilder sb = new StringBuilder();
for(int i = 0; i < n; i++)
{
sb.append(s);
}
return sb.toString();
}
for (int i = 1;i<256;i++)
{
System.out.println("i="+i+" -> "+RomanNumerals(i));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.