Question

In: Computer Science

Declare a Song struct to store the data for a single song (make it a private member), and you must have anarray of Song structures as a member variable.

USE C++ 

Declare a Song struct to store the data for a single song (make it a private member), and you must have anarray of Song structures as a member variable.

Player(string name, float size) a constructor for the class. ’name' is a name for it
'size' is a maximum capacity in Mb.

addSong(string band, string title, string length, float size) a function for adding a new song.

'band' is a name of the band
'title' is a name of the song
'length' is a time length of that song in a '1:23' format (“mm:ss") 'size' is a size of the song in Mb

Return true if the song was added and false if there was not enough space (memory) for it or there was a song with the same band and title already in that device or if the device already has 1000 songs in it.

Solutions

Expert Solution

// CODE
#include
#include
#include
using namespace std;

class Player {
    public:
    Player(string name, float size) {
        this->name = name;
        this->size_allowed = size; // this is the max Mb allowed to store
        this->current_size = 0; // this is the Mb that is currently filled
        this->current_songs_count = 0; // songs currently present
    }
   
    bool addSong(string band, string title, string length, float size) {
        Song s; // first create a song structure for the data given
        s.band = band;
        s.title = title;
        s.length = length;
        s.size = size;
       
        // now check if the number of songs limit is reached
        if(current_songs_count > MAX_SONGS_ALLOWED) { // if the songs exceeds limit
            return false; // return false
        }
        if(current_size+s.size > size_allowed) { // if adding the song exceeds the memory limit
            return false; // return false
        }
       
        // check if there any duplicat of the current song exists
        for(int i = 0; i < current_songs_count; i++) {
            if((songs[i].title == s.title) && (songs[i].band == s.band)) {
                return false;
            }
        }
       
        songs[current_songs_count] = s; // add song to the player
        current_songs_count++; // update the number of songs
        current_size += s.size; // add the size of the song to the player's size
        return true;
    }
   
    // additional method to print the stats
    void printStats() {
        cout<<"************************************"<         cout<<"    Name        :"<         cout<<"    Total Songs : "<         cout<<"    Total Space : "<         cout<<"    Free Space : "<<(size_allowed-current_size)<         cout<<"************************************"<     }
    private:
    typedef struct Song {
        string band;
        string title;
        string length;
        float size;
    } Song;
   
    static const int MAX_SONGS_ALLOWED = 1000;
    int size_allowed;
    int current_size;
    int current_songs_count;
    Song songs[MAX_SONGS_ALLOWED];
    string name;
};

int main() {
    Player p("My Music Player", 1000); // create a music player with 1Gb space
   
    p.printStats();
    cout<     p.addSong("The Pebbles", "I am Fortunate", "2:23", 20);
   
    p.printStats();
    return 0;
}

// OUTPUT


Related Solutions

Song struct to store the data for a single song (make it a private member), and you must have an array of Song structures as a member variable.
USE C++ Song struct to store the data for a single song (make it a private member), and you must have an array of Song structures as a member variable.Player(string name, float size) a constructor for the class. ’name' is a name for it'size' is a maximum capacity in Mb.addSong(string band, string title, string length, float size) a function for adding a new song.'band' is a name of the band'title' is a name of the song'length' is a time length of...
myLinkedList.java>>>>>>>> public class MyLinkedList implements MiniList<Integer>{ /* Private member variables that you need to declare: **...
myLinkedList.java>>>>>>>> public class MyLinkedList implements MiniList<Integer>{ /* Private member variables that you need to declare: ** The head pointer ** The tail pointer */ public class Node { // declare member variables (data and next) // finish these constructors public Node(int data, Node next) {} public Node(int data) {} // HINT: use this() with next = null } // Initialize the linked list (set head and tail pointers) public MyLinkedList() {} @Override public boolean add(Integer item) { return false; }...
Recall that for a random variable to be a binomial random variable, you must have an...
Recall that for a random variable to be a binomial random variable, you must have an experiment which meets the following three criteria: 1: There are exactly two outcomes for each trial. 2: There are a fixed number (n) of trials. 3: The trials are independent, and there is a fixed probability of success (p) and failure (q) for each trial. For each of the two situations described below, please indicate if the variable X (as defined in each situation)...
1. Define a class counterType to implement a counter. Your class must have a private data...
1. Define a class counterType to implement a counter. Your class must have a private data member counter of type int and functions to set counter to the value specified by the user, initialize counter to 0, retrieve the value of counter, and increment and decrement counter by one. The value of counter must be nonnegative. 2. Some of the characteristics of a book are the title, author(s), publisher, ISBN, price, and year of publication. Design a class bookType that...
The Encrypt class has an integer private data member 8 element array named digits. The first four elements (0 ~ 3) are to store the original 4 digits integer and the next four (4 ~ 7) are to store the encrypted data
C++ Please Modify the code and create a new header fileA company wants to transmit data over the telephone, but is concerned that its phones could be tapped. All of the data are transmitted as four-digit integers. The company has asked you to write a program that encrypts the data so that it can be transmitted more securely. Your program should read a four-digit integer and encrypt it as follows: Replace each digit by (the sum of that digit plus...
(MUST BE DONE IN C (NOT C++)) In this task, you will have to make sure...
(MUST BE DONE IN C (NOT C++)) In this task, you will have to make sure you understood the concept of “the dot” in programming. Go ahead and declare an array of characters with a default length (whichever length you want, it's fine). Next, you want to ask the user for a phrase and store the characters in your array, but before you do that, ask the user for an estimated length of the array. If the length given is...
Write a C program that summarizes an order from a fictitious store. You must have these...
Write a C program that summarizes an order from a fictitious store. You must have these four lines in your program: float bike_cost, surfboard_cost; float tax_rate, tax_amount; int num_bikes, num_surfboards; float total_cost_bikes, total_cost_surfboards; float total_cost, total_amount_with_tax;
Write a C program that summarizes an order from a fictitious store. You must have these...
Write a C program that summarizes an order from a fictitious store. You must have these four lines in your program: float bike_cost, surfboard_cost; float tax_rate, tax_amount; int num_bikes, num_surfboards; float total_cost_bikes, total_cost_surfboards; float total_cost, total_amount_with_tax; You will assign your own unique values for each of the variables, except the totals which are computed. No other variables are needed in the program. For example, you will see the numbers I picked in my program in the sample output below. I...
language c++(Data structure) You have to read a file and store a data in character array...
language c++(Data structure) You have to read a file and store a data in character array ( you cant initialize a character array, you have to code generically) code must be generic u must read a file onece u cant use built in function etc string, code in classes if u initialized a char array or ur code doesn't run i will dislike and report u you can use link list to store data
Ben Graham stated that "if you want to make money on Wall Street, you must have...
Ben Graham stated that "if you want to make money on Wall Street, you must have the proper psychological attitude." Quoting the philosopher, Spinoza, Graham said "you must look at things in the aspect of eternity". What does this mean? How did this change Warren Buffet's life and the trajectory of investor psychology? And does this investment guidance hold true given the unprecedented swings in the stock market today?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT