UMBC CMSC 201, Computer Science I, Fall 1995 Sections 0101, 0102, 0103 and Honors

Project 5 Comments


Announcements:


Comments:

Prof. Chang,
I have a question about project 5. You said that fractions cannot have spaces within the numerator and the denominator. I have written code to ensure that there is no white space within the numerator with no problem. The problem I'm having is thinking of how to write code to prevent from thinking that a fraction like:
   24/  1 35
   
is not 24/1. Do we just assume that the user will not enter an illegal denominator or should I keep trying to think of a safeguard?

Dear Student,
In this case, your function should store 24/1 as the result and return the index of the space after the 1. The point is that if ScanFraction is included as part of Project 4, then the error will be detected when the main program looks for an operator and finds "35" instead.

Prof. Chang,
For project 5, can we use a second function to take out spaces, or do you want everything in ScanFraction???

Dear Student,
You can use a second function, but you probably don't want to take out the spaces, because you have to report the new position in the original string.

For example:

  ScanFraction ("abc  12/34  xyz", 4, &f)
  
must return the index 10, because it is the position of the space after 12/34. If you take out all of the spaces, you won't know what the position is. Note that there may be several spaces between "abc" and "12/34".

Prof. Chang,
I was wondering for project 5 what was considered a fraction. Is it the presense of a '/' character?

Dear Student,
A fraction is a sequence of spaces, followed by a sequence of digits, followed by a sequence of spaces, followed by a '/', followed by a sequence of spaces, followed by a sequence of digits. The spaces are optional, but your function must correctly calculate the new position.

Prof. Chang,
What is ScanFraction suppose to do when there is more than 1 fraction in the string? For example, given the string
  "    3/8    3/9 bec"
  
and the index 0, should ScanFraction take both fractions?

Dear Student,
How can ScanFraction take both fractions? where would it store the resutlts? ScanFraction should take the first fraction after the index given by the parameter and return the position after that fraction. So, in your example, you should store 3/8 in the pointer and return 7.

Last Modified: Fri Dec 1 08:28:00 EST 1995

Richard Chang, chang@gl.umbc.edu