CISC 1110 Lab 12


You are going to write a program that reads data from input file and processes that data.


First, prepare the input file. To do this, in the editor, open a new file, then type in this set of values:

10        12

-10       18

4          -9

-7         -15


Save the file and call it data12.txt. Don't forget to change to All files (*.*) in the Files of Type box before saving the data file.


Now, write a program that will use this file. First, open the file (call it infile, and associate it with file "data12.txt").


The program will use a structured read loop to read values two at a time from the input file, storing the values in the variables x and y. Print x and y. Then process each set of values as explained in the paragraph below. Continue reading and processing values until you get to the end of the data file (read to input failure). Then close the file.




Using a nested if/else, test each set of values. Print the words "both are positive" if both of the two variables are greater than zero (for example, if x is 10 and y is 12).


Otherwise test to see if one or the other is positive. Test x; if x is positive, print the words: "x is positive". Test y; if y is positive, print the words: "y is positive".


If neither one is positive, print "neither is positive". This last message would print, for example, if x is -7 and y is -15.