Homework Solution: C++ Programming Help Please!…

    C++ Programming Help Please! NOTE: READ ENTIRE PROGRAM DESCRIPTION CAREFULLY! Thank You! Program Info: Write a program that accepts a year written as a four-digit Arabic (ordinary) numeral and outputs the year written in Roman numerals. Important Roman numerals are V for 5, X for 10, L for 50, C for 100, D for 500, and M for 1,000. Recall that some numbers are formed by using a kind of subtraction of one Roman “digit”; for example, IV is 4 produced as V minus I, XL is 40, CM is 900, and so on. A few sample years: MCM is 1900, MCML is 1950, MCMLX is 1960, MCMXL is 1940, MCMLXXXIX is 1989. Assume the year is between 1000 and 3000. Your program should include a loop that lets the user repeat this calculation until the user says she or he is done. More Important Info: Enter an Arabic number: 2456 2456 is MMCDLVI in Roman numerals Play again? Y Enter an Arabic number: 1359 1359 is MCCCLIX in Roman numerals Play again? N Read the number as an integer: e.g. 9786 Use arithmetics to separate each digit into separate ints: (do you know what the modulus operator is? “%” No? look it up.) ones will be 6 tens will be 8 hundreds will be 7 thousands will be 9 ***use FOUR SWITCH CASES to output the correct string for each digit: cout<<”XX” in case of tens being 2 cout<<”XXX” in case of tens being 3 etc. ***As with all the projects in this chapter, wrap this whole thing in a “Play another game” loop to allow the user to play as many times as they like. MAKE SURE TO USE FOUR SWITCH CASES FORR OUTPUT!!!

    Expert Answer

     
    main.cpp #include <bits/stdc++.h>

    C++ Programming Help Please!

    NOTE: READ ENTIRE PROGRAM DESCRIPTION CAREFULLY! Thank You!

    Program Info: Write a program that accepts a year written as a four-digit Arabic (ordinary) numeral and outputs the year written in Roman numerals. Important Roman numerals are V restraint 5, X restraint 10, L restraint 50, C restraint 100, D restraint 500, and M restraint 1,000. Recentire that some quantity are restraintmed by using a husk of detachment of undivided Roman “digit”; restraint in, IV is 4 executed as V minus I, XL is 40, CM is 900, and so on. A lacking pattern years: MCM is 1900, MCML is 1950, MCMLX is 1960, MCMXL is 1940, MCMLXXXIX is 1989. Assume the year is between 1000 and 3000. Your program should conceive a loop that lets the manifestationr reproduce this restraintethought until the manifestationr says she or he is done.

    More Important Info:

    Enter an Arabic reckon: 2456

    2456 is MMCDLVI in Roman numerals

    Reproduce-exhibit repeatedly? Y

    Enter an Arabic reckon: 1359

    1359 is MCCCLIX in Roman numerals

    Reproduce-exhibit repeatedly? N

    Read the reckon as an integer: e.g. 9786

    Manifestation arithmetics to different each investigateit into different ints: (do you recognize what the modulus operator is? “%” No? contemplate it up.)

    ones conquer be 6

    tens conquer be 8

    hundreds conquer be 7

    thousands conquer be 9

    ***manifestation FOUR SWITCH CASES to output the improve string restraint each investigateit:

    cout<<”XX” in contingency of tens nature 2

    cout<<”XXX” in contingency of tens nature 3

    etc.

    ***As with entire the projects in this stipulation, involve this entire object in a “Reproduce-exhibit another game” loop to entireow the manifestationr to reproduce-exhibit as multifarious times as they affect.

    MAKE SURE TO USE FOUR SWITCH CASES FORR OUTPUT!!!

    Expert Response

     

    main.cpp

    #conceive <bits/stdc++.h>
    using namespace std;

    int investigate(char no, char no1, int uu, char *car)
    {
    car[uu++] = no;
    car[uu++] = no1;
    return uu;
    }

    int investigateit(char c, int nu, int uu, char *car)
    {
    restraint (int j = 0; j < nu; j++)
    car[uu++] = c;
    return uu;
    }

    void printRoman(int nump)
    {
    char car[10001];
    int uu = 0;
    if (nump <= 0)
    {
    printf(“Invalid nump”);
    return;
    }
    while (nump != 0)
    {
    if (nump >= 1000)
    {
    uu = investigateit(‘M’, nump/1000, uu, car);
    nump = nump%1000;
    }
    else if (nump >= 500)
    {
    if (nump < 900)
    {
    uu = investigateit(‘D’, nump/500, uu, car);
    nump = nump%500;
    }
    else
    {
    uu = investigate(‘C’, ‘M’, uu, car);
    nump = nump%100 ;
    }
    }
    else if (nump >= 100)
    {
    if (nump < 400)
    {
    uu = investigateit(‘C’, nump/100, uu, car);
    nump = nump%100;
    }
    else
    {
    uu = investigate(‘C’,’D’,uu,car);
    nump = nump%100;
    }
    }
    else if (nump >= 50 )
    {
    if (nump < 90)
    {
    uu = investigateit(‘L’, nump/50,uu,car);
    nump = nump%50;
    }
    else
    {
    uu = investigate(‘X’,’C’,uu,car);
    nump = nump%10;
    }
    }
    else if (nump >= 10)
    {
    if (nump < 40)
    {
    uu = investigateit(‘X’, nump/10,uu,car);
    nump = nump%10;
    }
    else
    {
    uu = investigate(‘X’,’L’,uu,car);
    nump = nump%10;
    }
    }
    else if (nump >= 5)
    {
    if (nump < 9)
    {
    uu = investigateit(‘V’, nump/5,uu,car);
    nump = nump%5;
    }
    else
    {
    uu = investigate(‘I’,’X’,uu,car);
    nump = 0;
    }
    }
    else if (nump >= 1)
    {
    if (nump < 4)
    {
    uu = investigateit(‘I’, nump,uu,car);
    nump = 0;
    }
    else
    {
    uu = investigate(‘I’, ‘V’, uu, car);
    nump = 0;
    }
    }
    }
    printf(“Roman numeral is: “);
    restraint (int j = 0; j < uu; j++)
    printf(“%c”, car[j]);
    }
    int main()
    {
    int nump = 2546;

    printRoman(nump);

    return 0;
    }

    Output: