×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

I need your help ,I am desperate ,please!!!!!!!

I need your help ,I am desperate ,please!!!!!!!

I need your help ,I am desperate ,please!!!!!!!

(OP)


Term Project - 2

A MusicBox Using Polymorphism



 

In this project you’ll write a MusicBox program that is asked to you in the lab midterm. The full description of the project and the minimum requirements are given below. You can make any improvements as you wish (such as being able to turn the musicbox on/off, copying records etc.). Although the header file “music.h” was given in the midterm, now you will implement also the header file, whose prototype is given below.

Implement a MusicBox that can play a Record (Plak). As you can see from the following figure, the MusicBox contains 3 buttons (or more depending on your own design):

·        INSERT button allows you to insert a record into its drawer; and will be implemented by the insert method that requires a record object.

·        EJECT button ejects the previously inserted record from its drawer; and will be implemented by the eject method.

·        PLAY button plays the record that was inserted previously to its drawer; and will be implemented by the play method.



Record is an abstract base class for all types of records. In our system we will design and implement InstrumentalRecord (having only music) and VocalRecord (having music and song) that are subclasses of Record. Since Record is the base class it should have all the common properties of InstrumentalRecord and VocalRecord. So, inside the Record class you should provide a data structure to store the music that is common for all types of Records. music is simply an array of Notes. Note class will be implemented in the “music.h” header file.

//============  A MUSIC NOTE (MUZIK NOTASI)
class Note {

    //  note can take values from 0 to 6.
    //  0:do, 1:re, 2:mi, 3:fa, 4:sol, 5:la, 6:si
    int note;

    //  duration can take values from 1 to 3.
    //  note will be played duration seconds.
    int duration;


public:

    //  default constructor generates a random note
    //  having a random duration
    Note();

    //  displays the note in a readible format.
    //  format : note(duration)
    //  example: if note=0, duration=2 output will be do(2)
    void play();

};
Implement the Record class that stores a pointer to an array of Notes and the length of music (number of Notes). Its only constructor (default constructor) generates a random record that means a record having a random number of random notes. Record class should also have a play method that provides us to play it. The maximum length of a Record should be 45 Notes.

Implement the InstrumentalRecord class  deriving from the Record class. This InstrumentalRecord class implements a Record which has only music (array of Notes).

Implement the VocalRecord class deriving from the Record class. Other than having a music (array of Notes) that is inherited from the Record, it should also have a song, which is simply an array of Syllables (heceler). A VocalRecord’s each Note has a corresponding Syllable so; the lengths of music and the song are the same. Its only constructor (default constructor) generates a random record that means a record having a random number of random notes and the same number of random syllables. Syllable class will be implemented in the “music.h” header file.
//============  HECE (No need to be meaningful)
//  Syllable is generated as a sequence of 1 vowel (sesli)
//  followed by 1 consonant (sessiz) characters
class Syllable {

    char syllable[3];        // syllable containing 3 characters
                             // vowel + consonant + null
                             // examples "ak", "el", "of".

public:
    //  default constructor generates a random syllable
    //  containing 2 characters; 1 vowel followed by 1 consonant
    Syllable();

    //  displays the syllable
    void play();

};
After completing the implementations of your classes, execute the following main:
void main() {

    srand((int)time(NULL)); // initialize the random number generator

    InstrumentalRecord vangelis; // create one InstrumentalRecord,
    VocalRecord shakira;         //        one VocalRecord,
    MusicBox sony;               //    and one MusicBox
                                 // then perform MusicBox's methods
    sony.play();
    sony.eject();
    sony.insert(vangelis);
    sony.play();
    sony.insert(shakira);
    sony.eject();
    sony.insert(shakira);
    sony.play();
    sony.eject();
}
Its output should be similar to the following:
Error(3) Cannot be played: There is no record in the drawer!
Error(2) Cannot be ejected: There is no record in the drawer!
Record is inserted.
Playing an instrumental:fa(3)-sol(3)-mi(2)-si(2)-mi(2)-mi(1)
Error(1) Cannot be inserted: First, you've to eject the inserted record!
Record is ejected.
Record is inserted.
Playing a song:up[la(1)]-ug[si(3)]
Record is ejected.
After completing this core part of the project you can do any improvements as you wish. One of the improvements you MUST perform is to overload at least one operator. A sample operator overload is given below:

    VocalRecord mix = vangelis + shakira;
    sony.insert(mix);
    sony.play();
To be able to execute the first line (calculation) you have to overload '+' and '=' operators. '+' operator mixes its two operands, and then returning VocalRecord object is assigned to mix object by '=' overload. Mixing operation takes 1 InstrumentalRecord and 1 VocalRecord objects, then a new VocalRecord object is generated whose Note is taken from the InstrumentalRecord object and Syllable is taken from the  VocalRecord object.

Its output should be similar to the following:
Records are mixed.
Record is inserted.
Playing a song:up[fa(3)]-ug[sol(3)]
Read the following note carefully!



 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close