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;
}

The image displays a screenshot of an error list from a development environment. It shows compilation errors for a project file named "Source.cpp" associated with the course "USM CSC 102 Set Limit 14."

### Error Details:

- **Total Errors:** 12
- **Total Warnings:** 0
- **Messages Displayed:** 0 of 15

#### Errors:
1. **Error Code E0289 (3 instances)**
   - **Description:** "no instance of constructor 'Song::Song' matches the argument list"
   - **Project:** USM CSC 102 Set Limit 14
   - **File:** Source.cpp
   - **Lines:** 105, 106, 107

2. **Error Code C4996**
   - **Description:** "'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."
   - **Project:** USM CSC 102 Set Limit 14
   - **File:** Source.cpp
   - **Line:** 37

### Explanation:
- **E0289 Error:** The error indicates that the constructor for the class `Song` is not found with the provided argument list in the code at lines 105 to 107. This may require checking the definition of the `Song` class to ensure all needed constructors are defined.

- **C4996 Warning:** The warning indicates the use of `strcpy`, which is considered unsafe due to potential buffer overflow vulnerabilities. The suggested solution is to use a safer alternative, `strcpy_s`, or suppress the warning by defining `_CRT_SECURE_NO_WARNINGS`.

This error list is typical when compiling C++ code and assists developers in identifying and resolving issues to ensure their program compiles and runs correctly.
Transcribed Image Text:The image displays a screenshot of an error list from a development environment. It shows compilation errors for a project file named "Source.cpp" associated with the course "USM CSC 102 Set Limit 14." ### Error Details: - **Total Errors:** 12 - **Total Warnings:** 0 - **Messages Displayed:** 0 of 15 #### Errors: 1. **Error Code E0289 (3 instances)** - **Description:** "no instance of constructor 'Song::Song' matches the argument list" - **Project:** USM CSC 102 Set Limit 14 - **File:** Source.cpp - **Lines:** 105, 106, 107 2. **Error Code C4996** - **Description:** "'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." - **Project:** USM CSC 102 Set Limit 14 - **File:** Source.cpp - **Line:** 37 ### Explanation: - **E0289 Error:** The error indicates that the constructor for the class `Song` is not found with the provided argument list in the code at lines 105 to 107. This may require checking the definition of the `Song` class to ensure all needed constructors are defined. - **C4996 Warning:** The warning indicates the use of `strcpy`, which is considered unsafe due to potential buffer overflow vulnerabilities. The suggested solution is to use a safer alternative, `strcpy_s`, or suppress the warning by defining `_CRT_SECURE_NO_WARNINGS`. This error list is typical when compiling C++ code and assists developers in identifying and resolving issues to ensure their program compiles and runs correctly.
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.
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