Activity No. 3: (Roman Numeral)

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Casilao, Princess Lheakyrie R.

ECE-2102

Activity No. 3
(Roman Numeral)

Introduction

Roman numerals are a number notation scheme used by the Romans. These are an
additive (and subtractive) system that uses letters to represent some "base" numbers, and then
denote arbitrary numbers using symbol combinations. The origin of the Roman numeral system
is unfortunately little known (Cajori 1993, p. 30). The Roman Numeral System is a system in
which numbers are expressed by adding the letters of the Latin alphabet. During the late Middle
Ages, it was the standard way of writing numbers in Europe. Even after the fall of the Roman
Empire, Roman numerals were useful, but it was replaced by the Hindu-Arabic number system
as it was more convenient from the fourteenth century. The replacement process, however, was
quite slow. There are still small uses for the Roman numerals today.

Flowchart
Start

Input a number

Convert the input number


from string to double

Declare the array of strings equivalents


of integers in Roman Numerals

Use the modulo Number Is isnan


operation in the input >1000 (number Is n!=0?
by 1 and store it in “n” or <0? )==1

YES YES YES

“OUT OF “NOT AN “NOT AN


RANGE” INTEGER” INTEGER”

End
NO

Carry out a quotient remainder on


“number” and keep quotient in
“q1” and remainder in “r1”

Carry out a quotient remainder


on “r1” and keep quotient in
“q2” and remainder in “r2”

Carry out a quotient remainder


on “r2” and keep quotient in
“q3” and remainder in “r3”

Index the values of q1, q2, q3, and r3


which will express the thousands,
hundreds, tens, and ones digit.

Concatenate “THOUSAND”, “HUNDRED”,


“TEN”, and “ONE” into “roman”.

Display “roman”

End

Figure above exhibits flowchart of the roman numeral algorithm. This algorithm begins
when the "digit" value is set to be the user's input. As a string can be input, the input number will
be converted into a double. The number will be announced containing the thousands, hundreds,
tens, and digits of the roman numerals. Since an array starts counting at one and not at zero, a
blank string has been included. To test the input value and make sure it is an integer, the "n" will
be initialized as the number module and 1. First, if the input is greater than 1000 or equal to zero,
the program should display "OUT OF RANGE" when it is real. Nevertheless, if the input is an
integer based on the initial conversion, if valid, it will display "NOT AN INTEGER." Therefore,
if mod(num,1) is not equal to zero, "NOT AN INTEGER" will be shown if valid. The number
(input) would be translated to "roman" (roman number equivalent). The remaining syntax of the
quotient divides the input by 1000, 100, 10 and stores the rest and quotient. A quotient remaining
on "number" will be performed and the quotient will be kept in "q1" and the remaining quotient
in "r1." Then perform a quotient on "r1" and keep the quotient in "q2" and the remaining quotient
in "r2." Perform a quotient rest on "r2" and keep the quotient in "q3" and the remaining quotient
in "r3." The values of q1, q2, q3, and r3 were indexed to express the numbers of thousands,
hundreds, tens, and others. It will concatenate "THOUSAND," "HUNDRED," "TEN" and
"ONE" into "roman." Finally, the "roman" (equivalent roman number) that ends the algorithm
will be displayed.

MATLAB CODES
1 % Casilao, Princess Lheakyrie
2 % ECE 2102
3 % MATLAB Activity 3
4 % Roman Numeral
5 number = input ('Input a Number: ', 's');
6 number = str2double(number);
7 roman = 0;
8 thousands = ["" "M"];
9 hundreds = ["" "C" "CC" "CCC" "CD" "D" "DC" "DCC" "DCCC"
"CM"];
10 tens = ["", "X" "XX" "XXX" "XL" "L" "LX" "LXX" "LXXX"
"XC"];
11 ones= ["", "I" "II" "III" "IV" "V" "VI" "VII" "VIII" "IX"];
12 n = mod(number,1);
13 if number > 1000 || number<=0
14 disp("OUT OF RANGE!")
15 elseif isnan(number)==1
16 disp("NOT AN INTEGER!")
17 elseif n~= 0
18 disp("NOT AN INTEGER!")
19 else
20 [q1, r1] = quorem(sym(number),
sym(1000));
21 [q2, r2] = quorem(sym(r1), sym(100));
22 [q3, r3] = quorem(sym(r2), sym(10));
23 THOUSAND = thousands (1,q1+1);
24 HUNDRED = hundreds
(1,q2+1);
25 TEN = tens (1,q3+1);
26 ONE = ones (1,r3+1);
27 roman = strcat(THOUSAND,HUNDRED,TEN,ONE);
28 disp("Roman Numeral is: ")
29 disp(roman)
30 end

The roman numeral algorithm's MATLAB code is above. First and foremost, the
activity's name, title and description are the lines 1 to 4, which are followed by percentage
sign and are in green colour. The value of "digit" that will be a user input was initialized in
line 5 for the first time. In line 6, as a string can be input, the input will be translated into a
double. The initialization of "roman" as zero in line 7. Line 8 then announces a set of
thousands of roman numerals (M= 1000). Since an array starts counting at one and not at zero,
a blank string has been included. Line 9 declares an array containing the hundreds digit of the
roman numerals. A blank string was once again included just like in the previous line. Line 10
declares an array containing the tens digit of the roman numerals. In addition, line 12
initializes n as the number module and 1 to test the input value and ensure it is an integer. The
next line is an if-case that tests if the input is greater than or equal to zero than 1000. If line 13
is real, "OUT OF RANGE" will be shown.”. The row is a case Else-if that checks whether the
input is an integer based on the initial conversion. If line 15 is true, "NOT INTEGER!" will be
shown.”. Line 17 is a case of "Else if" checking that mod(num,1) is not equal to zero in line 8.
If the condition in line 17 is true, "NOT INTEGER!" will be shown.” Line 19 is the Else case
that contains the conversion process of “number” (inputted integer) into “roman” (equivalent
roman numeral).

Thereupon, line 20 is quotient remainder syntax that divides the input by 1000 and
stores the remainder and quotient. Line 21 is also a quotient remainder syntax that divides the
input by 100 and stores the remainder and quotient. And line 22 is also a quotient remainder
syntax that divides the input by 10 and stores the remainder and quotient.

In line 23, “THOUSAND” was initialized as the value indexed on the “thousands”
array from the quotient in line a. It contains a plus one on the quotient due to the blank content
on the array. Line 24 initializes “HUNDRED” as the value indexed on the “hundreds” array
from the quotient in line 23. It contains a plus one on the quotient due to the blank content on
the array. Line 25 initializes “TEN” as the value indexed on the “tens” array from the quotient
in line 24. It contains a plus one on the quotient due to the blank content on the array. Line 26
initializes “ONE” as the value indexed on the “ones” array from the remainder in line 25. it
contains a plus one on the quotient due to the blank content on the array. The line 27
concatenates the strings “THOUSAND”, “HUNDRED”, “TEN” and “ONE” and make it the
new value of “roman” which now contains the converted equivalent roman numeral of the
input integer. The last line displays the value of “roman” which terminates the program.

Many functions have been discovered in this operation. Techniques for initializing and
announcing were further discussed. If it could also be executed, Else-if, and Else. In fact, in
this simple algorithm, the statements of condition and the manipulating string and numbers
were learned.

References

Know the Romans. (n.d.). Retrieved December 2019, from


https://www.knowtheromans.co.uk/Categories/SubCatagories/RomanNumerals/

Smith, D. E., & Ginsburg, J. (n.d.). Numbers and Numerals. Retrieved December 2019,
from https://files.eric.ed.gov/fulltext/ED077712.pdf

You might also like