CSCE 2014 - Laboratory Assignment 2

    The purpose of this lab is to review C++ classes and get some practice with object oriented design and incremental program development. As you follow the steps below, you will create a program to store and manipulate information describing a music CD. We will not put iTunes out of business, but hopefully you will have some fun.

  1. Design the Music Object
  2. Your first task is to design the Music object we will be implementing today. When someone asks you to "tell me everything about your favorite CD" you will probably start with the artist name and the album name. Then you will probably look at the back of the CD and start reading off other interesting information.

    Your first step in designing a Music object is to think of meaningful names for all of these attributes, and decide what data types would be appropriate to store these values. For example, a CAR object could have a Model attribute of type string, a Year attribute of type int, and a Mileage attribute of type float.

    Think up FIVE Music attributes and decide what C++ variables are appropriate for storing each attribute. Too keep things simple for now, use just the basic types (int, float, string) and fixed size arrays of basic types. Type in your C++ declarations for your Music attributes in the space below:

  3. Create NetBeans Project
  4. Go through the following steps to create a NetBeans project and to create an empty main program.

  5. Create Music Class
  6. Go through the following steps to create a C++ class called "Music" inside the NetBeans project.

  7. Declaring Attributes and Implementing Constructors
  8. Now we can start adding information to the "Music.h" and "Music.cpp" files to declare private variables and to declare and implement constructor function.

    Copy and paste the contents of your "Music.h" file below:

    Copy and paste the contents of your "Music.cpp" file below:

  9. Declaring Methods
  10. So far we have ignored the operations that "do something" to our Music object. Frankly, there is not much you can "do" to objects this simple without a copy of the music or artwork. Since we are not going to re-implement iTunes in two hours, we will limit ourselves to operations that input/output the attributes, and print the information we have stored.

    Typically, direct access from outside to variables of a class is not recommended. The variables are usually made private, and read/write access is done through the getVar and setVar methods. For example, with the CAR object above, the methods to read/write the Model attribute would be getModel/setModel.

    Add public methods to "get" and "set" each of your Music attributes. Start by typing THREE method prototypes into your class definition in "Music.h". Then, add calls to these methods in "main.cpp". When you compile the program, you will probably get some error message. Cut and paste these error messages below.

  11. Implementing Methods
  12. The reason you got error messages was because the methods were not implemented. Your next task is to create EMPTY methods for each of your new methods in the "Music.cpp" file. Be careful to use the same parameters and return type as the method definition in "Music.h". Every public method has the following syntax:

          cout << "In CLASS_METHOD method\n";

    After you have implemented the THREE methods you created in "Music.h", add calls to these methods in "main.cpp" and compile and run your program. Cut and paste your program output below:

  13. Adding More Methods
  14. Continue the process of adding methods to the class declaration "Music.h", the class implementation "Music.cpp", and add calls to these methods in the main program until you have all FIVE "get" and "set" methods completed.

    Next, add TWO different print methods to the Music class, one that prints all of the music attributes, and another that prints an interesting subset of the music attributes. Cut and paste your new and improved "Music.h" below:

  15. Completing and Testing Methods
  16. The next step is to complete the implementations for ALL of your methods above, one method at a time, and test the program as you go. Each time you run your program it should print out more information as more of the methods do actual work. Cut and paste your final version of "Music.cpp" below:

    Cut and paste your final version of "main.cpp" below:

    Cut and paste your final program output below:

  17. Submit Work
  18. When you have completed all of the steps to this lab:

    Enter your FIRST name:
    Enter your LAST name:
    Enter your UAID number: