Be sure you have read, or at least skimmed, the assigned readings from chapter 7 and appendix H.
Do the following programming problems. You will end up with at least one code file per problem. Submit your program source (and any other needed files) by sending mail to bmassing@cs.trinity.edu with each file as an attachment. Please use a subject line that mentions the course and the assignment (e.g., ``csci 1312 hw 6'' or ``CS1 hw 6''). You can develop your programs on any system that provides the needed functionality, but I will test them on one of the department's Linux machines, so you should probably make sure they work in that environment before turning them in.
The input file can contain any characters -- alphabetic, numeric,
punctuation, etc. -- but the output file should contain only
the ``words'' (sequences of one or more alphabetic characters),
each on a separate line, in lowercase.
The program should also print (to standard output)
the number of alphabetic characters
and the number of total characters in the input file.
So for example if file words-in.txt contains the following:
hello world HELLO AGAIN! and some numbers 1234 words,words,words,words.calling the program with the command
./a.out words-in.txt words-out.txtshould print the line
54 alphabetic characters, 72 characters in alland produce a file words-out.txt containing the following:
hello world hello again and some numbers words words words words
Since the logic for this program is a little tricky, I recommend that you start by writing a simpler but somewhat similar program that just converts alphabetic characters to lowercase, copies newline characters unchanged, and converts all other characters to spaces. If you can't figure out the full problem, you can turn in this simpler program for part credit.
Hints:
You will then use gnuplot to generate a plot showing the resulting data in graphical form.
The program should get the names of the input and output files from its command-line arguments (not by prompting the user as most of our programs have done) and should print appropriate error messages if fewer than two command-line arguments are given or if it cannot open the specified files. It should also print appropriate error messages if the input file contains anything other than positive integers. (Probably it should also check that the input values are in ascending order, but you don't need to do that.)
So for example if file estimate-pi-in.txt contains the following:
10000 20000 30000 40000calling the program with the command
./a.out estimate-pi-in.txt estimate-pi-out.txtshould produce a file estimate-pi-out.txt containing the following:
10000 8.3334095180020995031e-10 8.3333073774838339887e-10 20000 2.0833246239249092469e-10 2.0834134417668792594e-10 30000 9.2581942112701653969e-11 9.2588603450849404908e-11 40000 5.2116977400373798446e-11 5.2073012568598642247e-11For this problem I think you will get best results if you ``print'' (to the output file) the two computed values with %g rather than %f, and in particular it may be useful to say you want more than the default number of significant figures -- I used %22.20g. You should also use more values than I did in the example, and you could consider having each value be twice the preceding one rather than a fixed amount more. Try different choices until you get a set of input that produces output that seems meaningful.
To generate a plot, put the needed gnuplot commands in a file, such as estimate-pi.plotin. The command gnuplot estimate-pi.plotin will then generate a plot estimate-pi.png, which you can view with the command display estimate-pi.png.
Turn in your program and, for at least one set of input values (you might want to try more than one):
Hints:
Include the Honor Code pledge or just the word ``pledged'', plus at least one of the following about collaboration and help (as many as apply).2Text in italics is explanatory or something for you to fill in. For programming assignments, this should go in the body of the e-mail or in a plain-text file honor-code.txt (no word-processor files please).
Include a brief essay (a sentence or two is fine, though you can write as much as you like) telling me what about the assignment you found interesting, difficult, or otherwise noteworthy. For programming assignments, it should go in the body of the e-mail or in a plain-text file essay.txt (no word-processor files please).