CS 333: Homework

Homeworks

Current HW

HW 1: What languages do you know?

Due Friday, Sep 7

Write down all of the programming languages you recall using. Use a broad definition of a programming languages as something that enables you to instruct a computer to complete a task automatically. For each language you recall, give a brief answer to each of the following questions.

• For what purpose did you use the language?
• How would you describe the syntax of the language?
• Was the language well-suited for the purpose? Why, why not?
• Could you write a program in the language right now without recourse to a textbook or manual? Why, why not?

HW 2: What languages do you want to know?

Due Friday, Sep 14

Pick four languages you do not yet know and write the equivalent of a Hello World program in each of them. Have it do something simple like print out the first ten terms of the Fibonacci series or calculate the average of 1000 random numbers between 0 and 100. Keep your programs under 20 lines of code.

Do not just copy and paste an example from somewhere else. You won't learn anything. You are free to look at example programs in the language, but type your own programs from scratch. Try to give them a unique twist.

Make a wiki page with your sample programs and do a little compare and contrast. Note especially the differences in syntax between the languages. Are there any differences in naming, variable scope, or data types?

You will likely choose your two focus languages from these four, so be sure to include languages of interest to you.

HW 3: Parse trees

Due Monday, September 24

Demonstrate that addition in C is not associative. The following two statements should print significantly different results. You need to figure out appropriate types and values for a, b, and c. Can you do the same with multiplication?

```printf( "%f\n", (a + b) + c );
printf( "%f\n", a + (b + c) );
```

Using the Clite syntax, generate both the concrete parse trees and abstract parse trees for the following statements. Feel free to do the concrete tree automatically using flex.

• a = b * ( 5 + c );
• ```if( a == 0 || b > 0 )
b = 0;
else
b = a;
```

Exam 1 Prep

The following are some suggested exercises for exam 1 preparation. Email the instructor with any questions you have.

• Chapter 2: 2.5, 2.6, 2.7, 2.9, 2.9, 2.12
• Chapter 3: 3.10, 3.13 (a, b), 3.19
• Chapter 4: 4.1, 4.5, 4.6
• Chapter 5: 5.3, 5.9, 5.14
• Chapter 6: 6.4 (you get the idea)
• Chapter 7: 7.1, 7.4
• Chapter 8: 8.1 (a, b), 8.4 (a, b)

HW 4: Exam follow-up

The following are worth up to 15 additional points on the last exam. Please do not use materials other than the text, your own notes, or the lecture notes and example code on the course web site. Email the prof your answers to one or both questions no later than than Wed before class.

1. Implement a function in C that can sum an array of any type. The function can return the sum in the manner of your choice, but it must be of the same (unknown) type as the input array.
2. Consider the do-loop below. The state of the program consists of a single variable i.
```int i=0;

do {
i++;
} while (i < 5);
```

Write a purely functional python representation of the do loop itself. The top level call should be MDo( doloop, state ). The state will be a single integer that starts with the value 0. The body of the do loop consists of adding something to the state variable. The test of the do loop involves comparing the state to the expression value.

Create a simple class DoLoop that contains a test field and a body field. Assign the test field the value 5. Assign the body field the value 1. You can use the body field as the thing to add to the state.

The MStmt function should, in addition to updating state, print out something indicating it is running.

Demonnstrate your functional python code works by running it. Your MStmt function should execute five times and then the MDo function should return 5 for the state.

HW 5: Exam 2 Prep

These are some suggested questions to study for both the second exam and the final exam.

• Chapter 9: 9.1, 9.6
• Chapter 10: 10.1, 10.2
• Chapter 11: 11.1, 11.3, 11.7
• Chapter 12: 12.1, 12.8
• Chapter 13: 13.1, 13.3
• Chapter 14: 14.4, 14.5
• Chapter 15: 15.1, 15.2, 15.3

HW 6: Logic Puzzle

Due Friday, 7 December

Go to the site Logic Puzzles. Pick a puzzle. Write a prolog program similar to this one to solve the puzzle.