Question

Assignment Draw a flowchart, using Microsoft Visio or LucidChart, to document the logic required to complete this program Save the flowchart as a PDF file Develop a C++ program, following the logic in your flowchart, to convert a series of whole number decimal values to their Roman equivalent. Develop a function that will accept a whole number value in the range 1-9999 and return a string containing the long-form Roman Numeral equivalent of the input value, consisting only of upper-case letters. The prototype for this function should be string toLongRoman ( int x );. Develop a function that will accept any string and return a lower-case version of the same string. Do not limit this function to working only on Roman Numerals. The prototype for this function should be string toLower ( string s);. Create a set of parallel arrays, each having 35 rows . . o A single-column array to contain whole numbers, and o Atwo-column array to contain Roman Numerals as strings. Convert a series of decimal values to Roman Numerals as follows: o Request a positive whole number in the range 1-5000 from the user. o Verify that the number is in the proper range. Reject all values outside this range and request a replacement value. Do no proceed until the user enters a valid number Starting with the users input value, repeat the following steps until all 35 rows of both arrays are full Store the current numeric value into the next available row of the whole number array Using your first function, generate the upper-case long-form Roman Numeral equivalent of the current value Store the upper-case long-form Roman Numeral into the first column of the same row of the string array. For instance, if row 7 is the current row of the whole number array, then the upper-case Roman value string will be stored in row 7 of the first column of the string array o o o o o Using your second function, convert the upper-case Roman Numeral string to lower-case o Store the lower-case Roman Numeral string in the second column of the current row of the string array o Increment the current numeric value by one o Do not output anything until all values have been converted and al rays are full Display the contents of the first 20 rows of all arrays, one set of values per row in neat columns on the console Save the contents of all 35 rows of all arrays, one set of values per row in neat columns to a file named roman.txt The format of the file output must be identical to that of the console output. Repeat this process of asking the user for a number and then converting a series of values to Roman Numerals . until the user enter enters a zero (since there is no Roman equivalent of zero)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program.cpp

#include <iostream>
#include <bits/stdc++.h>
#include<fstream>
using namespace std;
int whole_xber_array[35];
string roman_array1[35],roman_array2[35];
  
string toLongRoman(int x){
    int decimal[] = {1000,900,500,400,100,90,50,40,10,9,5,4,1}; //base values
   const char *symbol[] = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; //roman symbols
    int i = 0;
string s="";
    while(x){ //repeat process until x is not 0
        while(x/decimal[i]){ //first base value that divides x is largest base value
          s+=symbol[i];
            x -= decimal[i]; //subtract largest base value from x
        }
        i++;    //move to next base value to divide x
    }
    return s;
}


string toLower(string s){
transform(s.begin(),s.end(),s.begin(),::tolower);//convert string to lowercase
    return s;
}
int main()
{
ofstream oFile;
oFile.open("roman.txt");
      int x,index=0;
      do{
x=-1;
      do{
    cout<<"Enter the number ";
  
    cin>>x;
      }while(x<0 || x>5000);
   string s=toLongRoman(x);
      cout<<s<<endl;
   if(x!=0)   {
   whole_xber_array[index]=x;
   roman_array1[index]=s;
   roman_array2[index]=toLower(s);
   index++;
   }
      }while(x!=0);
string s="number\tRoman\tRoman small\n";
cout<<s;
oFile<<s;
for(int i=0;i<index;i++){
   cout<<whole_xber_array[i]<<"\t"<<roman_array1[i]<<"\t"<<roman_array2[i]<<endl;
   oFile<<whole_xber_array[i]<<"\t"<<roman_array1[i]<<"\t"<<roman_array2[i]<<"\n";//write to file
  
}
oFile.close();//close file
    return 0;
}

Output

user@ubuntu: $ g++ roman.cpp user@ubuntu:-$./a.out Enter the number 12 XII Enter the number -5 Enter the number 321 CCCXXI Enter the number number Roman Roman small 12 321 usereubuntu:-s -/a.out Enter the number 50000 Enter the number 100 XII xii Enter the number number Roman Roman small 100 user@ubuntu:$

Add a comment
Know the answer?
Add Answer to:
Assignment Draw a flowchart, using Microsoft Visio or LucidChart, to document the logic required to complete...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can someone code this asap? Use any language that you want. 2. Ancestral Names Given a...

    Can someone code this asap? Use any language that you want. 2. Ancestral Names Given a list of strings comprised of a name and a Roman numeral, sort the list first by name, then by decimal value of the Roman numeral. In Roman numerals, a value is not repeated more than three times. At that point, a smaller value precedes a larger value to indicate subtraction. For example, the letter I represents the number 1, and Vrepresents 5. Reason through...

  • *Answer must be in C* Write a complete program as follows (declare any necessary variables): Create...

    *Answer must be in C* Write a complete program as follows (declare any necessary variables): Create an array of doubles named “hummus” with 2 rows and 300 columns. Initialize all array elements to zero. Write a loop that will repeatedly ask the user to enter a value and store it in the first row of the array (do not overwrite previously entered values) until the whole first row is populated with the user input. (hint the loop should have the...

  • Write a menu based program implementing the following functions: (0) Write a function called displayMenu that...

    Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...

  • Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What...

    Please complete the following programming with clear explanations. Thanks! Homework 1 – Programming with Java: What This Assignment Is About? Classes (methods and attributes) • Objects Arrays of Primitive Values Arrays of Objects Recursion for and if Statements Selection Sort    Use the following Guidelines: Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc.) Use upper case for constants. • Use title case (first letter is upper case) for classes. Use lower case with uppercase...

  • I need help as quick as possible, thanks beforehand. Please provide the test output The Lo...

    I need help as quick as possible, thanks beforehand. Please provide the test output The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown below. 35 The Lo Shu Magic Square has the following properties: The grid contains the numbers 1 - 9 exactly The sum of each row, each column and each diagonal all add up to the same number. This is shown below: 15 4 92 15 - 81 + 15 15 15...

  • Using java : In this exercise, you need to implement a class that encapsulate a Grid. A grid is a useful concept in crea...

    Using java : In this exercise, you need to implement a class that encapsulate a Grid. A grid is a useful concept in creating board-game applications. Later we will use this class to create a board game. A grid is a two-dimensional matrix (see example below) with the same number of rows and columns. You can create a grid of size 8, for example, it’s an 8x8 grid. There are 64 cells in this grid. A cell in the grid...

  • In this assignment, we will be making a program that reads in customers' information, and create...

    In this assignment, we will be making a program that reads in customers' information, and create a movie theatre seating with a number of rows and columns specified by a user. Then it will attempt to assign each customer to a seat in a movie theatre. 1. First, you need to add one additional constructor method into Customer.java file. Method Description of the Method public Customer (String customerInfo) Constructs a Customer object using the string containing customer's info. Use the...

  • Objectives Work with functions Assignment Write each of the following functions using Python. The function header MUST b...

    Objectives Work with functions Assignment Write each of the following functions using Python. The function header MUST be written as specified. In your main code test all of the specified functions. Each function must have a comment block explaining what it does, what the parameters are and what the return value is. Please remember the following two guidelines: unless the purpose of the function is to generate output DO NOT write to the screen within the function unless the purpose...

  • DESCRIPTION Complete the program using Java to read in values from a text file. The values...

    DESCRIPTION Complete the program using Java to read in values from a text file. The values will be the scores on several assignments by the students in a class. Each row of values represents a specific student's scores. Each column represents the scores of all students on a specific assignment. So a specific value is a specific student's score on a specific assignment. The first two values in the text file will give the number of students (number of rows)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT