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 a Java test program, all the code should be in a single main method, that...
Write a Java test program, all the code should be in a single main method, that prompts the user for a single character. Display a message indicating if the character is a letter (a..z or A..Z), a digit (0..9), or other. Java's Scanner class does not have a nextChar method. You can use next() or nextLine() to read the character entered by the user, but it is returned to you as a String. Since we are only interested in the...
Write and test a C program to implement Bubble Sort. . In your C program, you...
Write and test a C program to implement Bubble Sort. . In your C program, you should do: Implement the array use an integer pointer, get the size of the array from standard input and use the malloc function to allocate the required memory for it. Read the array elements from standard input. Print out the sorted array, and don’t forget to free the memory. Debug your program using Eclipse C/C++ CDT.
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....
Please Use C++ to finish as the requirements. Implement a class called SinglyLinkedList. In the main...
Please Use C++ to finish as the requirements. Implement a class called SinglyLinkedList. In the main function, instantiate the SinglyLinkedList class. Your program should provide a user loop and a menu so that the user can access all the operators provided by the SinglyLinkedList class. DestroyList InitializeList GetFirst InsertFirst, InsertLast, Insert DeleteFirst, DeleteLast, Delete IsEmpty Length Print, ReversePrint
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT