Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

2. MCXVIII

image text in transcribed'

3. (Prints black screen)

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions

Question

6. Identify characteristics of whiteness.

Answered: 1 week ago

Question

e. What are notable achievements of the group?

Answered: 1 week ago