Help need to write fortran program

In summary, the programmer implemented a feature for Mrs. Deli's on-line store that allows her to report that an item has been purchased multiple times. The first line of the input file contains two integers L and N (0 is less than or equal to L is less than or equal to 100, 1 is less than or equal to N is less than or equal to 1000) and the next L lines contain the description of the irregular words and their plural form. After the list of irregular words, the remaining N lines contain one word each, which you have to make plural.
  • #1
s133kgtvr4
4
0
I have this program that needs to be written, but I don't know where to start. Can someone please help me with it.Thanks

*1 Problem Statement
Mrs. Deli is running the delicatessen store “Deli Deli”. Last year Mrs. Deli has decided to expand her business andbuild up an on-line store. She has hired a programmer who has implemented the on-line store.
Recently some of her new on-line customers complained about the electronic bills. The programmer had forgotten touse the plural form when reporting that an item is purchased multiple times. Unfortunately the programmer of Mrs.Deli is on holiday and now it is your task to implement this feature for Mrs. Deli. Here is a description how to make
the plural form:
1. If the word is in the list of irregular words replace it with the given plural.
2. Else if the word ends in a consonant followed by "y", replace "y" with "ies".
3. Else if the word ends in "o", "s", "ch", "sh" or "x", append "es" to the word.
4. Else append "s" to the word.

2 Inputs
Your program should accept a single file name as a command line parameter. This parameter will be the name of a filecontaining the all of the input data items, as described below. The file name may be as long as 256 characters.
Your program should not prompt the user for any input information.
The first line of the input file consists of two integers L and N (0 is less than or equal to L is less than or equal to 100, 1 is less than or equal to N is less than or equal to 1000)
The next L lines contain the description of the irregular words and their plural form. Each line consists of two wordsseparated by a space character, where the first word is the singular, the second word the plural form of some irregularword.
After the list of irregular words, the remaining N lines contain one word each, which you have to make plural. Youmay assume that each word consists of at most 20 lowercase letters from the English alphabet (’a’ to ’z’).

3 Outputs
All output should be written to the the default, standard, output device.
Print N lines of output, where the ith line of output is the plural form of the with input word

5.1.1 Sample Input
The contents of a file named sample_input.txt:
3 7
rice rice
spaghetti spaghetti
octopus octopi
rice
lobster
spaghetti
strawberry
octopus
peach
turkey

5.1.2 Sample Execution
Running the program (complied as the executable named deli) with the above sample data file will yield these
results:
rice
lobsters
spaghetti
strawberries
octopi
peaches
turkeys
 
Technology news on Phys.org
  • #2
wow who in the hell uses fortran to program this kind of software? what class is this you're taking? are you supposed to use f90? f95? f77?
 
  • #3
Also, who did the grammar? As I recall "octopus" has proper English "octopuses" and Latin plural "octopodes".
 
  • #4
CRGreathouse said:
Also, who did the grammar? As I recall "octopus" has proper English "octopuses" and Latin plural "octopodes".

either one
 
  • #5
This is for intro to fortran. We have to us f95/2003
 
  • #6
CRGreathouse said:
Also, who did the grammar? As I recall "octopus" has proper English "octopuses" and Latin plural "octopodes".

Merriam-Webster said:
oc·to·pus plural oc·to·pus·es or oc·to·pi

But seriously, why do this in Fortran?? Fortran's strength is not string processing. I predict even Fortran-2050 will be weak in string processing. Good luck.
 
  • #7
Just be thankful it's not FORTRAN IV...
 
  • #8
That will be a pain in the ass. Good luck.

I'd start with the irregular word first, since you can go through the list and just compare whether or not yourWord == word1, word2, etc. until you find it and replace it.

Playing around with the individual characters will NOT be fun. I haven't done any string processing in F, only C++, but I remember a string being an array of characters, right? so you'd have to check the last 1 or two characters and just add more to the array or change some characters. I don't know whether or not String is a dynamic array or just has a set limit of characters, but you should probably copy your word array into a new one with x + 2 (for ies or es) slots and work your magic there.
 
  • #9
Well Fortran is mostly developed for scientific calculations, but I think string processing is not very hard if you know how to it. Fortran doesn't have the String datatype but instead an array of characters. So if you want to have a word with l characters you define the type as
character(len=l)::word.

So in the problem you need to define word as a character array with l=maximum length a word can have.
The characters i to j in the array word can be changed by
word(i:j)="..."

So now I think it's quite easy for you too go further.
 

1. What is FORTRAN and why is it important in scientific programming?

FORTRAN (short for Formula Translation) is a high-level programming language used for scientific and engineering applications. It was one of the first programming languages to be developed and is still widely used today due to its efficiency in handling complex mathematical and scientific calculations. Many legacy codes and libraries are written in FORTRAN, making it an important language for scientific programming.

2. How do I get started with writing a FORTRAN program?

To write a FORTRAN program, you will need a text editor and a compiler. The most commonly used compiler for FORTRAN is GNU Fortran (GFortran), which is available for free on various platforms. You can also use an Integrated Development Environment (IDE) such as Eclipse with a FORTRAN plugin for a more user-friendly experience.

3. What are the basic syntax and structure of a FORTRAN program?

A FORTRAN program is made up of a series of statements, each of which is written on a separate line. A simple program starts with a program statement and ends with an end statement. The main body of the program is written between these two statements, and each line of code should end with a semicolon. FORTRAN follows a strict column-based formatting, where the first six columns are reserved for line numbers and the remaining columns are for the code.

4. How do I input and output data in a FORTRAN program?

Input and output in FORTRAN are done using the READ and PRINT statements, respectively. The READ statement is used to read data from a specified input device, such as the keyboard or a file, while the PRINT statement is used to display data on the screen or write it to a file. You can also use the WRITE statement to format and write data to a file.

5. Can I use modern programming techniques in FORTRAN?

Yes, FORTRAN has evolved over the years, and the latest version (FORTRAN 2018) includes many modern programming features such as object-oriented programming, parallel processing, and interoperability with other programming languages. However, some legacy codes may still use older versions of FORTRAN and may not support these modern techniques.

Similar threads

  • Programming and Computer Science
2
Replies
65
Views
2K
  • Programming and Computer Science
3
Replies
75
Views
4K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
1
Views
2K
Back
Top