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 SIX or more Music attributes and type them in the box below.

  3. Create C++ Variables
  4. Your next step is to 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 (as if you were declaring them in a full program) in the space below:

  5. Create C++ Class Declaration
  6. When we create C++ classes the data describing the object (the attributes) are normally stored in the "private" section of the class definition. The the methods (functions) which are operations on this data are normally declared in the "public" section. Since we are only telling users of the class what methods are available, the class declaration contains only the prototype for each method (return type, method name, and parameter names and types). The basic syntax of a C++ class is illustrated below:

    // Purpose: To declare and implement a Music class
    // Author:  John Gauch
    #include < iostream >
    using namespace std;
    class Music
       // TBA
       // TBA
       cout << "Music Program\n";
       Music cd;
       // TBA

    Create a new file called "music.cpp" using the code above and extend this code to include the variables you invented above. Then compile this code using NetBeans using the instructions from the previous lab (or by running "g++ -o music music.cpp" at the command line). When you have something that compiles and runs, cut/paste the code below.

  7. Adding Method Declaration
  8. 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 accesses (read or write) are 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 methods to "get" and "set" each of your music attributes. Start by typing THREE methods into your class definition. Then add calls to these methods in the main program. When you compile the program, you will probably get some error message. Cut and paste these messages below.

  9. Implementing Methods
  10. 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. Put these in between the class definition and the main program, and recompile. The syntax to start the implementation of a method belonged to a class is:

          //CODE GOES HERE

    Run your program and cut and paste your results below:

  11. Adding More Methods
  12. Now continue the process of adding methods to the class declaration, the main program, and create EMPTY method implementations until you have all the "get" and "set" methods you need. Then create TWO different print methods, one that prints all of the music attributes, and another that prints an interesting subset of the music attributes in the object. Use the same naming style with respect to the attributes being printed out as the one used for the get and set methods. This may take a few minutes. Cut and paste your resulting code below:

  13. Completing and Testing Methods
  14. 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 program below:

    Cut and paste your final program output below:

  15. Submit Work
  16. This lab assignment will be submitted electronically to the TAs once you fill in the fields below and click on the "submit" button. You do NOT need to print a copy of this document to hand in.

    Your full name:
    Your uaid number: