Homework No.2

[Streams]

The number of your particular task is the value of the expression faculty_number%11.


0. Write a program copy_file that copies one file to another. The file names are specified on the command line. For example

copy_file data1.txt data2.txt
1. Write a program concat_sort that concatenates the contents of two files of integers into one file. Suppose that the files are sorted and you have to produce the sorted file too.  For example if the first file contains the numbers 1, 9, 12, 25 and the second file contains 2, 11, 32, 39, the resulting file must consists of the numbers 1, 2, 9, 11, 12, 25, 32, 39. The file names are specified on the command line:
concat_sort data1.txt data2.txt result.txt
2. Write a program divide that divides the content of a files of integers into two. The numbers, which are less than a given number n form a new file while the remaining numbers form a second new file. For example if the first file contains the numbers 1, 9, 12, 25, 10 and n = 12, the numbers 1, 9 and 10 form the first file and the numbers 12 and 25 form the second file. The number n and the file names are specified on the command line:
divide 12 data.txt result1.txt result2.txt
3. Write a program addition that add a number n to all numbers that are contained in a file (of integers). The obtained  new numbers form a new file. For example if the file contains the numbers 1, 9, 12, 10 and n = 2, the numbers 3, 11, 14 and 12 form the resulting file. The number n and the file names are specified on the command line:
addition 2 data.txt result.txt
4. Write a program square that calculates the squares of all numbers that are contained in a file of floatibg point numbers. The obtained  new numbers form a new file. For example if the file contains the numbers 1, 2.5, 0.1, the numbers 1, 6.25 and 0.01 form the resulting file. The file names are specified on the command line:
square data.txt squares.txt
5. Write a program unique that reads the numbers contained in a file (of  integers). Then removes duplicate numbers and form a new file consisting of only one copy of the numners from the input file. For example if the file contains the numbers 1, 5, 1, 1, 8, 10 the numbers 1, 5, 8 and 10 form the resulting file. The file names are specified on the command line:
unique data.txt result.txt
6. Write a program even_odd that reads the numbers contained in an input file (of  nonnegative integers). Then creates two new files - the first file contains the even numbers and the second file - the odd numbers of the input file. For example if the file contains the numbers 1, 5, 0, 1, 8, 10, the even numbers 8 and 10 form the first file and 5 forms the second file. The file names are specified on the command line:
even_odd numbers.txt even.txt odd.txt
7. Write program even_odd that reads the numbers contained in an input file (of  nonnegative integers). Then creates two new files - the first file contains the even numbers and the second file - the odd numbers of the input file. For example if the file contains the numbers 1, 5, 0, 1, 8, 10, the even numbers 8 and 10 form the first file and 5 forms the second file. The file names are specified on the command line:
even_odd numbers.txt even.txt odd.txt
8. Write a program find that searches a file specified on the command line and prints out all lines, contaning a keyword. For example, if you call
find Kirov data.txt
all lines of the file data.txt containig the keyword Kirov will appear on the screen.

9. Write program replace that searches for a keyword in a file and replaces that keyword with another one. The keywords and file names are specified on the command line:
replace Kiril Maria data.txt
10. Write a program counter that searches a file specified on the command line and prints out the number of all lines, contaning a keyword. For example, if you call
count Kirov data.txt
the number of lines of the file data.txt containig the keyword Kirov will appear on the screen.