progrm for converting integers to roman numerals using files in clanguage

K

kotlakirankumar

please help me out the program for converting the integers to roman
numerals using files in the c language from 1-5000 range send the
program to my
mail id ::::::: (e-mail address removed)
thank you all
 
R

Richard Heathfield

(e-mail address removed) said:
please help me out the program for converting the integers to roman
numerals using files in the c language from 1-5000 range send the
program to my
mail id

Are you sure you're on the right course? You might find management more to
your liking than programming.
 
S

santosh

please help me out the program for converting the integers to roman
numerals using files in the c language from 1-5000 range send the
program to my
mail id ::::::: (e-mail address removed)
thank you all

You are joking right?

No one is going to do your homework for you. Besides shirking at this
stage is going to leave you looking a fool later on. Post some
semblance of an attempt and you might likely get good help.
 
S

Sjouke Burry

please help me out the program for converting the integers to roman
numerals using files in the c language from 1-5000 range send the
program to my
mail id ::::::: (e-mail address removed)
thank you all
Dork.
 
K

Keith Thompson

please help me out the program for converting the integers to roman
numerals using files in the c language from 1-5000 range send the
program to my
mail id ::::::: (e-mail address removed)
thank you all

Give us your instructor's e-mail address, and we'll be glad to send
the solution directly to him. For a nominal fee, we'll mention your
name.
 
M

Mark Bluemel

Keith said:
Give us your instructor's e-mail address, and we'll be glad to send
the solution directly to him. For a nominal fee, we'll mention your
name.
For a larger fee we will fake the mail to appear to come from you.
 
R

Randy Howard

please help me out the program for converting the integers to roman
numerals using files in the c language from 1-5000 range send the
program to my
mail id ::::::: (e-mail address removed)

As soon as $1000 hits my paypal account I'll send the solution. Have a
nice day.
 
N

Nick Keighley

please help me out  the program for converting the integers to roman
numerals using files in the c language from 1-5000 range send the
program to my
 mail id :::::::    (e-mail address removed)
  thank you all

what does "using files" mean? Can't we dream up a bizzare way of
implementing this? Use file names to store the numbers?

I.dat contains 1
V.dat contains 10
etc.

or
1.dat contains I
5.dat contains V

<pause>

spilt the input into "decades" number 1000's number of 100's
then use the number to generate a filename. Which contains the
answer.

0 -> <empty>
1 -> "I"
2 -> "II"

no probably too silly.

To the OP. Do it on paper first.
 
E

Eric Sosman

please help me out the program for converting the integers to roman
numerals using files in the c language from 1-5000 range send the
program to my
mail id ::::::: (e-mail address removed)

Ask here, get answers here.

#include<stdio.h>
#define LO 1
#define HI 5000
#define SPAN(min,max)(1-((max)-(min)))
static char*r[SPAN(HI,LO)]={"I","II","III",
/* ... fill in remaining values here ... */
"MMMMCMXCVIII","MMMMCMXCIX","?"};
int main(int argc,char**argv){
if(argv!=r)return main(SPAN(HI,LO),r);
for(puts(*argv);--argc;puts(*++argv));
return argc;
}
 
B

Bart C

Eric Sosman said:
please help me out the program for converting the integers to roman
numerals using files in the c language from 1-5000 range send the
program to my
mail id ::::::: (e-mail address removed)

Ask here, get answers here.

#include<stdio.h>
#define LO 1
#define HI 5000
#define SPAN(min,max)(1-((max)-(min)))
static char*r[SPAN(HI,LO)]={"I","II","III",
/* ... fill in remaining values here ... */
"MMMMCMXCVIII","MMMMCMXCIX","?"};

Above 1000 you use V, X, L etc with a 'bar' over to scale by 1000.

So not so easy, unless you use a convention like /V.

And the 4000 above looks better as MV-Bar I think. Might be wrong though.
 
R

Randy Howard

Eric Sosman said:
please help me out the program for converting the integers to roman
numerals using files in the c language from 1-5000 range send the
program to my
mail id ::::::: (e-mail address removed)

Ask here, get answers here.

#include<stdio.h>
#define LO 1
#define HI 5000
#define SPAN(min,max)(1-((max)-(min)))
static char*r[SPAN(HI,LO)]={"I","II","III",
/* ... fill in remaining values here ... */
"MMMMCMXCVIII","MMMMCMXCIX","?"};

Above 1000 you use V, X, L etc with a 'bar' over to scale by 1000.

So not so easy, unless you use a convention like /V.

And the 4000 above looks better as MV-Bar I think. Might be wrong though.

How about:

_ _ _
V X L

etc.
 
A

Army1987

Bart said:
Above 1000 you use V, X, L etc with a 'bar' over to scale by 1000.

So not so easy, unless you use a convention like /V.

And the 4000 above looks better as MV-Bar I think. Might be wrong though.
__
4000 is IV, though MMMM is also used (but becomes awkward for larger
numbers. _
Numbers from one million onwards are written as |X|, the "box" multiplying
by 10**5.
 
C

CBFalconer

Keith said:
Give us your instructor's e-mail address, and we'll be glad to
send the solution directly to him. For a nominal fee, we'll
mention your name.

It's actually quite simple. Simply list the 5000 Roman values in
order, i.e.:

I
II
III
IV
...
IMMMMM
MMMMM

and put those strings into the array ROMANS. i.e.:

char *romans[] = ( /* here the above comma separated set */ );
/* Don't forget to quote each string. */

Now the conversion and printing is simply:

/* write i in roman numerals */
int iwrite(i) {
return puts(roman[i - 1]);
}

which returns EOF for any i/o error, else a positive int.
 
J

John J. Smith

please help me out

Here you go...
the program for converting the integers to roman
numerals using files in the c language from 1-5000 range

Find below the portable C source code for a program that will print
all roman numerals from 0 to 5000. Changing the code so it starts
with 1 is left as an exercise.

[snips]
thank you all

You're welcome.

Here comes the code...

/*
* runum.c
*
* Copyright (c) 2008, John J. Smith
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose except in homework assignments
* is hereby granted without fee, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation.
*
*/

/*
* Requirements:
*
* the program for converting the integers to roman
* numerals using file(s) in the c language from 1-5000 range
*
*/

#include <stdio.h>
#include <string.h>

/*
* the biggest foobarfoobar that foofoobarbar will accept
*/
#define MAX_FOOBARFOOBAR 5000

#define M 1000
#define D 500
#define C 100
#define L 50
#define X 10
#define V 5
#define I 1
#define N 0

/*
* struct: foofoofoofoo
*
* purpose: map foofoofoobar values to their corresponding
* foofoobarfoo values
*
*/
#define M1(a) { #a , (a) }
#define M2(a,b) { #a #b , (b)-(a) }

static struct {
char *foofoofoobar;
int foofoobarfoo;
} foofoofoofoo[] = {
M1(M),M2(C,M),M1(D),M2(C,D),M1(C),M2(X,C),M1(L),
M2(X,L),M1(X),M2(I,X),M1(V),M2(I,V),M1(I),M1(N),
};
#define N_FOOFOOFOOFOO \
((sizeof foofoofoofoo) / (sizeof foofoofoofoo[0]))

#undef M1
#undef M2

static int ConstraintFailed(void) { return -1; }

/*
* function: foofoobarbar
*
* purpose: convert a foobarfoobar value to foobarbarfoo
*
* parameters:
* foobarfoobar: value to be converted
* foobarbarfoo: buffer that receives the converted foobarfoobar
*
* notes:
* it is the callers responsiblility that foobarbarfoo is
* sufficiently large
*/
static int foofoobarbar(int foobarfoobar, char *foobarbarfoo)
{
int barfoobarfoo = 0;
size_t barbarfoofoo;
char *foobarbarbar;

if(foobarfoobar < 0 || foobarfoobar > MAX_FOOBARFOOBAR) {
barfoobarfoo = ConstraintFailed();
strcpy(foobarbarfoo, "ERROR!"); goto barfoobarbar;
}
else if(foobarfoobar == 0) {
strcpy(foobarbarfoo, "N"); goto barfoobarbar;
}

for(foobarbarbar = foobarbarfoo, *foobarbarbar = 0, barbarfoofoo = 0;
barbarfoofoo < N_FOOFOOFOOFOO-1; barbarfoofoo++) {
while(foobarfoobar >= foofoofoofoo[barbarfoofoo].foofoobarfoo) {
char *barfoofoofoo = foofoofoofoo[barbarfoofoo].foofoofoobar;
size_t barfoofoobar = strlen(barfoofoofoo);
memcpy(foobarbarbar, barfoofoofoo, barfoofoobar);
foobarbarbar += barfoofoobar;
foobarfoobar -= foofoofoofoo[barbarfoofoo].foofoobarfoo;
}
}
*foobarbarbar = '\0';

barfoobarbar:
return barfoobarfoo;
}

/*
* function: foobarfoofoo
*
* purpose: as per spec, use file foobarfoobar
*
* parameters: (none)
*/
static int foobarfoofoo(void)
{
FILE *foobarfoobar;
printf("Using file... ");
if((foobarfoobar = tmpfile()) != NULL) {
printf("success!!!\n");
fclose(foobarfoobar);
return 0;
} else {
printf("failed.\n");
return 1;
}
}


/*
* function: main
*
* purpose: program's entry point
* invokes foofoobarbar() MAX_FOOBARFOOBAR times
*/
int main(void)
{
int foobarfoobar;
char foobarbarfoo[64];

printf("John's Table of Roman Numerals\n"
"Copyright (c) MMVIII, John J. Smith\n\n");
foobarfoofoo();
printf("\n"
" arabic | roman\n"
"--------+----------------------\n");
for(foobarfoobar = 0;
foobarfoobar <= MAX_FOOBARFOOBAR;
foobarfoobar++) {
foofoobarbar(foobarfoobar, foobarbarfoo);
printf(" %5d | %s\n", foobarfoobar, foobarbarfoo);
}
return 0;
}

/* end ronum.c */
 
H

Hans Schneider

please help me out

Here you go...
the program for converting the integers to roman
numerals using files in the c language from 1-5000 range

Find below the portable C source code for a program that will print
all roman numerals from 0 to 5000. Changing the code so it starts
with 1 is left as an exercise.

[snips]
thank you all

You're welcome.

Here comes the code...

Does not compile with LCC-WIN32...

|
|Error ronum.c: 62 redefinition of 'ConstraintFailed'
|Error c:\lcc\include\safelib.h: 3 Previous definition of 'ConstraintFailed' here
|Warning ronum.c: 62 inconsistent linkage for 'ConstraintFailed' previously declared at c:\lcc\include\safelib.h 3
|2 errors, 1 warning
|1 error
|

(and I don't even know what "safelib.h" is. Program or compiler problem?)

/*
* runum.c
*
* Copyright (c) 2008, John J. Smith
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose except in homework assignments
* is hereby granted without fee, provided that the above copyright
* notice appear in all copies and that both that copyright notice and
* this permission notice appear in supporting documentation.
*
*/

/*
* Requirements:
*
* the program for converting the integers to roman
* numerals using file(s) in the c language from 1-5000 range
*
*/

#include <stdio.h>
#include <string.h>

/*
* the biggest foobarfoobar that foofoobarbar will accept
*/
#define MAX_FOOBARFOOBAR 5000

#define M 1000
#define D 500
#define C 100
#define L 50
#define X 10
#define V 5
#define I 1
#define N 0

/*
* struct: foofoofoofoo
*
* purpose: map foofoofoobar values to their corresponding
* foofoobarfoo values
*
*/
#define M1(a) { #a , (a) }
#define M2(a,b) { #a #b , (b)-(a) }

static struct {
char *foofoofoobar;
int foofoobarfoo;
} foofoofoofoo[] = {
M1(M),M2(C,M),M1(D),M2(C,D),M1(C),M2(X,C),M1(L),
M2(X,L),M1(X),M2(I,X),M1(V),M2(I,V),M1(I),M1(N),
};
#define N_FOOFOOFOOFOO \
((sizeof foofoofoofoo) / (sizeof foofoofoofoo[0]))

#undef M1
#undef M2

static int ConstraintFailed(void) { return -1; }

/*
* function: foofoobarbar
*
* purpose: convert a foobarfoobar value to foobarbarfoo
*
* parameters:
* foobarfoobar: value to be converted
* foobarbarfoo: buffer that receives the converted foobarfoobar
*
* notes:
* it is the callers responsiblility that foobarbarfoo is
* sufficiently large
*/
static int foofoobarbar(int foobarfoobar, char *foobarbarfoo)
{
int barfoobarfoo = 0;
size_t barbarfoofoo;
char *foobarbarbar;

if(foobarfoobar < 0 || foobarfoobar > MAX_FOOBARFOOBAR) {
barfoobarfoo = ConstraintFailed();
strcpy(foobarbarfoo, "ERROR!"); goto barfoobarbar;
}
else if(foobarfoobar == 0) {
strcpy(foobarbarfoo, "N"); goto barfoobarbar;
}

for(foobarbarbar = foobarbarfoo, *foobarbarbar = 0, barbarfoofoo = 0;
barbarfoofoo < N_FOOFOOFOOFOO-1; barbarfoofoo++) {
while(foobarfoobar >= foofoofoofoo[barbarfoofoo].foofoobarfoo) {
char *barfoofoofoo = foofoofoofoo[barbarfoofoo].foofoofoobar;
size_t barfoofoobar = strlen(barfoofoofoo);
memcpy(foobarbarbar, barfoofoofoo, barfoofoobar);
foobarbarbar += barfoofoobar;
foobarfoobar -= foofoofoofoo[barbarfoofoo].foofoobarfoo;
}
}
*foobarbarbar = '\0';

barfoobarbar:
return barfoobarfoo;
}

/*
* function: foobarfoofoo
*
* purpose: as per spec, use file foobarfoobar
*
* parameters: (none)
*/
static int foobarfoofoo(void)
{
FILE *foobarfoobar;
printf("Using file... ");
if((foobarfoobar = tmpfile()) != NULL) {
printf("success!!!\n");
fclose(foobarfoobar);
return 0;
} else {
printf("failed.\n");
return 1;
}
}


/*
* function: main
*
* purpose: program's entry point
* invokes foofoobarbar() MAX_FOOBARFOOBAR times
*/
int main(void)
{
int foobarfoobar;
char foobarbarfoo[64];

printf("John's Table of Roman Numerals\n"
"Copyright (c) MMVIII, John J. Smith\n\n");
foobarfoofoo();
printf("\n"
" arabic | roman\n"
"--------+----------------------\n");
for(foobarfoobar = 0;
foobarfoobar <= MAX_FOOBARFOOBAR;
foobarfoobar++) {
foofoobarbar(foobarfoobar, foobarbarfoo);
printf(" %5d | %s\n", foobarfoobar, foobarbarfoo);
}
return 0;
}

/* end ronum.c */
 
F

Flash Gordon

Hans Schneider wrote, On 27/01/08 03:15:
please help me out
Here you go...
the program for converting the integers to roman
numerals using files in the c language from 1-5000 range
Find below the portable C source code for a program that will print
all roman numerals from 0 to 5000. Changing the code so it starts
with 1 is left as an exercise.

[snips]
thank you all
You're welcome.

Here comes the code...

Does not compile with LCC-WIN32...

|
|Error ronum.c: 62 redefinition of 'ConstraintFailed'
|Error c:\lcc\include\safelib.h: 3 Previous definition of 'ConstraintFailed' here
|Warning ronum.c: 62 inconsistent linkage for 'ConstraintFailed' previously declared at c:\lcc\include\safelib.h 3
|2 errors, 1 warning
|1 error
|

(and I don't even know what "safelib.h" is. Program or compiler problem?)

<snip>

If you put the compiler in to conforming mode (-ansic is I think the
switch) then it is a compiler problem. If not then I would still say it
is a compiler problem, but it could be a deliberate feature.

C code is allowed to use the identifier ConstraintFailed for anything it
wants.
 
M

Mark McIntyre

Hans said:
Does not compile with LCC-WIN32...

|
|Error ronum.c: 62 redefinition of 'ConstraintFailed'
|Error c:\lcc\include\safelib.h: 3 Previous definition of 'ConstraintFailed' here

Bug in lcc-win32, or you're not invoking it in conforming mode.

ConstraintFailed is a valid identifier which lcc-win32 happens to use
in some implementation-specific library. You need to disable compiler
extensions.
 
S

santosh

Hans said:
please help me out

Here you go...
the program for converting the integers to roman
numerals using files in the c language from 1-5000 range

Find below the portable C source code for a program that will print
all roman numerals from 0 to 5000. Changing the code so it starts
with 1 is left as an exercise.

[snips]
thank you all

You're welcome.

Here comes the code...

Does not compile with LCC-WIN32...

|
|Error ronum.c: 62 redefinition of 'ConstraintFailed'
|Error c:\lcc\include\safelib.h: 3 Previous definition of
|'ConstraintFailed' here
|Warning ronum.c: 62 inconsistent linkage for 'ConstraintFailed'
|previously declared at c:\lcc\include\safelib.h 3 2 errors, 1 warning
|1 error
|

(and I don't even know what "safelib.h" is. Program or compiler
problem?)

Please post problems with lcc-win32 to <where
it's author will be able to address them.

PS. I'm surprised that jacob is using an user-space identifier in his
implementation, even in non-conforming mode. Unfortunately I have not
got Windows, so I cannot check this myself at the moment.

<snip code>
 
B

Bartc

Does not compile with LCC-WIN32...
(and I don't even know what "safelib.h" is. Program or compiler
problem?)

This worked fine for me. Although had to rename the ConstraintFailed
function.

safelib.h seems to be used in the string.h header.

And the output seems fine apart from slight quibble of using MMMMM for 5000.
 
C

Coos Haak

Op Sun, 27 Jan 2008 19:14:38 GMT schreef Bartc:
This worked fine for me. Although had to rename the ConstraintFailed
function.

safelib.h seems to be used in the string.h header.

And the output seems fine apart from slight quibble of using MMMMM for 5000.

Slight? Everything from 4000 onwards had at least four M's in a row ;-)
Perhaps the Romans used a wide (high) character set, the A in ASCII surely
wasn't known then.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top