Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Help! need to write fortran program

  1. Mar 17, 2008 #1
    I have this program that needs to be written, but I dont 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

    5.1.2 Sample Execution
    Running the program (complied as the executable named deli) with the above sample data file will yield these
  2. jcsd
  3. Mar 19, 2008 #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?
  4. Mar 19, 2008 #3


    User Avatar
    Science Advisor
    Homework Helper

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

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    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.
  8. Apr 1, 2008 #7
    Just be thankful it's not FORTRAN IV...
  9. Apr 1, 2008 #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.
  10. Apr 12, 2008 #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

    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

    So now I think it's quite easy for you too go further.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook