CSE 305 Programming Languages Fall, 2003 Professor Shapiro Homework 7 Maximum Points: 18 Due 9:00 am, Tuesday, November 4, 2003 Copy this file to a text file named hw7.txt, edit into it your answers, and submit the file via the submit program by the deadline given above. 1. Do the following parts of exercise 7.9 (page 315-316) of the text. Instead of superscripts, write the integer to indicate order immediately after the right parenthesis. For example, the answer to a + b * c + d would be written as ((a + (b * c)1)2 + d)3 a. (3) a * (b - 1) / c mod d b. (3) -a or c = d and e c. (3) a > b xor c or d <= 17 2. (3) Fortran 77 and earlier versions of Fortran do not have pointers. However, pointers may be simulated by parallel arrays. Edit the following program to replace the question marks (`?') with appropriate integers so that when you compile and run the program, it prints the 12 months in the correct order starting with "January". Copy the edited program into a file named months.f. Compile the program with the Unix command f77 -o months.fout months.f and then run it with the Unix command months.fout Here's the program: Program months Character monName*9(12) Integer i, firstMonth, nextMonth(12) Data monName/"November", "April", "September", "May", C "December", "June", "February", "October", C "January", "July", "March", "August" / Data firstMonth/?/ Data nextMonth/?,?,?,?,?,?,?,?,?,?,?,?/ i = firstMonth 10 If (i .NE. 0) Then Print *, monName(i) i = nextMonth(i) Goto 10 EndIf End 3. (3) Fortran is one of the few current languages that has an operator (**) for exponentiation. What is printed by the following Fortran program? (Programs compiled by f77, f90, and f95 print the same number.) Program exptest Integer i, j, k j = 2 k = 4 i = j ** 2 ** k - 1 Print *, i End 4. (3) The echo.c program you ran for homework 1 reads and echoes input until it encounters the string "bye". However, if it reaches the end of the input file before it encounters the string "bye", it will loop infinitely. The function echo.c uses to read input is scanf("%s", str). If this is evaluated and there is nothing left in the input file, it will return a value equal to the predefined constant EOF. Edit echo.c so that it will print "Good bye." and terminate if it reaches the end of the input file. Use a short-circuited Boolean expression to do this. There should be only one occurrence of the statement `printf("Good bye.\n");' in your program, and the expression `strcmp(str, "bye")==0' should not be evaluated when EOF is reached. After testing the program, paste it here in the hw7.txt file you submit: