1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#include<stdlib.h>
#include<string>
#include<iostream>
#include<fstream>
using namespace std ;
class checkfile
{
public :
bool is_number (string& );
private :
};
class Convert
{
public :
void ConvertToRoman (string& );
private :
};
////cpp file to check for number/////
bool checkfile::is_number(string&s)
{
for (int i = 0; i < s.length(); i++) {
if (!isdigit(s[i]))
return false;
}
return true;
}
/////cpp.file convert numbers to roman Numerals///
void Convert::ConvertToRoman(string& ArabicNumber)
{
int h,th,t,o,number;
string roman ;
number = atoi (ArabicNumber.c_str());
int number2 = 0;
int test1 = 0;
int test2 = 0;
int test3 = 0;
char *ones[] = {"","I","II","III","IV","V","VI","VII","VIII","IX"};
char *tens[] = {"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
char *hundreds[] = {"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
number2 = number / 1000;
for(int i = 1; i <= number2; i++)
cout << 'M' ;
test1 = number % 1000;
h = test1 / 100;
test2 = test1 % 100;
t = test2 / 10 ;
test3 = test2 % 10;
o = test3 / 1;
roman = roman + hundreds[h] + tens[t] + ones[o];
cout << roman << endl ;
}
///////main////
using namespace std;
int main() {
string num ;
checkfile ck ;
Convert cv;
cout << "Enter the text file please ";
cin >> num ;
ck.FileCheck(num);
if (ck.FileCheck(num) == 1)
{
cout << "File is open"<< endl ;
}
else
{
cout << "File not found" << endl;
}
fstream readFile("Test.txt");
string Numeral ;
while (getline(readFile,Numeral))
{
if (Numeral != " "){
ck.is_number(Numeral);
}
if (ck.is_number(Numeral)){
cv.ConvertToRoman(Numeral);
}
else {
cout << "it has alphabets" << endl;
}
}
}
|