Homework No.1

[Pointers, Inheritance, Streams]

Some of tasks are Programing Exercises from our textbook. Read carefully the text and use that every odd-numbered exercise has a solution given by Kay Horsmann, see
http://www.horstmann.com/bigcpp/solutions/solutions.html

The number of your particular task is the value of the expression faculty_number%24.
Write a complete program (even though the texts of some exercises begin with "Write a function ...").


0. Exercise P10.2 (p. 399)

1. Exercise P10.4 (p. 399)

2. Exercise P10.6 (p. 399)

3. Exercise P10.10 (p. 400)

4. Exercise P10.12 (p. 400)

5. Exercise P10.14 (p. 400)

6. Exercise P11.2 (p. 430)

7. Exercise P11.4 (p. 430)

8. Exercise P11.6 (p. 431)

9. Exercise P11.8 (p. 431)

10. Exercise P11.10 (p. 431)

11. Exercise P11.12 (p.432)

12. Exercise P11.14 (p. 432)

13. 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
14. 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
15. 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
16. 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
17. Write a program square that calculates the squares of all numbers that are contained in a file of floating 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
18. 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 numbers 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
19. 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
20. 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
21. Write a program find that searches a file specified on the command line and prints out all lines, containing a keyword. For example, if you call
find return data.txt
all lines of the file data.txt containing the keyword return will appear on the screen.

22. 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
23. Write a program counter that searches a file specified on the command line and prints out the number of all lines, containing a keyword. For example if you call
count return data.txt
the number of lines of the file data.txt containing the keyword return will appear on the screen.