CS 1001 Assignment 6
Assigned: Tuesday, April 25, 2000   Due: Wednesday, May 3, 2000


Problem

Write a set of subroutines to do the following:
a.     delete a substring from a source string
b.     insert a new string in a source string at a specified position
c.     indicate where a specified target string occurs in the source string
d.     replace the first occurrence of a specified substring in a source string with another

Test these procedures by writing a text editor and performing several editing operations.  The editor should be driven by the following menu:

    Enter the first letter of an edit operation described as follows:

D - Delete a substring
E - Enter a source string to be edited
I - Insert a substring
L - Locate a substring
P - Print the source string
R - Replace one substring with another
S - Show the menu
Q - Quit
 

A sample run of the program is given here to clarify how the program should behave:

%a.out
              Text Editor Program

 You will be able to edit text by choosing from the
 following list of commands:

 Enter

      D to delete a substring from the source string
      E to enter a source string to be edited
      I to insert a substring in the source string
           at a specified position
      L to locate the position of a substring in the
           source string
      P to print the source string
      R to replace one substring with another
      S to show this menu
      Q to quit

 What is your choice?
e
 Enter string

This*is*a*string.

 What is your choice?
d
 Enter string to be deleted
is

 What is your choice?
p
 Th*is*a*string.

 What is your choice?
l
 Enter string to locate
*is

 What is your choice?
i
 Enter string to be inserted
at

 What is your choice?
p
 That*is*a*string.

 What is your choice?
r
 Enter old string
is

 Enter new string
is*not

 What is your choice?
p
 That*is*not*a*string.

 What is your choice?
d
 Enter string to be deleted
thing
 string not found
 

 What is your choice?
p
 That*is*not*a*string.

 What is your choice?
i
 Enter string to be inserted
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 Can't insert; string would exceed 80 characters
 

 What is your choice?
i
 Enter string to be inserted
+++

 What is your choice?
p
 Th+++at*is*a*string.

 What is your choice?
q
 

Assumptions and Restrictions

You should assume that the maximum size of a string is 80 characters. The string that is being edited should, therefore, be declared in the main program as
      CHARACTER (80) ::  string
and all changes to the string will be implemented using the string subprograms defined in Chapter 11.

Hints

We will go over the string functions Thursday 4/7.  There is an example of a text editor on pages 781-785 of the text
Each of the menu items should be implemented in a separate subroutine. Rather than try to write the entire program at once, approach it incrementally: implement the Enter and Print subroutines first, then add the others one at a time, thoroughly testing each one before you attempt the next. When using an incremental approach like this, the subroutines that aren't functional yet are usually written as ``stubs'' (pp. 459).

Grading

This assignment will be graded based on 100 points. Point values will be allocated as follows:
Documentation
(20 points) Introductory comment, meaningful identifiers, proper use of indentation and blank lines, comments for variables, algorithm comments. Each subprogram must be adequately commented, including pre- and post-conditions!
Functionality
(50 points) The program must work correctly on our test data.
Modularity and Design
(10 points) The main program should be simple and easy to follow. Each menu item should be implemented as a separate subprogram. Parameters must be used to pass information to the subprograms.
Error handling and Testing
(20 points) See the sample execution for ideas; each subprogram should check for and report error conditions. The script file should show thorough testing of the program.

 

Deliverables

Using turnin, turn in your Fortran source file and a script file showing successful compilation and program execution. Your files must be turned in prior to 12:00 pm on Wednesday, May 3.  The command you should use to turn in your files is

/cs/bin/turnin submit cs1001 hw6 hw6.f90 hw6.script