6.s096 2013

6.s096 2013 Diagnostic Test

Due: Tuesday, January 1, 2013 11:59pm
Send Questions To: 6.s096-staff@mit.edu

Complete these 3 tasks using any programming language within reason. Since this is a diagnostic test, you should work individually.

Submit your solutions by e-mail:

To 6.s096-staff@mit.edu
Subject 6.s096 Diagnostic Test
Body Include your name, Athena username, class year, and course number
Attachments The source code for your solutions (as separate files, not a zip, if possible)

The staff will respond by the end of the semester.

- Task 1: Fibonacci Numbers

The Fibonacci Sequence is the familiar integer sequence: { 0, 1, 1, 2, 3, 5, 8, 13, … } where the nth term is the sum of the previous 2 terms:

fib(0) = 0
fib(1) = 1
fib(n) = fib(n-1) + fib(n-2)

Write a function named fib that calculates the nth term in the Fibonacci sequence for a given n. For example:

fib(0) returns 0
fib(1) returns 1
fib(2) returns 1
fib(3) returns 2
fib(4) returns 3
fib(5) returns 5
fib(6) returns 8
fib(7) returns 13

- Task 2: String Reversal

Write a function named reverse that returns a given string with the order of all words reversed. Words are separated by a single space. For example:

reverse("I would like to learn C") returns "C learn to like would I"
reverse("wonder") returns "wonder"
reverse("My?! Computer#123") returns "Computer#123 My?!"

- Task 3: Shopping Cart

Write a program to simulate an online shopping cart.

A shopping cart contains items. An item has a name, price, and quantity. Your shopping cart should be able to do the following:

We should be able to run your program and interactively perform all of the above operations. You are free to design your program however you would like as long as it satisfies the above requirements.