Question

In: Computer Science

The question is about C++ The main should test all functionalities of the playlist implement a...

The question is about C++

The main should test all functionalities of the playlist

implement a linked list to store songs of a playlist. A song (which is your node) is going to include the following data:

- int Song ID

- string Song Title

- string Author Title

- double Length

Don't forget to include the next pointer that will lead to the next song.

Your playlist (which is your linkedlist) is going to include the following functionalities:

- Default Constructor

- Non default constructor

- getSong(string Ttitle) that will print the information of the song object that has that specific title

- addSong() to add a new song to the end of the playlist

- removeSong() to remove a song from the beginning of the playlist

- Overload cout to display the playlist for the user

Develop a main to test your code

Solutions

Expert Solution

//C++ program

#include<iostream>
using namespace std;

typedef struct Song{
   int ID;
   string Title;
   string Author;
   double Length;
   struct Song* next;
}Song;

class PlayList{
   private:
       Song *head;
      
   public:
       PlayList(){
           head = NULL;
       }
       PlayList(int id , string title , string author , double length){
           head = new Song;
           head->ID = id;
           head->Title = title;
           head->Author = author;
           head->Length = length;
           head->next = NULL;
       }
      
       Song* getSong(string Title){
           Song*current = head;
           while(current != NULL){
               if(current->Title == Title) return current;
               current = current->next;
           }
           return NULL;
       }
       void addSong(int id , string title , string author , double length){
           Song* newNode = new Song;
           newNode->ID = id;
           newNode->Title = title;
           newNode->Author = author;
           newNode->Length = length;
           newNode->next = NULL;
          
           if(head == NULL){
               head = newNode;
               return;
           }
           Song*current = head;
           while(current->next != NULL)current = current->next;
           current->next = newNode;
       }
      
       void removeSong(){
           if(head == NULL) return;
           Song*current = head;
           head = head->next;
           delete current;
       }
      
       friend ostream & operator << (ostream& out , const PlayList &list){
           Song*current = list.head;
           while(current != NULL){
               out<<"ID: "<<current->ID<<endl;
               out<<"Title: "<<current->Title<<endl;
               out<<"Author: "<<current->Author<<endl;
               out<<"Length: "<<current->Length<<"\n\n";
               current = current->next;
           }
           return out;
       }
};

int main(){
   PlayList list;
  
   list.addSong(100,"ABC","XYZ",23.90);
   list.addSong(101,"JKL","XYZ",12.80);
   list.addSong(102,"GHJ","XYZ",13.80);
   list.addSong(103,"qwer","XYZ",34.67);
  
   cout<<list;
  
   Song* current = list.getSong("JKL");
   if(current != NULL){
       cout<<"Song found\n";
       cout<<"ID: "<<current->ID<<endl;
       cout<<"Title: "<<current->Title<<endl;
       cout<<"Author: "<<current->Author<<endl;
       cout<<"Length: "<<current->Length<<"\n\n";
   }
   else{
       cout<<"Song not found\n";
   }
  
   list.removeSong();
   cout<<"\n\nList After Removing a song from playList\n";
   cout<<list;
   return 0;
}


Related Solutions

C++ problem - Implement and add the advanced functionalities to the ADT of the BST made...
C++ problem - Implement and add the advanced functionalities to the ADT of the BST made with the fundamental functionalities: Visit - Description: It will display each of the data stored in the BST depending on the input parameter:Preorder Inorder Bidder Level by level Input - An integer (1-4) Exit - Nothing Precondition - A valid BST Postcondition - Nothing Height - Description:Will return the height of the BST Entry - Nothing Output - An integer with which to indicate...
C++ MAIN remains same Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp,...
C++ MAIN remains same Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp, you will complete the class declaration and class implementation. The following member functions are required: constructor copy constructor destructor addSong(song tune) adds a single node to the front of the linked list no return value displayList() displays the linked list as formatted in the example below no return value overloaded assignment operator A description of all of these functions is available in the textbook's...
Explain the main functionalities and features included in e-commerce servers. What factors should be included in...
Explain the main functionalities and features included in e-commerce servers. What factors should be included in the decision-making process for choosing from among the various e-commerce merchant server software packages?
Write the code in C++. Write a program to implement Employee Directory. The main purpose of...
Write the code in C++. Write a program to implement Employee Directory. The main purpose of the class is to get the data, store it into a file, perform some operations and display data. For the purpose mentioned above, you should write a template class Directory for storing the data empID(template), empFirstName(string), empLastName(string), empContactNumber(string) and empAddress(string) of each Employee in a file EmployeeDirectory.txt. 1. Write a function Add to write the above mentioned contact details of the employee into EmployeeDirectory.txt....
QUESTION 40 When you plan the test runs for a program, you should do all but...
QUESTION 40 When you plan the test runs for a program, you should do all but one of the following. Which one is it? a. list the invalid entries and unexpected user actions for each test run b. list the expected exceptions for each test run c. list the expected results for each test run d. list the valid entries for each test run 1.5 points    QUESTION 41 Which of the following for loops could you use to iterate...
Implement a non-recursive reverse print of linked list using stack and the main function to test:...
Implement a non-recursive reverse print of linked list using stack and the main function to test: You will need to finish the printReversed_nonrecursive method in ch04.LinkedStack2 class, and the ch04.UseStack2 is the main function to test. public class LinkedStack2<T> extends LinkedStack<T> { private void revPrint(LLNode<T> listRef) { if (listRef != null) { revPrint(listRef.getLink()); System.out.println(" " + listRef.getInfo()); } } public void printReversed() { revPrint(top); } /* use stack to implement non-recursive reverse print */ public void printReversed_nonrecursive() { } public...
C Programming Question: Q) Write a C - program to implement an Uprooted version (Save to...
C Programming Question: Q) Write a C - program to implement an Uprooted version (Save to parent pointer instead of child pointer, ie. parent of top is null) of Kruskal's Minimum Spanning Tree with adjacency list and min-heap as the additional data structure. Note: Please implement it in C and also keep the above conditions in mind. You can take your time. Thank you.
For this program you will implement the following utility functions to test mastery of C strings....
For this program you will implement the following utility functions to test mastery of C strings. *******you MUST use these these function***** void removeBlanks(char *src, char *dest); void replaceChar(char *src, char oldChar, char newChar); char *flipCase(const char *src); Please read the description of these functions carefully. In the removeBlanks function you will implement a routine that takes a string in as src and outputs the same string into dest but removing any blank space character encountered. For example, if the...
Problem: Write a C++ program that will implement and test the five functions described below that...
Problem: Write a C++ program that will implement and test the five functions described below that use pointers and dynamic memory allocation. The Functions: You will write the five functions described below. Then you will call them from the main function, to demonstrate their correctness. 1. minimum: takes an int array and the array's size as arguments. It should return the minimum value of the array elements. Do not use square brackets anywhere in the function, not even the parameter...
Using C++ 1. Create a main function in a main.cpp file. The main function should look...
Using C++ 1. Create a main function in a main.cpp file. The main function should look as follows int main() {return 0;} 2. Create an array. 3. Ask user to enter numbers in size of your array. 4. Take the numbers and store them in your array. 5. Go through your array and add all the numbers. 6. Calculate the average of the numbers. 7. Display the numbers, sum and average.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT