COSC 072: Computer Science I

Project 2
Spring 2011

Due: Fri, Feb 25 @ 5 PM
6 points

As an homage, in this project, you will use classes, inheritance, and polymorphism to implement software that stores information about different varieties (or shapes) of pasta. For simplicity, we will assume that all pasta is one of two shapes, flat or round. Apologies to pasta lovers! Furthermore, we will not worry about storing so-called specialty shapes, such as orzo or fusilli. If your pasta knowledge is a little rusty, you may find helpful the information in Kyle Phillips' article The Pasta Shapes Glossary. Generally, in this project, we are concerned with sheet and strip (i.e., flat) pastas, and then extruded (i.e., round) pastas. I encourage you to think of better models for the pasta hierarchy.

I have drawn a class diagram for pastas using the Unified Modeling Language (UML), which appears in the image below. Computer scientists and software engineers commonly use UML to design software. We will discuss the diagram in class, but its interpretation should be relatively straightforward. Briefly, a rectangle represents a class and is divided into three sections for the class's name, its data members (or attributes), and its methods (or operators). Characters precede attributes and methods. The hyphen (-) denotes private, the pound sign (#) denotes protected, and the plus sign (+) denotes public.

As the diagram indicates, you should implement the Pasta class and derive two subclasses, Flat and Round. All pastas have a name and length, both of which must be protected. Flat pastas have a width, whereas round pastas have a diameter. Each class should have virtual methods that read and print the pasta's information from and to a stream. Naturally, the set methods should perform range checks and can fail silently when values are out of range. (We will learn proper methods of error handling for p3.)

Storing a single type of pasta is not very interesting, so also implement a Pastas (plural) class that stores Pasta objects in a C++ vector. As the composition link in the diagram indicates, there is a one-to-many relationship between the Pastas class and the Pasta class. The UML diagram depicts the vector as a private attribute of the Pastas class, but you could also derive Pastas from the vector class. Implement methods to read pastas from a file, print the pastas stored in the vector, and compute the total volume of those pastas.

Design a file format for storing information about pastas, their type, name, width, and diameter. Fabricate data for a number of pastas named in Phillips' article, noting that pastas such as penne rigate consist of two strings. Store the information in the file pastas.dta.

In the main function, write a simple driver program that reads pastas from your data file, prints them to the console, and prints the total volume of the pasta. If the data file does not exist, then main should issue an appropriate message and exit.

Use stepwise refinement and incremental development. For example, implement the Pasta class and test it thoroughly before implementing, say, the Flat class.

All class definitions and class methods must be documented with Doc comments. Doc comments for class definitions must include @author and @version tags. Doc comments for methods must include @param and @return tags, where appropriate.

Getting Started

I'm sure that writing your own Makefile for p1 was fun, but for p2, you'll use a Makefile that is less obvious, but more general. You should be able to use it for the rest of the projects this semester.

To get started, log on to seva, create a directory, and copy over my Makefile:

seva% mkdir p2
seva% cd p2
seva% cp ~maloofm/cosc072/Makefile.p2 ./Makefile
seva% ls
Makefile
seva%
I'll explain this Makefile in class. It might be a useful exercise to get this Makefile working for your solution to p1 just to make sure you know what you're doing.

Instructions for Electronic Submission

At the top of the file main.cc (or the file containing the main function), place the following header comment, with the appropriate substitutions:

/*
 * COSC 072 Project 2
 * Name: <your name>
 * ID: <GoCard ID>
 * E-mail: <e-mail address>
 * Instructor: Maloof
 *
 * In accordance with the class policies and Georgetown's Honor Code,
 * I certify that, with the exceptions of the class resources and those
 * items noted below, I have neither given nor received any assistance
 * on this project.
 */

You'll be submitting p2 exactly like you submitted p1. If you need to include a message about your submission, then place the message in a file named README. Place the README file in the project's directory.