CSC 270

Homework 3
assigned 22 Oct, due 12 Nov

Modify your previous calculator program (homework 1 or 2) to work with strings rather than numbers. You should be able to do this by writing two functions named "read_string" and "write_string" (or something like that) and calling them in place of some of the calls to "scanf" and "printf" in your old program, as well as writing functions named "add_string", "sub_string", and "mult_string" to do the corresponding operations on strings.

The user will type an operator (+, -, or *), then two strings, each enclosed in double-quote marks. The program will print out the answer, also in double-quote marks, in a suitably informative format. Try to include the input strings in the output, as in the examples below. (This can be tricky; if you don't get it to work, turn in the program without the input strings repeated in the output.)

So, you may ask, what do "+", "-", and "*" mean for strings? For the purposes of this program,

The grading criteria are roughly the same as for homework 1.

I recommend working on the parts of the program in the following order:

  1. write, test, and debug functions to read and print a string. (To test this, have each of your operators return the string "xyz" or something like that regardless of what operands you gave them.)
  2. write, test, and debug the "add_string" function, which concatenates strings.
  3. write, test, and debug the "sub_string" function, which deletes all characters in the second from the first.
  4. write, test, and debug the "mult_string" function, which does the weird stuff with the two-dimensional array and the bitwise OR.

Last modified: Tue Oct 22 11:47:10 EDT 1996
Stephen Bloch /