Functions and File I/O
For this assignment, develop a wiki page for each of your languages that shows examples of file I/O and function definitions. Focus on the semantics of function declarations, how function arguments are defined and used, and how functions are treated as a data type.
For each of your languages, create some example programs that
demonstrate reading and writing to both the terminal and to a
file. Some things to consider in your examples and writeup include the
- Does your language have built-in support for I/O, or is it part of a set of standard libraries?
- Does your language support different types of files, such as binary v. text files?
- Can the user input information into the program interactively?
- What is the relationship between files and strings? Demonstrate similarities and differences in the way the programming language handles them.
For each of your languages, create some examples of functions. Explore
the variations in the way functions and their parameters are defined.
Issues to consider include the following.
- How do you define the return type of a function? Must all functions have a return value or type?
- Can you overload functions in your language? If so, what are the rules for differentiating overloaded functions?
- Can you create functions with an unknown number of arguments? How do you access those arguments?
- Can you dynamically create functions? If so, how?
- Can you override functions with a new definition?
- What mechanism exists for publishing the existence of a function to other functions or compilable units (e.g. files)?
In C, write a set of programs that do the following. If C is one of
your languages, this should be in addition to the example code for
- The first program should generate an array of 20 random floating point numbers between 0 and 1. The program should then write them out to a user-defined file, or to the terminal if no filename is given, putting one number on each line, with five decimal places on each number.
- The second program should read in a file consisting of one number per line. It should not know how many lines are in the file, and it should be able to read in an arbitrary size file. You will probably need to read through the file first to get the number of numbers, then re-read it to actually grab the data. After reading in the data, it should write the set of numbers back to a user-defined file or the terminal if no filename is given.
- The third program should read two arbitrary length files of numbers, compare the values of numbers of corresponding lines, and print out the difference, flagging any difference that is not zero.
After writing your programs, run the first program once and save the file (call it file A). Then run the second program multiple times (3-4). The first time, read from file A and write to file B. For all subsequent times read from the file last written and write to a new file (B to C, C to D, etc). Finally, run the third program on file A and the last file written. Are there any differences? How big are they?
- Undertake one or more of the tasks for a third language.
- Explore the capabilities of formatted printing and scanning in C.
- Write a compilable haiku on functions or file I/O
- How does your language treat files accessed over the internet?
The writeup for this week is the assignment itself, plus the code, which should be integrated with your writeup. Email the well-commented and working C code from task three to the professor. Once you have written up your assignment, give your main page for this week the label: