7.1.0.8

2 — Exploring Your Favorite Programming Language

Due Thursday, September 13, midnight

Delivery You must deliver two artifacts via a directory called 2 in your repository (master branch):
  • spread.pdf, the artifact for task 1.

  • 2, the executable for task 2, and

All auxiliary files must be put into a sub-directory called Aux.

Task 1 Your company has hired a group of stellar programmers in Codemanistan, a country located in a galaxy far, far away. Your manager has put you in charge of writing a specification for the interface for a module, dubbed spreadsheet, which these stellar programmers will implement in your favorite language and ship back real soon.

As the name suggests, the high-level purpose of the desired module is to provide the services of a basic spreadsheet. For our purposes a spreadsheet is a rectangular grid of formulas. The module must provide the following services (functions, methods):
  • building a spreadsheet from a rectangular arrangement of formulas

  • determining the value of a position (cell) in such a rectangle

  • placing a formula into a specific position

As for formulas, the module should at least support constants (numbers), references to cells in the spreadsheet, addition and multiplication (of two terms).

Formulate your specification in a mix of English and technical terms appropriate for your chosen language. For example, in Java you’d use the term package while a Racketeer would speak of modules.

Write a specification in memo form. It must fit on a single page in a 12-point PDF document. In "from" use your manager’s name, in "to" say "Matthias^2" or "Jason^2".

Specify the precise language (name, version) in which you expect the product to be written in.

Task 2 Your company has chosen JSON as the data language for your project. (Well, your team voted, and the vast majority fell for the latest and greatest teenage-heartbreak data fashion.)

So, it is time to explore your chosen language with small programs that confirm your memo’s claims.

Develop a program that echos JSON values on the Linux command line. Specifically, the program reads an unlimited number of JSON values from STDIN until the input stream is closed (^D). At that point, the program prints all the JSON values, each on a separated line, embedded in a JSON array that indicates its reverse position in the stream (counting down to 0).

    [login-students: matthias] $ ./2

    [1,2]

    {"a":1}

    ^D

    [1,[1,2]]

    [0,{"a":1}]

    [login-students: matthias] $

You are not guaranteed that every JSON value occupies a single line.

Note Instead of typing JSON values into the program by hand, you may wish to use the re-direction facility of Unix/Linux:

    [login-students: matthias] $ cat sample-input

    [1,2]

    {"a":1}

    [login-students: matthias] $ cat expected-output

    [1,[1,2]]

    [0,{"a":1}]

    [login-students: matthias] $ ./2 < sample-input > sample-output

    [login-students: matthias] $ diff sample-output expected-output

    [login-students: matthias] $

If diff does not display any lines, your test succeeded.If you recognize a generalization of the test idea from Fundamentals I, then you are on the right track. Alternatively, you can run

    [login-students: matthias] $ ./2 < sample-input | diff - expected-output

which uses Unix pipes to send the actual output into diff as the first input and compares it with the expected output directly.