Lecture notes for the Introduction to Computer Science I by James Tam Return to the course web page

CPSC 231: Assignment 6 (Worth 5%)

Score Grade
67 - 70 A
63 - 66 A-
59 - 62 B+
55 - 58 B
51 - 54 B-
46 - 50 C+
41 - 45 C
36 - 40 C-
31 - 35 D+
21 - 30 D
11 - 20 D-
0   - 10 F

New concepts to be applied for the assignment

  1. One-dimensional character arrays

Write a program to perform text analysis

Your program implements a string as a 9 element character array that up to 8 characters as input. The last occupied array element (1 - 8) will be followed by a special character (ASCII value 32/space) that marks the end of the array e.g., if the user typed in 8 characters then the 9nth element would contain a blank space.  Your program starts by describing the string function that were implemented and it ends with brief parting message.   In between it will prompt the user to enter in a string of characters which is to be eventually stored in the character array.  (JT's note: to make it easier to complete Feature #8, you may want to read the information one character at a time into a temporary character variable with the 'read' procedure before you actually copy the information into each successive element of the array to avoid overflowing the bounds of the array if the user types in more than 8 characters - any extra characters beyond the 8th won't be read into the array).   As usual the user signals to your program that he or she has finished inputting the information by hitting the 'enter' key so the last character will be the end-of-line marker (EOL) which this particular compiler stores as ASCII 32 (if displayed onscreen it appears as a space).  This last character is to be read into the string but your program should not display it onscreen.  

Here's how to picture the process:

Supposed that the user typed in 'abc' and then hit enter.  The stream of characters that were typed in will be stored in some temporary memory location (typically computers have a keyboard buffer to store this information):

First character

Second character

Third character

Fourth character

'a' (ASCII 97)

'b' (ASCII 98)

'c' (ASCII 99)

EOL/SPACE (ASCII 32)

 

 

 

Successively read each of these characters up to and including the character with an ASCII value of 32 into a temporary character variable.  Successively copy the character from the temporary variable into each element of your character array.  Your program stop the copy process when the array is already full to avoid overflow).

 
 

 

Array element[1]

Array element[2]

Array element [3]

Array element[4]

Array element [5]

...

Array element [9]

'a'

'b'

'c'

EOL/SPACE

Not occupied

...

Not occupied

When your program displays the array onscreen it should display all the characters except for the character containing the EOL/SPACE (to do this your program must explicitly check for and avoid displaying this value)  Thus the EOL/SPACE character is used to mark the end of the input.  You can assume that the strings entered by the user will not explicitly contain a space (and it is acceptable if your program treats any spaces entered by the user as the end of input so it won't read in any values that follow the space).  If the user just hits enter when prompted to type in their string of characters then the program will treat this as a empty string (nothing to analyze so two operations will not work). Operations that should be implemented for non-empty strings include:

  1. Count: The user will be prompted to enter a string of characters followed by a single character. The program will then count the number of occurrences of the the letter in the string.

  2. Length: The user will be prompted to enter a string of characters and the program will count the number of characters in the string (excluding the EOL/space at the end).

  3. Replace: The user will be prompted to enter a string of characters and then prompted twice to enter a single character. The first character will be the character to be replaced (search character) while the second character will be the character that acts as a replacement. For example if the user entered the string: 'ababab' and 'a' as the character to be replaced and 'A' as the replacement character the program would replace all instances of lower case 'a' with upper case 'A' to yield the string 'AbAbAb'.

In the case of count and replace, because the space character marks the end of the string

Features to be implemented (you will also be graded on other criteria such as coding style and providing program documentation as listed in the marking guide):

 
  1. The first time that program is run it displays an introduction with a brief description of the features: 1 mark
 
  1. When the user quits the program it displays a brief conclusion/signoff message: 1 mark
 
  1. Program shows a menu of the main features of the program (count, length and replace): 1 mark
 
  1. Declares a new type 'MyString' as a one-dimensional character array: 1 mark
 
  1. Declares an instance of type 'MyString': 1 mark
 
  1. Can read user input into this instance of 'MyString': 1 mark
 
  1. Can display the contents of this instance of 'MyString': 1 mark
 
  1. Error prevention: Program prevents overflow of the array, it will count the number of characters entered by user and stop reading after the 8th character: 6 marks
 
  1. Count: After the user enters a string and a character, the program can count the number of occurances of that character: 6 marks
 
  1. Length: Determines the length of the string entered by the user (excluding the space): 6 marks
 
  1. Replace: After the user enters a string and a search character and a replacement character, the program can replace all occurances of the search character with the replacement character: 6 marks
 
  1. General error checking: Can determine when an empty string has been entered (e.g., the user hits enter without typing in a string) and when one is encountered the program will not count occurances of letters nor will it perform a search and replace. The length of the string will be zero characters: 6 marks
 
  1. Error checking, counting occurances: Can determine when the user tries to count the number of occurances of the space and in such a case the program will display an error message and not perform the count: 3 marks
 
  1. Error checking, search and replace: Can determine when the user enters a space as the search character and in such a case the program will display an error message and not perform the search and replace: 3 marks
 
  1. Error checking, search and replace: Can determine when the user enters a space as the replacement character and in such a case the program will display an error message and not perform the search and replace: 3 marks

Submission requirements

In addition to having fulfill the generic assignment requirements, the requirements specific to this assignment include:

  1. Include a README file in your submission:  For this assignment you need to include a file called 'README' which includes your contact information: your name, university identification number and UNIX login name as well as all the features of the program that you implemented so that your marker knows whose assignment that he or she is marking and what features to look for.

  2. Assignments (source code/'dot-p' file and the README file) must be electronically submitted.  In addition a paper print out of the source code and README must be handed into the assignment drop box (located on the second floor of the Math Sciences building) for the tutorial that you are registered in.  Electronically submitting the assignment allows your marker to compile and run the code in order to quickly determine what features were implemented.  Providing a paper printout makes it easier for your marker to read and flip through your source code. 

  3. As a reminder, you are not allowed to work in groups for this class.   Copying the work of another student will be regarded as academic misconduct (cheating).  For additional details about what is and is not okay for this class please refer to the following link.

To help make sure that you haven't missed anything here is a checklist of items to be used in marking. A sample executable 'analyzer' can be found in UNIX under the directory: /home/231/tamj/assignments/assignment6.