Question

Introduction Welcome to Rad.io, you've been hired to work on our music streaming app, think of...

Introduction

Welcome to Rad.io, you've been hired to work on our music streaming app, think of it as Spotify only more rad! You're in charge of handling our customer’s song list. When a user selects a playlist it will load into the list a number of songs. Users can skip to the next song, move to the previous, they can select a song to play next or select a song to add to the end of their list.

Objective

You are given two header files, Song.hpp and RadList.hpp. Song holds a song’s name, artist, album, duration (in seconds) and whether or not it contains explicit lyrics. RadList keeps track of all Song objects in the linked list List. RadList also has an iterator that points to the Song object currently playing.

Complete the implementation of these classes, and make sure all tests pass. Your instructor may require you to keep your header and implementation code seperate in both .hpp and .cpp files. Your code is tested in the provided main.cpp.

You will need to implement the following functions:

  • Song Constructor - This should initialize all Song member variables.

  • Song Getters - name, artist, album, minutes, seconds and explicit lyrics should all be returned with these member functions. Keep in mind the duration in seconds is stored. The minutes() and seconds() getters should return the minutes and leftover seconds of a song. For example a song with a duration of 291 seconds should return 4 minutes and 51 seconds.

  • next() - This should move the nowPlaying iterator to the next song in the list.

  • prev() - This should move the nowPlaying iterator to the previous song in the list.

  • nowPlaying() - This should return the current Song the nowPlaying iterator is currently pointing to.

  • addToList() - This should add the passed in song to the end of the list.

  • playNext() - This should add the passed in song as the next song in the list right after the current song playing.

Initially the given code will not compile. As you complete the code, the tests should start to pass in main.cpp.

Source Code Files

You are given “skeleton” code files with declarations that may be incomplete and without any implementation. Implement the code and ensure that all the tests in main.cpp pass successfully.

  • Song.hpp: This is to be completed

  • RadList.hpp: This is to be completed

  • main.cpp: The main function tests the output of your functions. You may wish to add additional tests. During grading your main.cpp file will be replaced with the one you were provided with.

  • README.md: You must edit this file to include your name and CSUF email. This information will be used so that we can enter your grades into Titanium.

Hints

The goal of this assignment is to make a class that wraps around a linked list class. You do not need to implement the linked list class, just use the standard library implementation. You can refer to http://www.cplusplus.com/reference/list/list/?kw=list for a list of methods of the std::list class.

The use of iterators is key. It may help to draw out the list with each song and trace through the list with every operation, keeping track of where the nowPlaying iterator should point.

Make sure your code compiles, and then try and solve the logic. Focus on solving one test at a time. It’s recommended that you start with Song.hpp first and then RadList.hpp next. The order of each function is the order in which it’s recommended that you solve.

You do not need to worry about error checking although it would be a good idea!

Codes To Be Completed:

1. Song.hpp

1 #pragma once
2
3 #include <string>
4
5 class Song {
6 private:
7 std::string name_;
8 std::string artist_;
9 std::string album_;
10 unsigned int duration_;
11 bool explicit_lyrics_;
12
13 public:
14 Song(std::string, std::string, std::string, unsigned int, bool);
15
16 std::string name();
17 std::string artist();
18 std::string album();
19 unsigned int minutes();
20 unsigned int seconds();
21 bool explicit_lyrics();
22 };

2. RadList.hpp

1 #pragma once
2 #include <fstream>
3 #include <iostream>
4 #include <list>
5 #include <stdexcept>
6 #include <string>
7
8 #include "Song.hpp"
9
10 class RadList {
11 private:
12 std::list<Song> queue_;
13 std::list<Song>::iterator nowPlaying_;
14 public:
15 void loadPlaylist(const std::string&);
16 void next();
17 void prev();
18 Song nowPlaying();
19 void addToQueue(const Song&);
20 void playNext(const Song&);
21 };
22
23 void RadList::loadPlaylist(const std::string& filename) {
24 std::ifstream playlist(filename);
25
26 if (playlist.is_open()) {
27 std::string name, artist, album, duration, explicit_lyrics, toss;
28
29 // Read in everything from comma seperated values file
30 while (std::getline(playlist, name, ',')) {
31 std::getline(playlist, toss, ' '); // ignore leading space
32 std::getline(playlist, artist, ',');
33 std::getline(playlist, toss, ' '); // ignore leading space
34 std::getline(playlist, album, ',');
35 std::getline(playlist, toss, ' '); // ignore leading space
36 std::getline(playlist, duration, ',');
37 std::getline(playlist, toss, ' '); // ignore leading space
38 std::getline(playlist, explicit_lyrics);
39
40 // Construct Song and add to queue
41 queue_.push_back(Song(name, artist, album, stoi(duration), explicit_lyrics == "true"));
42 }
43
44 playlist.close();
45 nowPlaying_ = queue_.begin();
46 } else {
47 throw std::invalid_argument("Could not open " + filename);
48 }
49 }

3. main.cpp (optional)

#include <iostream>
#include <string>
#include "Song.hpp"
#include "RadList.hpp"
using std::string;
using std::cout;
using std::endl;
// Helper Functions
template <typename T>
void assertEquals(string, T, T);
int main(int argc, char const *argv[]) {
RadList jukebox;
jukebox.loadPlaylist("Downtempo.csv");
assertEquals("RadList.name()", static_cast<string>("All In Forms"), jukebox.nowPlaying().name());
jukebox.next();
assertEquals("RadList.artist()", static_cast<string>("Bonobo"), jukebox.nowPlaying().artist());
jukebox.prev();
assertEquals("RadList.minutes()", static_cast<unsigned int>(4), jukebox.nowPlaying().minutes());
assertEquals("RadList.seconds()", static_cast<unsigned int>(51), jukebox.nowPlaying().seconds());
jukebox.next();
jukebox.addToQueue(Song("Black Canyon", "Ana Caravelle", "Basic Climb", 457, false));
jukebox.next();
jukebox.playNext(Song("Tumbleweed", "9 Lazy 9", "Sweet Jones", 192, false));
assertEquals("RadList.name()/album()", jukebox.nowPlaying().name(), jukebox.nowPlaying().album());
jukebox.addToQueue(Song("Building Steam With A Grain Of Salt", "DJ Shadow", "Endtroducing...", 399, true));
jukebox.next();
assertEquals("RadList.playNext())", static_cast<string>("9 Lazy 9"), jukebox.nowPlaying().artist());
jukebox.next();
assertEquals("RadList.album()", static_cast<string>("Silver Wilkinson"), jukebox.nowPlaying().album());
jukebox.next();
assertEquals("RadList.addToQueue()", static_cast<string>("Ana Caravelle"), jukebox.nowPlaying().artist());
jukebox.next();
assertEquals("RadList.explicit_lyrics()", true, jukebox.nowPlaying().explicit_lyrics());
return 0;
}
template <typename T>
void assertEquals(string test_name, T expected, T actual) {
if (actual == expected) {
cout << "[PASSED] " << test_name << endl;
} else {
cout << "[FAILED] " << test_name
<< " - Expected: " << expected
<< ", Actual: " << actual
<< endl;
}
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please let me know if you have any doubts or you want me to modify the answer. And if you find this answer useful then don't forget to rate my answer as thumps up. Thank you! :)

//main.cpp

#include <iostream>
#include <string>

#include "Song.hpp"
#include "RadList.hpp"
using std::string;
using std::cout;
using std::endl;


template <typename T>
void assertEquals(string, T, T);

int main() {
   RadList jukebox;
   jukebox.loadPlaylist("/Users/swapnil/CLionProjects/RadList/Downtempo.csv");
   assertEquals("RadList.name()", static_cast<string>("All In Forms"), jukebox.nowPlaying().name());
   jukebox.next();
   assertEquals("RadList.artist()", static_cast<string>("Bonobo"), jukebox.nowPlaying().artist());
   jukebox.prev();
   assertEquals("RadList.minutes()", static_cast<unsigned int>(4), jukebox.nowPlaying().minutes());
   assertEquals("RadList.seconds()", static_cast<unsigned int>(51), jukebox.nowPlaying().seconds());
   jukebox.next();
   jukebox.addToQueue(Song("Black Canyon", "Ana Caravelle", "Basic Climb", 457, false));
   jukebox.next();
   jukebox.playNext(Song("Tumbleweed", "9 Lazy 9", "Sweet Jones", 192, false));
   assertEquals("RadList.name()/album()", jukebox.nowPlaying().name(), jukebox.nowPlaying().album());
   jukebox.addToQueue(Song("Building Steam With A Grain Of Salt", "DJ Shadow", "Endtroducing...", 399, true));
   jukebox.next();
   assertEquals("RadList.playNext())", static_cast<string>("9 Lazy 9"), jukebox.nowPlaying().artist());
   jukebox.next();
   assertEquals("RadList.album()", static_cast<string>("Silver Wilkinson"), jukebox.nowPlaying().album());
   jukebox.next();
   assertEquals("RadList.addToQueue()", static_cast<string>("Ana Caravelle"), jukebox.nowPlaying().artist());
   jukebox.next();
   assertEquals("RadList.explicit_lyrics()", true, jukebox.nowPlaying().explicit_lyrics());

   return 0;
}

template <typename T>
void assertEquals(string test_name, T expected, T actual) {
   if (actual == expected) {
       cout << "[PASSED] " << test_name << endl;
   }
   else {
       cout << "[FAILED] " << test_name
           << " - Expected: " << expected
           << ", Actual: " << actual
           << endl;
   }
}
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//RadList.cpp
#include "RadList.hpp"

void RadList::loadPlaylist(const std::string& filename) {
    std::ifstream playlist(filename);

    if (playlist.is_open()) {
        std::string name, artist, album, duration, explicit_lyrics, toss;

        while (std::getline(playlist, name, ',')) {
            std::getline(playlist, toss, ' ');         
            std::getline(playlist, artist, ',');
            std::getline(playlist, toss, ' ');        
            std::getline(playlist, album, ',');
            std::getline(playlist, toss, ' ');        
            std::getline(playlist, duration, ',');
            std::getline(playlist, toss, ' ');         
            std::getline(playlist, explicit_lyrics);

            queue_.push_back(Song(name, artist, album, stoi(duration), explicit_lyrics == "true"));
        }

        playlist.close();
        nowPlaying_ = queue_.begin();
    }
    else {
        throw std::invalid_argument("Could not open " + filename);
    }
}
void RadList::next() {
    nowPlaying_++;
};
void RadList::prev() {
    nowPlaying_--;
};
Song RadList::nowPlaying() {
    return *nowPlaying_;
};
void RadList::addToQueue(const Song& addSong) {
    Song temp = addSong;
    queue_.push_back(temp);
};
void RadList::playNext(const Song& addSong) {
    Song temp = addSong;
    std::list<Song>::iterator tempIt;
    tempIt = nowPlaying_;
    queue_.insert(++tempIt, addSong);
};

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//RadList.hpp

#ifndef RADLIST_RADLIST_HPP
#define RADLIST_RADLIST_HPP


#pragma once

#include <fstream>
#include <iostream>
#include <list>
#include <stdexcept>
#include <string>

#include "Song.hpp"

class RadList {
private:
    std::list<Song> queue_;
    std::list<Song>::iterator nowPlaying_;
public:
    void loadPlaylist(const std::string&);
    void next();
    void prev();
    Song nowPlaying();
    void addToQueue(const Song&);
    void playNext(const Song&);
};


#endif //RADLIST_RADLIST_HPP

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Song.cpp
#include "Song.hpp"


Song::Song(std::string name, std::string artist, std::string album,
           unsigned int duration, bool explicitLyrics)
        : name_(name),
          artist_(artist),
          album_(album),
          duration_(duration),
          explicit_lyrics_(explicitLyrics)
{
}

std::string Song::name() {
    return name_;
};
std::string Song::artist() {
    return artist_;
};
std::string Song::album() {
    return album_;
};
unsigned int Song::minutes() {
    return duration_ / 60;
};
unsigned int Song::seconds() {
    return duration_ % 60;
};
bool Song::explicit_lyrics() {
    return explicit_lyrics_;
};


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Song.hpp
#ifndef RADLIST_SONG_HPP
#define RADLIST_SONG_HPP


#pragma once

#include <string>

class Song {
private:
    std::string name_;
    std::string artist_;
    std::string album_;
    unsigned int duration_;
    bool explicit_lyrics_;

public:
    Song(std::string, std::string, std::string, unsigned int, bool);

    std::string name();
    std::string artist();
    std::string album();
    unsigned int minutes();
    unsigned int seconds();
    bool explicit_lyrics();
};


#endif //RADLIST_SONG_HPP



RadList [-/CLionProjects/RadListJ-.../main.cpp RadListmain.cpp Project ▼ *÷ *-Δ cMakeLists.txt, main cpp-品RadListapp RadList.

Add a comment
Know the answer?
Add Answer to:
Introduction Welcome to Rad.io, you've been hired to work on our music streaming app, think of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Fix my code, if I the song or the artist name is not on the vector,...

    Fix my code, if I the song or the artist name is not on the vector, I want to user re-enter the correct song or artist name in the list, so no bug found in the program #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; class musicList{ private: vector<string> songName; vector<string> artistName; public: void addSong(string sName, string aName){ songName.push_back(sName); artistName.push_back(aName); } void deleteSongName(string sName){ vector<string>::iterator result = find(songName.begin(), songName.end(), sName); if (result == songName.end()){ cout << "The...

  • The task is to write Song.cpp to complete the implementation of the Song class, as defined...

    The task is to write Song.cpp to complete the implementation of the Song class, as defined in the provided header file, Song.h, and then to complete a program (called sales) that makes use of the class. As in Project 1, an input data file will be provided containing the song name and other information in the same format as in Program 1: Artist    Song_Title    Year    Sales    Medium As before, the program (sales) which are individual copies, will use this information to compute the gross...

  • You will be building a linked list. Make sure to keep track of both the head and tail nodes.

    Ch 8 Program: Playlist (Java)You will be building a linked list. Make sure to keep track of both the head and tail nodes.(1) Create two files to submit.SongEntry.java - Class declarationPlaylist.java - Contains main() methodBuild the SongEntry class per the following specifications. Note: Some methods can initially be method stubs (empty methods), to be completed in later steps.Private fieldsString uniqueID - Initialized to "none" in default constructorstring songName - Initialized to "none" in default constructorstring artistName - Initialized to "none"...

  • Introduction In this final programming exercise, you'll get a chance to put together many of the...

    Introduction In this final programming exercise, you'll get a chance to put together many of the techniques used during this semester while incorporating OOP techniques to develop a simple song playlist class. This playlist class allows a user to add, remove and display songs in a playlist. The Base Class, Derived Class and Test Client Unlike the other PAs you completed in zyLabs, for this PA you will be creating THREE Java files in IntelliJ to submit. You will need...

  • This is for my c++ class and I would really appreciate the help, Thank you! Complete...

    This is for my c++ class and I would really appreciate the help, Thank you! Complete the definitions of the functions for the ConcessionStand class in the ConcessionStand.cpp file. The class definition and function prototypes are in the provided ConcessionStand.h header file. A testing program is in the provided main.cpp file. You don’t need to change anything in ConcessionStand.h or main.cpp, unless you want to play with different options in the main.cpp program. ___________________ Main.cpp ____________________ #include "ConcessionStand.h" #include <iostream>...

  • This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a fun...

    This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a function and three overloaded operators. You don't need to change anything in the Multiplex.h file or the main.cpp, though if you want to change the names of the movies or concession stands set up in main, that's fine. Project Description: A Multiplex is a complex with multiple movie theater screens and a variety of concession stands. It includes two vectors: screenings holds pointers...

  • Program: Playlist (C++) I'm having difficulty figuring out how to get the header file to work....

    Program: Playlist (C++) I'm having difficulty figuring out how to get the header file to work. You will be building a linked list. Make sure to keep track of both the head and tail nodes. (1) Create three files to submit. Playlist.h - Class declaration Playlist.cpp - Class definition main.cpp - main() function Build the PlaylistNode class per the following specifications. Note: Some functions can initially be function stubs (empty functions), to be completed in later steps. Default constructor (1...

  • Write the following method definitions for the DLL class: (5 pt) void push(string t, string a,...

    Write the following method definitions for the DLL class: (5 pt) void push(string t, string a, int m, int s); This pushes a new node onto the end of the list. If there are no nodes in the list, it creates the first node and adds it. Otherwise it places a new node onto the end of the list. t is the song’s title,a is the song’s artist, m is the number of minutes the song runs for, and s...

  • Many of us have large digital music collections that are not always very well organized. It...

    Many of us have large digital music collections that are not always very well organized. It would be nice to have a program that would manipulate our music collection based on attributes such as artist, album title, song title, genre, song length, number times played, and rating. For this assignment you will write a basic digital music manager (DMM). Your DMM program must have a text-based interface which allows the user to select from a main menu of options including:...

  • is there anyway you can modify the code so that when i run it i can...

    is there anyway you can modify the code so that when i run it i can see all the song when i click the select button all the songs in the songList.txt file can be shown song.java package proj2; public class Song { private String name; private String itemCode; private String description; private String artist; private String album; private String price; Song(String name, String itemCode, String description, String artist, String album, String price) { this.name = name; this.itemCode = itemCode;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT