CS 333: Homework


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.

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?

Please put the label cs333F12hw02 on your wiki page.

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.

Exam 1 Prep

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

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 {
    } 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.

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.