CS21 Spring 2005 Homework 10

Due Sunday, April 3 (before 11:30pm)


Complete the following two programs:

  1. Write a program that reads in a number entered by the user as a string, and prints out the number as words. A valid input number should be in the form of a float literal (but not in scientific notation). For example:
    % ./a.out
    Please enter a number: -12345.67
    The number you entered was: negative one two three four five dot six seven
    
    % ./a.out
    Please enter a number: -123.abcd
    The number you entered was: invalid 
    
    Use good modular design in your solution. Run valgrind on your solution to find and fix all memory access errors.
    % valgrind --leak-check=yes --show-reachable=yes ./a.out
    

  2. Write a program that reads in two lines entered by the user into two different strings. It then calls a function, EqualNoPuncCase, that returns true if two input strings are equal ignoring (1) whitespace (2) the case of alphabetic characters (upper or lower) and (3) punctuation. Your function should NOT modify either input string. For example:
    % ./a.out
    This program computes the equality of two input strings
    ignoring whitespce, punctuation, and case
    
    Please enter the first line :          Danger!!!       Danger,     Dr.   Smith.
    Please enter the second line :  dANGER DAnger dr SMITH
    
    Ignoring whitespace, punc & case, the strings you entered are: EQUAL
    
    % ./a.out
    This program computes the equality of two input strings
    ignoring whitespce, punctuation, and case
    
    Please enter the first line :      Hello!!!   There,     Dr.   Smith.
    Please enter the second line :   Hello
    
    Ignoring whitespace, punc & case, the strings you entered are: NOT EQUAL
    
    
    Again, use good modular design and error detection in your solution. Your EqualNoPuncCase should not modify the two input strings, but it can make temporary copies of both, and modify the copies of each string. If you do this, make sure to free the space used by these copies when your function is done with it. Run valgrind on your solution to find and fix all memory access errors (including memory leaks).