Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Help Can someone program this for me so I can understand it? Create a functi

ID: 3605285 • Letter: C

Question

C++ Help

Can someone program this for me so I can understand it?

Create a function letterToInt with the following interface:

          int      letterToInt( char letter )

This function should accept a character value as a parameter. This variable represents one symbol in a roman numeral. Your function should return the integer equivalent (e.g., if you pass the function an 'X', it would return the number 10). The function should return -1 if the letter passed to it is not a valid letter in a roman numeral.

Additional Requirements:

Use a switch statement in your function.

Your function should contain only one return statement.

Write a main() function to test your function.

The valid roman numerals and their meanings are:

I - 1

V - 5

X - 10

L - 50

C - 100

M - 1000

NOTE: This function does not need to handle a complete roman number such XIV; it only handles one digit.

Explanation / Answer

#include <iostream>

using namespace std;

int letterToInt( char letter);

int main() {

// your code goes here

char ch;

cout<<"Enter a character ";

cin>>ch;

int numericEquivalent = letterToInt(ch);

if (numericEquivalent!= -1)

cout<< "Numeric Equivalent : "<<numericEquivalent;

else

cout<<-1;

return 0;

}

int letterToInt( char letter)

{

int num= 0;

switch(letter)

{ case 'I' : num =1;break;

case 'V' : num =5;break;

case 'X' : num =10;break;

case 'L' : num =50;break;

case 'C' : num =100;break;

case 'M' : num =1000;break;

default : num =-1;

}

return num;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote