What's wrong with this code? onvert between Arabic, base ten numbers, and Roman numerals. The Roman number
Fantastic news! We've Found the answer you've been seeking!
Question:
What's wrong with this code?
Transcribed Image Text:
onvert between Arabic, base ten numbers, and Roman numerals. The Roman number system has the digits I, V, X, L, C, D, and M. Numbers are formed according to the following rules: 1. Only numbers up to 3,999 are represented. 2. As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. (In other words, it's a positional number system.) The numbers 1 to 9 are expressed like the table shown at the right. As you can see, a I preceding a V or X is subtracted from the value, and you can never have more than three I's in a row. Tens and hundreds are done the same way, except that the let- ters X, L, C, and C, D, M are used instead of I, V, X respectively. I II III IV V VI VII VIII IX 1 2 3 4 5 6 7 8 9 The toRoman() function accepts a decimal number such as 1978, and converts it to a string containing the Roman numerals "MCMLXXVIII". An invalid number (0, a negative number, or a number greater than 3,999) returns the string "OUT OF RANGE". string digit(int n, const string symbols); string ones (int n) { return digit(n, "IVX"); } string tens(int n) { return digit(n, "XLC"); } string hundreds(int n) { return digit(n, "CDM"); } Do make things easier for you, I've already written a regular console program that converts integers to Roman numerals. You'll find it in the file decToRoman.txt. Notice that the program is long and complex. Decompose toRoman () using the following four functions, which will be tested separately as well. C onvert between Arabic, base ten numbers, and Roman numerals. The Roman number system has the digits I, V, X, L, C, D, and M. Numbers are formed according to the following rules: 1. Only numbers up to 3,999 are represented. 2. As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. (In other words, it's a positional number system.) The numbers 1 to 9 are expressed like the table shown at the right. As you can see, a I preceding a V or X is subtracted from the value, and you can never have more than three I's in a row. Tens and hundreds are done the same way, except that the let- ters X, L, C, and C, D, M are used instead of I, V, X respectively. I II III IV V VI VII VIII IX 1 2 3 4 5 6 7 8 9 The toRoman() function accepts a decimal number such as 1978, and converts it to a string containing the Roman numerals "MCMLXXVIII". An invalid number (0, a negative number, or a number greater than 3,999) returns the string "OUT OF RANGE". string digit(int n, const string symbols); string ones (int n) { return digit(n, "IVX"); } string tens(int n) { return digit(n, "XLC"); } string hundreds(int n) { return digit(n, "CDM"); } Do make things easier for you, I've already written a regular console program that converts integers to Roman numerals. You'll find it in the file decToRoman.txt. Notice that the program is long and complex. Decompose toRoman () using the following four functions, which will be tested separately as well. C
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
What is wrong with this code and why it isn't working. class BankAccount: def init (self) : self.balance = 0.00 def deposit (self, amount) : self.balance += amount def withdraw (self, amount) : if...
-
What is wrong with the following code fragment? Will this code compile if it is part of an otherwise valid program? Explain.
-
What is wrong with the following switch statement? // This code has errors!!! switch (temp) { case temp < 0 : System.out.println("Temp is negative."); break; case temp = 0: System.out.println("Temp...
-
Why is it helpful to understand leadership as a theory while managing a healthcare-orientated organization? Justify your stance using two examples. What factors do you think should appear in a model...
-
a. Someone in the 36 percent tax bracket can earn 9 percent annually on her investments in a tax-exempt IRA account. What will be the value of a one-time $10,000 investment in 5 years? 10 years? 20...
-
Based on the email that Mukilteo received, the IC members perspective is correct with regard to: A. layering and netting of fees. B. tactical allocation capabilities. C. manager-specific operational...
-
Mrs. Palsgraf was waiting for a train on a platform of a railroad. When a different train came into the station, two men ran to get on that train before it left the station. While one of the men...
-
A textile manufacturer wants to set up a control chart for irregularities (e.g. oil stains, shop soil, loose threads, and tears) per 100 square yards of carpet. The following data were collected from...
-
In late 2007, some observers were concerned that the U.S economy was experiencing a dangerous combination or reduced output growth (resulting in increased unemployment) and higher inflation, as had...
-
Bamboo Consulting is a consulting firm owned and operated by Lisa Gooch. The following end-of-period spreadsheet was prepared for the year ended July 31, 2016: Based on the preceding spreadsheet,...
-
What experiences have you had taking tests? Have you ever felt a test was unfair? Recall that experience and try to ascertain exactly what was unfair. How will this experience help you as a school...
-
Of what value is this general grouping of national cultures to managers in their SIHRM activities?
-
In 2018, Thomas transferred land he bought in 2009 worth \(\$ 100,000\) to Andy Co. in return for 50 shares of stock. The land has an adjusted basis of \(\$ 30,000\) and is subject to a \(\$ 50,000\)...
-
Distinguish between international and domestic economic issues.
-
In 2018, Bob will sell land that he bought in 2008 for \(\$ 50,000\) to Tom. The selling price is \(\$ 250,000\). Tom has given Bob two options for the sale. Under option 1, Bob would receive the...
-
During 2018, Jane Mason incurred the following home expenses: Assume that Jane qualified for the home office deduction, all of the above expenditures qualified for the deduction as home office...
-
Which of the following is true for f(x) = log (x) where b > 1 (for example f(x) = log(x) )? Select all that apply. 0 0 0 0 Which of the following is true about f(x) = ? Select all that apply. The...
-
Suppose the market is semistrong form efficient. Can you expect to earn excess returns if you make trades based on? a. Your brokers information about record earnings for a stock? b. Rumors about a...
-
Write a program that asks the user to enter an integer n into a text field. When a Draw button is clicked, draw an n-by-n grid in a component.
-
Write a program that lets users design line charts with a mouse. When the user clicks above or below an existing point, the point is moved. (Allow for a few pixels of tolerance.) When the user clicks...
-
Write a program that reads words and arranges them in a paragraph so that all lines other than the last one are exactly forty characters long. Add spaces between words to make the last word extend to...
-
A client who is a director of a publicly listed corporation is required by law to refrain from trading that companys stock at certain points of the year when disclosure of financial results are...
-
Consider the pairwise correlations of monthly returns of the following asset classes: Based solely on the information in the preceding table, which equity asset class is most sharply distinguished...
-
Investing the majority of the portfolio on a passive or low active risk basis while a minority of the assets is managed aggressively in smaller portfolios is best described as: A. The coresatellite...
Study smarter with the SolutionInn App