CMSC313, Computer Organization & Assembly Language Programming, Spring 2013

Project 6: Ciruclar Buffers and Currency Exchange

Due: Tuesday April 9, 2013, 11:59pm


The objective of this programming project is to have you work with dynamically allocated data structures.


If you missed the class discussion on circular buffers, look it up on the internet (e.g., Wikipedia) or a data structures textbook.

The data structure you will implement will help a currency trader (let's call him Andreas) summarize the foreign currency exchange data he receives throughout the day. Andreas's data feed looks like this:

USD-JPY 06:00:00.110 94.797 EUR-JPY 06:00:00.151 123.604 USD-JPY 06:00:00.230 94.799 EUR-JPY 06:00:00.271 123.605 EUR-JPY 06:00:00.333 123.605 USD-JPY 06:00:00.352 94.798 EUR-USD 06:00:00.361 1.30384 EUR-JPY 06:00:00.640 123.6 EUR-USD 06:00:00.683 1.30381 USD-JPY 06:00:00.884 94.798

Each line is a quote and represents an offer by someone somewhere to exchange currency at a particular rate. Here, USD is U.S. Dollars, EUR is Euros and JPY is the Japanese Yen. The second column is a timestamp and the third column is the actual exchange rate. For example, the line:

EUR-JPY 06:00:00.333 123.605 means that at approximately 6am, someone is willing to exchange Euros for Japanese Yen at the rate of 1 Euro = 123.605 Japanese Yen.

The exchange rates can vary dramatically over the course of a trading day — depending on the news of the day and what other currency traders are doing. Andreas can make money trading currencies, for example, if he correctly predicts that the Euro will rise versus the US Dollar today. Then he can buy Euros with dollars in the morning and exchange them back to dollars in the afternoon and end up with more dollars than he started with.

Thus, Andreas needs to pay attention to these quotes but on a busy day there may be thousands of quotes in an hour. That's too much information. He wants you to store the quotes from the last 5 minutes (300 seconds) and report the average exchange rate for him. You will do so by storing the quotes from the last 5 minutes in a circular buffer.

Finally, Andreas cannot tell you how many quotes there will be in 5 minutes. Your data structure should adapt its memory usage accordingly. If your circular buffer is full, you should double the amount of storage allocated. On the other hand, if your circular buffer is using less than a quarter of the storage, you should free up half of the storage.


Note: As with Project 5, this project description deliberately avoids using C syntax. This is so you figure out how to look up the syntax of various elements of the C programming language.

You will implement an Abstract Data Type (ADT) to store currency quotes in a circular buffer. Your functions must be compatible with the main programs given below. Memory for the circular buffer must be dynamically allocated. Main programs that use your ADT may use several circular buffers at a time. (Thus, your functions should not rely on global variables.) Your ADT must support the following functions:

You will likely implement additional functions used internally by your ADT. (Actually, this is highly recommended.) Programmers using your ADT may not use these additional functions.

You must provide a header file circular.h that contains all the typedefs and function prototypes needed to use your ADT. The header file must be guarded.

Your circular buffer needs to maintain an array of structs of type quote. Each quote struct must have an unsigned int field called time and a double field called rate. The array of quote structs must be dynamically allocated.

Your header file must have a type definition of cbuf. A pointer to cbuf is used to specify the circular buffer to the ADT's functions. The type cbuf itself is most likely a struct (you decide), but the programmer using your ADT is not allowed to assume that. In particular, the programmer is not allowed to manipulate the fields of cbuf.

You should make your declarations and definitions compatible with these sample main programs:

The three data files used in the third test, Ticks6am.txt, Ticks2pm.txt and TicksAll.txt are available on the GL filesystem:


Implementation Notes

Turning in your program

Use the UNIX submit command on the GL system to turn in your project. You must submit the header file circular.h, the implementation circular.c and any test programs you wish to submit (optional): test1.c, test2.c, ...

In addition, submit a typescript file showing that your ADT functions worked with main6a.c, main6b.c and main6c.c.

You may optionally submit a README file explaining anything the graders might need to know about compiling and/or running your programs.

Your submit commands will look like:

submit cs313 proj6 circular.h circular.c
submit cs313 proj6 test1.c test2.c
submit cs313 proj6 typescript README

Last Modified: 2 Apr 2013 08:20:36 EDT by Richard Chang
to Spring 2013 CMSC 313 Homepage