Take the Linked List from Problem 2 and let's create a linked list of songs. To achieve this, create a Song class with the following attributes: 1. Song Title 2. Song Author 3. Song Genre 4. Song Time (i.e., how long is the song in seconds) Songs should be sorted by Title. Write overloaded methods for the relational operations that compares the titles of a song. Create an Ordered Doubly Linked List and store random songs in the Linked List.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please provide C++ program code to the following question. Please list and provide all steps with code solution and results of code when executed. .

Take the Linked List from Problem 2 and let's create a linked list of songs. To
achieve this, create a Song class with the following attributes:
1. Song Title
2. Song Author
3. Song Genre
4. Song Time (i.e., how long is the song in seconds)
Songs should be sorted by Title. Write overloaded methods for the relational
operations that compares the titles of a song. Create an Ordered Doubly Linked
List and store random songs in the Linked List.
Transcribed Image Text:Take the Linked List from Problem 2 and let's create a linked list of songs. To achieve this, create a Song class with the following attributes: 1. Song Title 2. Song Author 3. Song Genre 4. Song Time (i.e., how long is the song in seconds) Songs should be sorted by Title. Write overloaded methods for the relational operations that compares the titles of a song. Create an Ordered Doubly Linked List and store random songs in the Linked List.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 8 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

This code is not working. I'm getting errors.Can you check code again.

#include <cctype>
#include <cstring>
#include <iostream>

using namespace std;

class Song {
private:
    char* title;
    char* author;
    char* genre;
    float time;

public:
    Song();
    Song(char* t, char* a, char* g, float ti);
    ~Song();
    void Set(char* t, char* a, char* g, float ti);
    void Display();
    bool operator<(Song& a);
    bool operator<=(Song& a);
    bool operator>(Song& a);
    bool operator>=(Song& a);
    bool operator==(Song& a);
    bool operator!=(Song& a);
};

Song::Song() {
    title = NULL;
    author = NULL;
    genre = NULL;
    time = 0;
}

Song::Song(char* t, char* a, char* g, float ti) {
    title = new char[strlen(t) + 1];
    strcpy(title, t);
    author = new char[strlen(a) + 1];
    strcpy(author, a);
    genre = new char[strlen(g) + 1];
    strcpy(genre, g);
    time = ti;
}

Song::~Song() {
    delete[] title;
    delete[] author;
    delete[] genre;
}

void Song::Set(char* t, char* a, char* g, float ti) {
    title = new char[strlen(t) + 1];
    strcpy(title, t);
    author = new char[strlen(a) + 1];
    strcpy(author, a);
    genre = new char[strlen(g) + 1];
    strcpy(genre, g);
    time = ti;
}

void Song::Display() {
    cout << "Title: " << title << endl;
    cout << "Author: " << author << endl;
    cout << "Genre: " << genre << endl;
    cout << "Time: " << time << endl;
}

bool Song::operator<(Song& a) {
    if (strcmp(title, a.title) < 0)
        return true;
    return false;
}

bool Song::operator<=(Song& a) {
    if (strcmp(title, a.title) <= 0)
        return true;
    return false;
}

bool Song::operator>(Song& a) {
    if (strcmp(title, a.title) > 0)
        return true;
    return false;
}

bool Song::operator>=(Song& a) {
    if (strcmp(title, a.title) >= 0)
        return true;
    return false;
}

bool Song::operator==(Song& a) {
    if (strcmp(title, a.title) == 0)
        return true;
    return false;
}

bool Song::operator!=(Song& a) {
    if (strcmp(title, a.title) != 0)
        return true;
    return false;
}

int main() {
    Song song1("Despacito", "Luis Fonsi", "Pop", 4.42);
    Song song2("Shape of You", "Ed Sheeran", "Pop", 3.53);
    Song song3("I Don't Wanna Live Forever", "Zayn Malik", "Pop", 4.10);

    if (song1 < song2)
        cout << "song1 comes before song2" << endl;
    else
        cout << "song1 does not come before song2" << endl;

    if (song2 <= song3)
        cout << "song2 comes before or is equal to song3" << endl;
    else
        cout << "song2 does not come before or is equal to song3" << endl;

    if (song1 > song2)
        cout << "song1 comes after song2" << endl;
    else
        cout << "song1 does not come after song2" << endl;

    if (song1 >= song2)
        cout << "song1 comes after or is equal to song2" << endl;
    else
        cout << "song1 does not come after or is equal to song2" << endl;

    if (song1 == song2)
        cout << "song1 is equal to song2" << endl;
    else
        cout << "song1 is not equal to song2" << endl;

    if (song1 != song2)
        cout << "song1 is not equal to song2" << endl;
    else
        cout << "song1 is equal to song2" << endl;

    return 0;
}

90 %
Error List
Entire Solution
Code
▷abc E0289
▷ abc E0289
▷ abc E0289
XC4996
X 3
0
↑
X 12 Errors
omas hotnro nr
◄
0 Warnings ✪ 0 of 15 Messages 7 Build + IntelliSense
Description
no instance of constructor "Song::Song" matches the argument list
no instance of constructor "Song::Song" matches the argument list
no instance of constructor "Song::Song" matches the argument list
'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable
deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details.
Ln: 103
Ch: 1
Search Error List
Project
File
USM CSC 102 Set Limit 14... Source.cpp
USM CSC 102 Set Limit 14... Source.cpp
USM CSC 102 Set Limit 14... Source.cpp
USM CSC 102 Set Limit 14... Source.cpp
SPC
CRLF
Line
105
106
107
37
x
O.
Transcribed Image Text:90 % Error List Entire Solution Code ▷abc E0289 ▷ abc E0289 ▷ abc E0289 XC4996 X 3 0 ↑ X 12 Errors omas hotnro nr ◄ 0 Warnings ✪ 0 of 15 Messages 7 Build + IntelliSense Description no instance of constructor "Song::Song" matches the argument list no instance of constructor "Song::Song" matches the argument list no instance of constructor "Song::Song" matches the argument list 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use_CRT_SECURE_NO_WARNINGS. See online help for details. Ln: 103 Ch: 1 Search Error List Project File USM CSC 102 Set Limit 14... Source.cpp USM CSC 102 Set Limit 14... Source.cpp USM CSC 102 Set Limit 14... Source.cpp USM CSC 102 Set Limit 14... Source.cpp SPC CRLF Line 105 106 107 37 x O.
Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Threads in linked list
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education