122 homework week 2


The assignment

Use Emacs to edit/compile/execute/debug a C++ program that solves problem 25, p. 89. Name the source file commas.cpp. Name the executable commas (using the g++ switch -o commas ). Note that the required for loop is explained in 3.8 of your text, not 3.9 as stated on p. 89.

Simplifying Assumptions:

  1. All inputs will be positive (Natural numbers)
  2. No inputs will have a zero to the immediate right of where a comma will go (1204 is ok but 1024 is not)
  3. No inputs will exceed LONG_MAX (that is, 2,147,483,647)

I/O specification

Your program should generate this interface (see p. 57):
How many numbers? 2
Enter number 1: 2306
2036 with commas is -2,306
Enter number 2: 1234567890
1234567890 with commas is 1,234,567,890
          
Exiting... 

Creating Files Using Unix I/O Redirection

Here is a tutorial about IO redirection, however you may be able to get by with the following tips until next week.

Use Emacs to create a file commas.in that will contain the inputs necessary to run your program (e.g., 2 2306 1234567890).

Then use Unix I/O redirection to create an output file by using this shell-level command:
commas < commas.in > commas.out

Note: if commas.out already exists you can overwrite it with this shell command:  commas < commas.in >! commas.out

You can examine the file using this shell command: more commas.out