1. #include <iostream.h>
  2. #include <iomanip.h>
  3. #include<conio.h>
  4. #include<stdio.h>
  5. #include<stdlib.h>
  6. #include <string.h>
  7.  
  8. void romanrecorder_1();
  9. void romanrecorder_2();
  10. void romanprinter_1();
  11. void romanprinter_2();
  12. void operation();
  13. void roman_translator();
  14. void exitprogram();
  15. char opsign;
  16. char I,V,X,L,C,D,M;
  17. char letter_1;
  18. char letter_2;
  19. int a;
  20. int Ia;
  21. int b;
  22. int Vb;
  23. int c;
  24. int Xc;
  25. int d;
  26. int Ld;
  27. int e;
  28. int Ce;
  29. int f;
  30. int Df;
  31. int g;
  32. int Mg;
  33. int first_number;
  34. int second_number;
  35. int total;
  36. int romantotal;
  37.  
  38. char roman_array[100];
  39. int main()
  40. {
  41.  
  42. a=0;
  43. b=0;
  44. c=0;
  45. d=0;
  46. e=0;
  47. f=0;
  48. g=0;
  49. clrscr();
  50. cout<<"Enter the first Roman Numeral followed by a dot(.): ";
  51.  
  52. romanrecorder_1();
  53.  
  54. return 0;
  55. }
  56. void romanrecorder_1()
  57. {
  58. cin>>letter_1;
  59. if (letter_1=='I')
  60. {
  61. a++;
  62. }
  63. else if (letter_1=='V')
  64. {
  65. b++;
  66. }
  67. else if (letter_1=='X')
  68. {
  69. c++;
  70. }
  71. else if (letter_1=='L')
  72. {
  73. d++;
  74. }
  75. else if (letter_1=='C')
  76. {
  77. e++;
  78. }
  79. else if (letter_1=='D')
  80. {
  81. f++;
  82. }
  83. else if (letter_1=='M'){
  84. g++;
  85. }
  86. romanprinter_1();
  87.  
  88. }
  89. void romanprinter_1()
  90. {
  91. Ia=1*a;
  92. Vb=5*b;
  93. Xc=10*c;
  94. Ld=50*d;
  95. Ce=100*e;
  96. Df=500*f;
  97. Mg=1000*g;
  98.  
  99. first_number=Ia+Vb+Xc+Ld+Ce+Df+Mg;
  100. cout<<endl<<"The first Roman Numeral is "<<first_number;
  101. cout<<endl;
  102. a=0;
  103. b=0;
  104. c=0;
  105. d=0;
  106. e=0;
  107. f=0;
  108. g=0;
  109. cout<<endl<<"Enter the second Roman Numeral followed by a dot(.):";
  110. romanrecorder_2();
  111.  
  112. }
  113. void romanrecorder_2()
  114. { cin>>letter_2;
  115. if (letter_2=='I')
  116. {
  117. a++;
  118. }
  119. else if (letter_2=='V')
  120. {
  121. b++;
  122. }
  123. else if (letter_2=='X')
  124. {
  125. c++;
  126. }
  127. else if (letter_2=='L')
  128. {
  129. d++;
  130. }
  131. else if (letter_2=='C')
  132. {
  133. e++;
  134. }
  135. else if (letter_2=='D')
  136. {
  137. f++;
  138. }
  139. else if (letter_2=='M'){
  140. g++;
  141. }
  142. romanprinter_2();
  143. }
  144. void romanprinter_2()
  145. {
  146. Ia=1*a;
  147. Vb=5*b;
  148. Xc=10*c;
  149. Ld=50*d;
  150. Ce=100*e;
  151. Df=500*f;
  152. Mg=1000*g;
  153. second_number=Ia+Vb+Xc+Ld+Ce+Df+Mg;
  154. cout<<endl<<"The second number is "<<second_number;
  155. a=0;
  156. b=0;
  157. c=0;
  158. d=0;
  159. e=0;
  160. f=0;
  161. g=0;
  162. cout<<endl<<endl;
  163. cout<<"Enter the desired arithmetic operation: ";
  164. operation();
  165. }
  166. void operation()
  167. {
  168. cin >> opsign;
  169. if (opsign=='+')
  170. {
  171. total=first_number+second_number;
  172. cout<<endl<<"The sum of "<<first_number<<" and "<<second_number<<" is "<<total;
  173. }
  174. else if (opsign=='-')
  175. {
  176. if (first_number>second_number)
  177. {
  178. total=first_number-second_number;
  179. }
  180. else if (second_number>first_number)
  181. {
  182. total=second_number-first_number;
  183. }
  184. cout<<endl<<"The difference of "<<first_number<<" and "<<second_number<<" is "<<total;
  185. }
  186. else if (opsign=='*')
  187. {
  188. total=first_number*second_number;
  189. cout<<endl<<"The multiplication of "<<first_number<<" and "<<second_number<<" is "<<total;
  190. }
  191. else if (opsign=='/')
  192. {
  193. total=first_number/second_number;
  194. cout<<endl<<"The division of "<<first_number<<" and "<<second_number<<" is "<<total;
  195. }
  196. cout<<endl<<endl;
  197. cout<<"The roman numeral value of "<<total<<" is ";
  198. roman_translator();
  199. }
  200. void roman_translator()
  201. {
  202. romantotal=total+1;
  203. if (romantotal>0)
  204. {
  205. while (romantotal>total)
  206. {
  207. if ( total>=1000)
  208. {
  209. total=total-1000;
  210. cout<<"M";
  211. romantotal=total+1;
  212. }
  213. else if (total>=500)
  214. {
  215. total=total-500;
  216. cout<<"D";
  217. romantotal=total+1;
  218. }
  219. else if (total>=100)
  220. {
  221. total=total-100;
  222. cout<<"C";
  223. romantotal=total+1;
  224. }
  225. else if (total>=50)
  226. {
  227. total=total-50;
  228. cout<<"L";
  229. romantotal=total+1;
  230. }
  231. else if (total>=10)
  232. {
  233. total=total-10;
  234. cout<<"X";
  235. romantotal=total+1;
  236. }
  237. else if (total>=5)
  238. {
  239. total=total-5;
  240. cout<<"V";
  241. romantotal=total+1;
  242. }
  243. else if (total>=1)
  244. {
  245. total=total-1;
  246. cout<<"I";
  247. romantotal=total+1;
  248. }
  249. else
  250. {
  251. romantotal--;
  252. }
  253. }
  254. }
  255. getch();
  256. }