Advertisement
lwytop

mp4 unfix

Jun 27th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.24 KB | None | 0 0
  1. // CPS 171 MP4 Wonyoung Lee  : Roman calculator.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <string>
  7. #include <fstream>
  8.  
  9. using namespace std;
  10.  
  11.  
  12. int convert_from_roman_to_decimal(char n)
  13. {
  14.     switch (n){
  15.     case 'I':
  16.         return 1;
  17.         break;
  18.     case 'V':
  19.         return 5;
  20.         break;
  21.     case 'X':
  22.         return 10;
  23.         break;
  24.     case 'L':
  25.         return 50;
  26.         break;
  27.     case 'C':
  28.         return 100;
  29.         break;
  30.     case 'D':
  31.         return 500;
  32.         break;
  33.     case 'M':
  34.         return 1000;
  35.         break;
  36.     default:
  37.         break;
  38.     }
  39. }
  40.  
  41. string convert_from_decimal_to_roman(int num)
  42. {
  43.     string romanNum = " ";
  44.  
  45.     while (num > 0){
  46.         if (num - 1000 >= 0){
  47.             romanNum += "M";
  48.             num -= 1000;
  49.         }
  50.         else if (num - 500 >= 0){
  51.             romanNum += "D";
  52.             num -= 500;
  53.         }
  54.         else if (num - 100 >= 0){
  55.             romanNum += "C";
  56.             num -= 100;
  57.         }
  58.         else if (num - 50 >= 0){
  59.             romanNum += "L";
  60.             num -= 50;
  61.         }
  62.         else if (num - 10 >= 0){
  63.             romanNum += "X";
  64.             num -= 10;
  65.         }
  66.         else if (num - 9 == 0){
  67.             romanNum += "IX";
  68.             num -= 9;
  69.         }
  70.         else if (num - 5 >= 0){
  71.             romanNum += "V";
  72.             num -= 5;
  73.         }
  74.         else if (num - 4 == 0){
  75.             romanNum += "IV";
  76.             num -= 4;
  77.         }
  78.         else if (num - 1 >= 0){
  79.             romanNum += "I";
  80.             num -= 1;
  81.         }
  82.        
  83.     }
  84.    
  85.     return romanNum;
  86. }
  87.  
  88.  
  89. int main()
  90. {
  91.     string romanNum1 = " ";
  92.     string romanNum2 = " ";
  93.     string romanResult = " ";
  94.  
  95.     int transferNum1 = 0;
  96.     int transferNum2 = 0;
  97.     int transferResult = 0;
  98.  
  99.     char oper = ' ';
  100.  
  101.  
  102.     ifstream inputfile;
  103.     inputfile.open("c:\\temp\\mp4romanletrdata.txt");
  104.    
  105.     inputfile >> romanNum1 >> romanNum2 >> oper;
  106.    
  107.  
  108.      
  109.    
  110.         for (int i = 0; i < romanNum1.length(); i++)        //first roman number convert to decimal.
  111.         {
  112.             transferNum1 += convert_from_roman_to_decimal(romanNum1[i]);    //use convert_from_roman_to_decimal function to change 1 roman number to decimal.
  113.         }
  114.         for (int i = 0; i < romanNum2.length(); i++)        //second roman number convert to decimal.
  115.         {
  116.             transferNum2 += convert_from_roman_to_decimal(romanNum2[i]);
  117.         }
  118.  
  119.  
  120.         transferResult = transferNum1 + transferNum2;
  121.         cout << transferNum1 << " " << oper << " " << transferNum2 << " = " << transferResult;
  122.  
  123.         romanResult = convert_from_decimal_to_roman(transferResult);
  124.    
  125.         cout << romanResult << endl;
  126.  
  127.  
  128.     system("pause");
  129.     return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement