Question
Can somebody help me loop this C++ project? I have written a code using random file access techniqes that translates roman numerals to arabic numbers
Can somebody help me loop this C++ project?
I have written a code using random file access techniqes that translates roman numerals to arabic numbers and arabic numbers to roman numerals from an input file named "newnum.txt". Each line of the file has the same format of (i.e. Roman Numeral field has 15 characters and Arabic Numeral field has 4 characters). When I insert the roman numeral MCXVIII from one line into my project it translates to Arabic and when I insert 1965 from 16 character spaces via first line it translates to roman numeral. However, when I try to have roman and arabic numerals on multiple lines in the file I get a black screen and unsure why?
By the way, if a field does not hold a value it has all spaces. If the Roman numeral field contains a space as 1st character, the line has an Arabic numeral.
Test Cases:
1. 1951
2. MCXVIII
'
3. (Prints black screen)
code:
#include
#include #include #include #include using namespace std;
int main() { string roman_val; int digits; int thous; int hunds; int tens; int ones; int i; int total_numerical=0; int curr_numerical=0; int prev_numerical=0; long int pointer=0; int record_num=0; string record; //To hold record read as a string bool eof = false; fstream file("newnum.txt",ios::in); if (!file.fail()) {
file.seekg(0L, ios::beg); //start at beginning of file getline(file, record); //read the first record while(!eof) { record_num++; if(record.length()
} } cout
//cout
} if (record[0] == ' ') { file.seekg(16L, ios::beg); pointer=file.tellg(); getline(file,record); cout > curr_numerical;
if (curr_numerical>999) { thous=curr_numerical/1000; switch(thous) { case 3: roman_val[0]='M'; roman_val[1]='M'; roman_val[2]='M'; digits=3; cout
switch(hunds) { case 1: roman_val[digits]='C'; digits=digits+1; break; case 2: roman_val[digits]='C'; roman_val[digits+1]='C'; digits=digits+2; break; case 3: roman_val[digits]='C'; roman_val[digits+1]='C'; roman_val[digits+2]='C'; digits=digits+3; break; case 4: roman_val[digits]='C'; roman_val[digits+1]='D'; digits=digits+2; break; case 5: roman_val[digits]='D'; digits=digits+1; break; case 6: roman_val[digits]='D'; roman_val[digits+1]='C'; digits=digits+2; break; case 7: roman_val[digits]='D'; roman_val[digits+1]='C'; roman_val[digits+2]='C'; digits=digits+3; break; case 8: roman_val[digits]='D'; roman_val[digits+1]='C'; roman_val[digits+2]='C'; roman_val[digits+3]='C'; digits=digits+4; break; case 9: roman_val[digits]='C'; roman_val[digits+1]='M'; digits=digits+2; cout
} cout
cout
} } file.close(); //cout string read 1951 the pointer is at =16 Got to case 1 sting= M =String at thousand compare = - Got to case 9 string=M String at hundred compare = Got to case 5 string=M String at tens compare = Got to case 1 string=M String at ones compare =M complete string = MCMLI Final numbere Process returnede (exe) execution time: 8.543 s, Press any key to continue
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started