Be sure you have read, or at least skimmed, the assigned readings from chapter 7 and appendix H.
Please include with each part of the assignment the Honor Code pledge or just the word ``pledged'', plus one or more of the following about collaboration and help (as many as apply).1Text in italics is explanatory or something for you to fill in. For written assignments, it should go right after your name and the assignment number; for programming assignments, it should go in comments at the start of your program.
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 7'' or ``CS1 hw 7''). 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, 75 characters in alland produce a file words-out.txt containing the following:
hello world hello again and some numbers words words words words
Hints:
More specifically, your program should take as input a file containing different values for this number of slices and produce a file containing, for each input value, the input value and two output values, one for left-to-right and one for right-to-left, with each the absolute value of the difference between the estimated value of and the best-available value of as produced by acos(-1.0).
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 numint-in.txt contains the following:
10000 20000 30000 40000calling the program with the command
a.out numint-in.txt numint-out.txtshould produce a file numint-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. I think 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 (or sets) of input that produces output that seems meaningful.
To generate a plot, put the needed gnuplot commands in a file, such as numint.plotin. The command gnuplot numint.plotin will then generate a plot numint.png, which you can view with the command display numint.png.
Turn in your program and, for at least one set of input values (you might want to try more than one):
Hints: