FILE PROCESSING

 

Problem # 1

 

Write a program that reads unknown number of integers from a file and writes the positive integers into a file and the negative integers into another file. Assume that each line of the file contains one value.

 

Problem # 2

 

Write a program that reads unknown number of integers from a file and writes the odd integers into a file and the even integers into another file. Assume that each line of the file contains one value.

 

Problem # 3

 

Write a program that reads unknown number of reals from a file and prints the values above the average. Don’t use an array.  Assume that each line of the file contains one value. HINT: Use the REWIND statement.

 

Problem # 4

 

Write a program that reads unknown number of reals from a file and prints  the percentage of values above average.  Don’t use an array.  Assume that each line of the file contains one value. HINT: Use the REWIND statement.

 

Problem # 5

 

Write a program that combines two files into one file such that the contents of the first file is followed by the contents of the second file. Assume that both files contain unknown number of values and each line in both files contains three values: name (maximum 12 characters) , Identification number , and GPA, e.g.:

            ‘AHMAD SAID’         45        3.5

Create your own data for each of the files.

 

Problem # 6

 

A file contains an unknown number of data lines; but each line contains two positive integers. Write a program which reads the file and computes the sum of the maximums, i.e. :

            SUM  =  MAX1 + MAX2 + . . . + MAXi + . . . + MAXn

 

where MAXi is the maximum of the ith data line.

 

Problem # 7

 

A file contains an unknown number of data lines. Each data line contains the name of a person (maximum 12 characters) and his age  (a REAL value), e.g.:

            ‘OMAR DAUD’          45.0

Write a program which reads the file and print all persons with age greater than 50.0 in a data file OLD.DAT

 

Problem # 8

 

Write a program which will determine whether two files are identical. It is known that each file contains one integer per each data line; but the number of data lines in each file is not known.

 

Problem # 9

 

Each line of a file contains the ID number of a student and his three quiz grades (Real numbers). The number of data lines in the file is not known. Write a program which will read the file and print, in another file, each student ID and his average in the three quizzes. The program should then print, in the other file, the overall average.

 

Problem # 10

 

Each line in a data file contains a sentence of no more than 75 characters. The number of data lines in the file is not known. Write a program which will read the data file and print the sentences in another data file double spaced.

 

Problem # 11

 

Each line in a data file contains two integers. Write a program which will read the file and create another file in which the contents of the input file are duplicated (i.e. the output file contains the contents of the input file followed by another copy of the input file). HINT: Use the REWIND statement.

 

Problem # 12

 

Write a program that reads a file of integers and prints the file reversed. Assume each line contains one integer and that the maximum number of integers in the file is 30. Hint: Use a one-dimensional array.