ICS 65 Fall 2011
Project #1: Land of Hope and Dreams

Due date and time: Friday, October 21, 11:59pm


Introduction

eBay is one of the Internet's great early success stories. Unlike many other high-profile Internet businesses that collapsed when the bubble burst, eBay not only survived the .com bust intact, but emerged stronger than before. Their success has been undoubtedly enabled by their high-margin, low-overhead business model, in which they need not purchase, warehouse, package, or ship anything. Acting only as a trusted middleman in millions of online transactions each year, they charge a tiny amount to allow a seller to bring an item to market, then take a small percentage of the purchase price. (Having acquired PayPal, a company that specialized in allowing individuals to make and receive payments online by credit card, eBay takes an additional small cut of most monetary transactions, as well.) In retrospect, it's difficult for those of us who were on the Internet before eBay's rise to avoid asking ourselves, "Why didn't I think of that?!"

Many of eBay's sales are organized as auctions. eBay auctions are run in the style of traditional auctions — a seller offers an item and buyers try to outbid each other for it — with one catch: not everyone has to be present in order to bid and win. The Internet changes the game quite a bit, allowing bidders all over the world to participate from the comfort of their own homes. To compensate for the lack of proximity, eBay auctions typically last several days — much longer than traditional auctions, which tend to last only a few minutes — and the bidding rules are somewhat different. The rules are designed to encourage the final sale prices of items to be higher, which not only benefits sellers, but also eBay, since they're keeping a percentage.

For this project, you will implement a C++ class called Auction, which handles some of the complexities of online auction-style bidding, using a set of rules similar to those employed by eBay. You will then surround it with a simple console-mode user interface that allows you to easily test it.


Choosing a partner (optional)

Feel free to work on this project with a partner. If you do, you should be using the "pair programming" technique, and other details about partnerships, discussed in the Lab Manual. It's not necessary for you to notify me ahead of time of your partnership, but you should be sure to include your partner in any email-based conversations about the project; ideally, try to include your partner in any in-person conversations (e.g., office hours), too. It should truly be a team effort.


The program

Your program is intended to manage only a narrow subset of the auction functionality provided by a site like eBay. This program only manages bids on one auction at a time, tracking only the identity and relevant bid amounts of the highest bidder. It does not track multiple auctions at a time, nor does it keep track of a list of all bids associated with an auction.

Your program should provide a simple console-mode user interface that allows a user to perform the following actions:


Handling input/output and dealing with money

You'll probably notice that the code I've provided uses the type unsigned int for all variables that store monetary amounts. Bids are accurate to one cent, which might make you wonder why I haven't used double values instead.

As far as our auction system is concerned, cents are indivisible. In other words, bids can never be made in fractions of a cent. The primary problem with using double values to store amounts of money is that they may be inaccurate, because of the way computers store floating-point numbers. Through simple arithmetic, a small amount of error, such as 0.0000001, can easily be introduced into a calculation, which becomes a nightmare to deal with when cents are meant to be indivisible.

There are programming languages with built-in types that handle decimal numbers in ways that are not subject to these kinds of problems; C++ is not one of them. So, I suggest using unsigned int variables to store amounts of money. (The reason I suggest unsigned int instead of int is that bid amounts must always be positive; since C++ provides us the ability to define whether our variables will be allowed to have negative values, we should be clear about our intent.) If the current bid is $1.57, you would store it in an unsigned int variable with the value 157. When reading amounts of money from the user, I would also suggest asking them to specify amounts in cents; so, to specify a bid of $1.57 in the program, have the user type the number 157. On the other hand, when outputting an amount, it might be nice to format it as $1.57. Here's a function that does just that, using a C++ feature called "stringstreams" that we haven't yet talked about; you're free to use this function as-is (or modify it) if you wish. (In brief, "stringstreams" are streams to which you can write using the same syntax as writing to cout, but a string containing the text is created instead of printing it to the console.)

string formatBidAmount(unsigned int bidAmount)
{
    ostringstream s;

    s << "$" << (bidAmount / 100) << ".";
    s << setw(2) << setfill('0') << (bidAmount % 100);

    return s.str();
}

In order to incorporate that function into a source file, you'll need to include this at the top of it:

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
using namespace std;

Since we haven't covered many of the details of console-mode input and output in C++ — and since many of those details require additional code to be written above and beyond the I/O library — error-handling of user input is not required. In other words, if your user interface requires an integer to be input at a certain time, it's fine for your program to misbehave or even crash when provided with anything else. However, the user interface must be friendly enough to make it clear what kind of input your program is expecting.


The rules of our auctions

Auctions will follow similar rules to those used by eBay. The rules are as follows:

To implement this behavior, the Auction object representing the current auction should know at all times the username of the high bidder, the current bid amount, and the proxy bid amount. It should also be aware of the opening bid amount, as well as whether or not any bids have been placed at all.

(A caveat: Some of you will have prior experience as buyers and sellers on eBay. It was not my intention to duplicate all of eBay's rules to the letter, though I've preserved most of them — as I understand them from conversations with eBay aficionados — as-is.)


Starting point

As a starting point, I've provided a header file Auction.h that suggests one possible design for your Auction class. You are not required to use it or keep it as it is, though you should be sure that you're following the acceptable coding practices if you decide to make changes to it. Either way, don't forget that you should have a separate source file called Auction.cpp that contains the implementation of this class. Header and source files are typically used in object-oriented C++ programs to cleanly separate interface from implementation, with the interface (i.e., class declaration) appearing in the header file and the implementation (i.e., definitions of class members) appearing in the corresponding source file. (There are gray areas; some definitions can appear in header files, which we'll talk about later this quarter. For now, let's keep everything separate.) This is different from how you arrange classes in Java, where all of the details are combined into one .java file.

To get started with Visual Studio,


Acclimating yourself to Visual Studio

If you've never used Visual Studio — or if you've never used it to write C++ programs — be sure to read my Visual Studio tutorial. And I strongly suggest using the empty solution I used for either Visual Studio 2010 or Visual Studio 2008, rather than trying to create a Visual Studio solution yourself, so that you can be sure that all of your settings will match mine.


Deliverables

Submit the C++ source and header files (.cpp and .h) that comprise your program. Do not submit any of the other files used or generated by your development environment. Follow this link for a discussion of how to submit your assignment. Remember that we do not accept paper submissions of your assignments, nor do we accept them via email under any circumstances.

If you worked with a partner, you'll only need to submit one copy of your program. Be sure that both names — yours and your partner's — appear in a comment in each header and source file, so that it will be clear to me how I should assign credit.