Program 4-instructor - #include #include u using namespace std/Input a vaild roman character(M D C L X V I/Output a decimal

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <string> using namespace std; u //Input: a vaild roman character (M, D, C, L, X, V, I) //Output: a decimal value of roman character int toInt(char chr) //function implementing a lookup table. { switch(chr) s { case 'M':return 1000; case 'D':return 500; case 'C':return 100; case 'L':return 50; case 'X':return 10; case 'V':return 5; case 'I':return 1; default:return 0; } } //Input: a pseudo roman number //Output: a positive integer representation of the pseudo roman number int toInt(string roman) { //roman="XVI" int sum=0; for (int i=0;i<(int)roman.length();i++) sum+=toInt(roman[i]); //I have two functions called toInt(). One takes char, one takes a string as input //That's how we know which one to call. return sum; } //Input: positive integer //Output: a pseudo roman number representation of the integer string toRoman(int number) { int romanints[7]={1000,500,100,50,10,5,1}; //define an array of possible values for roman chars char romanchars[7]={'M','D','C','L','X','V','I'};
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/25/2010 for the course CECS CIS 150 taught by Professor L.tsui during the Fall '07 term at University of Michigan-Dearborn.

Page1 / 2

Program 4-instructor - #include #include u using namespace std/Input a vaild roman character(M D C L X V I/Output a decimal

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online