Project 1

Assigned Monday, Feb 6, 2006
Due Sunday, Feb 19, 2006
Updates 13 Feb
There is a new requirement regarding comments in the command files.
12 Feb
The original sample output included the statement "The jar contains 34 jawbreakers". Trying to have a generic candy jar print something about the specific candy inside of it (while doable) can lead you done an ugly OO path. Please simply print something generic like "The jar contains 34 candies" instead.
09 Feb
  • PRINT command added to both command files
  • The EAT command for STARBURST now correctly indicates "flavor" as the first argument.

07 Feb So that we are sure to get the same results, please use the value 3.14 for PI in all calculations.


Background

Abstract Data Types (ADT) are a central idea of this course and of object-oriented programming in general. Recall that an ADT has two parts: (1) a description of the elements that make up the type, and (2) a description of the operations allowed on instances of the type. The ADT idea is implemented in C++ as a class. The ADT is one of the most powerful and important ideas in computer science. This project will give you some exercise in using ADTs.

Another important OOP idea, parametric polymorphism, is implemented in C++ by templates. This project will give you some practice with C++ templates.

You will get a chance to see how exceptions can be used to handle error situations. Since the text uses some C++ exception handling mechanisms, this project will help you understand the text's code.

You will get a chance to review some basic C++ tasks such as handling command-line arguments, and reading files. These should be in your basket of programming techniques and will be important for later projects and throughout your career.

You will get a chance to figure out how to use code written by someone else. This is a critical skill in the real world workplace.

Most importantly, you will get a chance to implement and use a C++ class template. Templates are used to implement almost all data structures in this class and all container classes in the STL.


Description

One thing that most everyone can agree on is that candy is delicious and fun to eat. Everyone has their favorite kind -- candy bars, M & Ms, Hershey Kisses, licorice, etc.

In this project you will implement a cylindrical candy jar as a container class, then fill that jar with candy. We will limit our candy selections to "jaw breakers" and "Starburst", but your jar should be designed and implemented to handle any kind of candy.

Your project will read the command line, create the appropriate type of candy jar and then read a command file which is specific to the type of candy in the jar. Your project will process each command in the file, producing an appropriate output or error message.

What To Do

Here are the project tasks to be done:
  1. Implement the candy jar ADT as a C++ class template.
  2. Implement the jaw breaker ADT as a C++ class.
  3. Implement the starburst ADT as a C++ class
  4. Use the main function provided in the file /afs/umbc.edu/users/d/e/dennis/pub/CMSC341/Proj1/Proj1.cpp. Use the function as-is, no changes.

  5. The main function calls the following functions that you must write. The signature and documentation for these functions are found in the header file Proj1Aux.h in Mr. Frey's public directory.
    1. GetCommandLine
    2. ProcessJBFile
    3. ProcessSBFile
    Note: There is no need to copy Proj1.cpp or Proj1Aux.h to your own directory. Your makefile must access these files from the directory in which they are provided. Do not submit Proj1.cpp or Proj1Aux.h.

  6. Write a makefile. You can copy the file /afs/umbc.edu/users/d/e/dennis/pub/CMSC341/Proj1/Makefile and modify it as needed. If you name your files to match those in the makefile provided, no changes will be necessary.

  7. Answer the questions posed in 341-spring06-proj1_questions.txt. Copy the file from Mr. Frey's public directory to your own directory and edit it to provide your answers to the questions. Don't forget to submit the edited file; it counts 10% toward this project's grade. Do not rename this file. It is searched for by an automatic script. If the script can't find it, you did not submit it properly and you will not get credit for it.

Definition of the ADTs

Candy Jar

A candy jar is a cylindrical container usually made out of glass that uses a screw-on lid to keep the candy fresh. Only one kind of candy at a time can be stored in the candy jar, but note that each kind of candy comes in different sizes, shapes, flavors, and/or colors. For example, a candy jar that contains only M&Ms may contain "plain red M&Ms", "blue peanut M&Ms", "green plain M&Ms", and other kinds of M&Ms.

The operations on a CandyJar are:

  1. Construct a new candy jar given the height and diameter in inches. A new jar is initially closed. Height and diameter may be fractional.
  2. Screw the lid onto the jar so no candy pieces can fall out or be removed.
  3. Unscrew and remove the lid so candy can be removed.
  4. Remove a specific piece of candy (e.g. large blue jawbreaker) from the jar.
  5. Place a specific piece of candy (e.g. small grape starbust) into the jar.
  6. Dump out all of the candy out of the jar.
  7. Print a summary of the jar's contents to a specified output stream. The output does NOT print a description of every piece of candy in the jar. The summary should be printed in order according to the number of pieces. The volume of the jar and the total number of pieces must also be shown. An example summary is shown below. The candy jar has a volume of 40.2 cubic inches The jar contains 34 candies 12 large blue 10 large yellow 8 small red 4 small blue

Jaw Breaker

A jaw breaker is a very hard, spherical piece of candy that comes in three sizes (small, medium, and large). Small jaw breakers are 1/4 inch in diameter. Medium jaw breakers are 1/2 inch in diameter. Large jaw breakers are 1 inch in diameter. Jaw breakers come in six different colors (red, blue, green, orange, purple, and pink).

You should examine the jaw breaker's role in this project, then design and implement a minimal set of operations to support the jaw breaker ADT.

Starburst

A starburst candy is a cube shaped piece of candy that comes in two sizes (medium and large) and four flavors (grape, cherry, lemon, and lime). Medium starburst are 1/2 inch on each side. A large starburt is 1 inch on each side.

You should exmine the starburt's role in this project, then design and implement a minimal set of operations to support the starburst ADT

The command files

Both command files have the same basic format and rules.
  1. If the first character on a line is the pound character, #, that line is a comment and the entire line should be ignored.
  2. There is one command per line.
  3. The file may contain invalid commands (the first word on the line). If you find an invalid command, print an appropriate error message and ignore the rest of the line.
  4. All valid commands are properly formatted. Valid commands will have the correct number of arguments and each argument will be of the appropriate type.
  5. The command file may be an empty file.
  6. The command file may contain blank lines which should be ignored.
  7. Both files may contain the following commands
    1. OPEN -- opens the candy jar.
    2. CLOSE -- closes the candy jar.
    3. DUMP -- dumps all of the candy out of the jar and onto the floor.
    4. PRINT -- prints the candy jar summary

The Jaw Breaker Command File

The following commands are valid only in the jaw breaker command file
  1. JAWBREAKER <count> <color> <size> where
    count is a positive integer
    color is one of "red", "blue", "green", "orange", "purple", or "pink" (without the quotes)
    size is one of "small", "medium" or "large" (without the quotes).
    This command creates "count" new jaw breaker candies with the specified color and size and attempts to put them into the candy jar.
  2. EAT <color> <size> where
    color is one of "red", "blue", "green", "orange", "purple", or "pink" (without the quotes)
    size is one of "small", "medium" or "large" (without the quotes).
    This command attempts to remove one jaw breaker of the specified color and size from the jar so that it may be eaten.

The Starburst Command File

The following commands are valid only in starburst command file
  1. STARBURST <count> <flavor> <size> where
    count is a positive integer
    flavor is one of "grape", "cherry", "lemon", or "lime" (without the quotes)
    size is one of "medium" or "large" (without the quotes).
    This command creates "count" new starburst candies of the specified flavor and size and attempts to put them into the candy jar.
  2. EAT <flavor> <size> where
    flavor is one of "grape", "cherry", "lemon", or "lime" (without the quotes)
    size is one of "medium" or "large" (without the quotes).
    This command attempts to remove one starburst of the specified flavor and size from the jar.

Project Notes, Hints, and Miscellaneous Requirements

  1. Mr. Frey's public directory for this project is /afs/umbc.edu/users/d/e/dennis/pub/CMSC341/Proj1
  2. The main function expects to be called with four command line arguments -- the type of candy (either "jawbreakers" or "starburst" without the quotes), height of the jar in inches, the diameter of the jar in inches, and the name of the command file, in that order. The jar's height and diameter may be fractional (e.g. 4.5).
  3. All output should be directed to cout.
  4. The starburst and jaw breaker classes must use an enum for their size. Global constants or #defines are not acceptable.
  5. In addition to the operations specified for each class, you should also implement any C++ specific methods you need (e.g. destructors).
  6. Correct design dictates that the method that prints the contents of the jar must have a parameter that specifies an output stream. It may not assume the output is going to cout.
  7. Be sure to follow the project organization guidelines with respect to class, variable, and file naming.
  8. Always use your makefile when developing. This gives you good experience with makefiles, ensures that your makefile works properly, and that your makefile is using Proj1.cpp and Proj1Aux.h from Mr. Frey's public directory. Don't lose points because your makefile has a typo.
  9. All commands (valid and invalid) must be echoed to cout.
  10. Even though a command is valid, it may not be logically possible. In the case that a valid command cannot be executed for a logical reason, an appropriate error message should be displayed. Your program must handle all valid, but illogical commands. It's up to you to use common sense to determine these errors. For example,
    1. You cannot close a jar that's already closed.
    2. You cannot put a piece of candy into a closed jar.
  11. Candy jars get full, or at least nearly full, so that new pieces of candy cannot be placed in the jar. To keep things easy, simply compare the candy's volume with the available space (volume) of the jar and if the volume of the jar is greater than or equal to the volume of the candy, then the candy may be placed in the jar.
  12. In the case of a JAWBREAKER or STARBURST command, place as many of the candies as possible into the jar. I.e. if the "count" in a JAWBREAKER command is 50 but only 23 jaw breakers will fit in the jar, then place those 23 in the jar and do nothing with the remaining 27.
  13. Your answers to 341-spring06-proj1_questions.txt are worth 10% of your project grade. Grammar and spelling must be correct.
  14. Cheating in any form will not be tolerated. Please re-read the CMSC 341 Project Policy handout for further details on honesty in doing projects for this course.

Files To Be Submitted

You should submit only the files you have written, a makefile, and the file containing your answers to the questions. Submit all the files needed to successfully compile your project.
You may submit a file named grader.README if you want to leave a message for the grader. For example, you might wish to point out some special feature of your project that may be eligible for extra credit. The file name must be grader.README if the automatic script is to detect it. Any other filename for grader comments will be ignored.
Don't forget to submit 341-spring06-proj1_questions.txt containing your answers to the questions. Please do not submit any of the files provided to you such as Proj1.cpp and Proj1Aux.h

These files, if present, will be removed by the automatic grading script. Your makefile should be able to successfully compile your project in a directory that does not contain these files.

If you have any comments for the grader, submit them in a file named grader.README.

Submit the files using the procedure given to you for your section of the course.

There are a number of tools available to you to check on your submittal. It is your responsibility to ensure that the submittal is correct and will result in a successful compilation of your project. Do not wait till the last minute to submit your files. Give yourself enough time to check that your submittal is correct.

If you don't submit a project correctly, you will not get credit for it. Why throw away all that hard work you did to write the project? Check your submittals. Make sure they work. Do this before the due date.

Documentation for the submit program is on the web at http://www.gl.umbc.edu/submit/. One of the tools provided by the submit program is submitls. It lists the names of the files you have submitted.

Additionally, there are two programs for use only by CMSC-341 students (not part of the UCS submit program). They are in the directory /afs/umbc.edu/users/d/e/dennis/pub/CMSC341/ and are named submitmake and submitrun. You can use these programs to make or run your submitted projects.

The syntax is similar to that for submit:

submitmake <class> <project>

Example:  submitmake cs341 Proj1
This makes the project, and shows you the report from the make utility. It cleans up the directory after making the project (removes .o files), but leaves the executable in place.

submitrun <class> <project> [command-line args]

Example:  submitrun cs341 Proj1 checkers checkfile.dat
This runs the project, assuming there is an executable (i.e. submitmake was run successfully).

Sorry! We could not find what you were looking for

Try going back to the main page here

 
4
4
0
0
0
0