Kat H.

asked • 09/29/21

C++. Create a program that helps keeping track of song lists. Include code.

This program is an exercise in building, traversing, and destroying linear linked lists. The use of recursion should be included at least once in each assignment to better prepare us for future programs. Avoid multiple traversals whenever possible.

Programming Assignment: For programming assignment, we are going to create a program that helps keeping track of song lists.

Your primary job will be to create an ADT for Song and an ADT for SongList

Part I: The Song ADT

The information about a song should include:

Artist name (e.g., Eminem)

Title (e.g., Lose Yourself)

Length (e.g., 5.23)

Number of likes (e.g., 654,000)

Part II: The SongList ADT

The data members for SongList should be a head pointer to a linear linked list of Song objects and the number of songs in the list. The songs should be organized by popularities with the most popular song as the first node in the list.

This ADT must have public member functions to perform the following:

  1. Constructor - Construct an object and initialize the data members
  2. Destructor - Release all dynamic memory and reset data members to their zero equivalent value
  3. Add a new song
  4. Edit the number of likes for a song
  5. Display all songs in the list
  6. Display all songs for an artist (in order of popularity)
  7. Remove all songs with fewer than M likes, where M is sent in as an argument

Part III: The driver or the test program

The test program needs to first load the test data set from external file at the beginning of the program.

The menu-based user interface should allow user to use/test ALL the functionalities of the program. Try to make the user interface easier to use.

  1. Always prompt user when you need input data.
  2. The prompt needs to be meaningful. Example works great. E.g. “Enter the minimum likes (e.g 1000): “
  3. When asking user to choose some existing data, index works great. You can display the data with index preceding each one first.

General Syntax Rules

  1. Do not use statically allocated arrays in your classes or structures. All memory must be dynamically allocated and kept to a minimum for the classes! You can only use statically allocated arrays for temporary storage, such as local variables.
  2. Global variables are not allowed. global constants are encouraged
  3. Do not use the String class! (use cstring, arrays of characters instead); you may use the cstring library with strlen, strcpy, strcmp etc
  4. Avoid using return from within the body of a loop
  5. Avoid using while(1) type of syntax
  6. Strive towards structured programming techniques
  7. Remember that at least one function needs to be written using recursion!
  8. For functions that have non-void return types, make sure to return a value through each path through the function.
  9. NEVER pass class types by value (always by reference); NEVER return class types by value. If you don’t want the objects modified, put const there.
  10. Use the iostream library for all I/O; do not use stdio.h for I/O
  11. Use of external data files is required
  12. MOST IMPORTANT:

BACKUP your files before creating a TAR archive!!!!

Your projects will be judged based on the use of classes, member functions, arguments, data structures, pointers, efficiency, and how well the software demonstrates that it has been fully tested. The code needs to compile and run, and include a test program for the member functions provided. It is not appropriate to hard code in the test cases - all tests should be interactive with the user. Your user interface must be clear for us to thoroughly test all features.


1 Expert Answer

By:

Richard C. answered • 10/13/21

Tutor
New to Wyzant

Hi! I am a full time tutor and contractor with python!

Richard C.

#include "LinkedList.h" // Default Constructor creates the head node. LinkedList::LinkedList() { head->song = "head (contains no song data)"; head->artist = "head (contains no artist data)"; head->next = NULL; listLength = 0; } // Setter adds a node to the list at a given position. // Takes a node and list position as parameters. // Position must be between 1 and the number of data nodes. // Returns true if the operation is successful. bool LinkedList::insertNode(node* newNode, int position) { if ((position <= 0) || (position > listLength + 1)) { cout << "nError: the given position is out of range.n"; return false; } if (head->next == NULL) { head->next = newNode; listLength++; return true; } int count = 0; node* p = head; node* q = head; while (q) { if (count == position) { p->next = newNode; newNode->next = q; length++; return true; } p = q; q = p->next; count++; } if (count == position) { p->next = newNode; newNode->next = q; listLength++; return true; } cout << "nError: node was not added to list.n"; return false; } // Setter removes a node by its given position. // Returns true if the operation is successful. bool LinkedList::removeNode(int position) { if ((position <= 0) || (position > listLength + 1)) { cout << "nError: the given position is out of range.n"; return false; } if (head->next == NULL) { cout << "nError: there is nothing to remove.n"; return false; } int count = 0; node* p = head; node* q = head; while (q) { if (count == position) { p->next = q->next; delete q; listLength--; return true; } p = q; q = p->next; count++; } cout << "nError: nothing was removed from the list.n"; return false; } // Prints each node in the list in consecutive order, // starting at the head and ending at the tail. // Prints the data to the console. void LinkedList::printList() { node* p = head; node* q = head; cout << "n---------------------------n"; cout << "Song Playlist n"; while (q) { p = q; cout << "n-----------------------------n"; cout << "t position: " << count << endl; cout << "t song: " << p->song << endl; cout << "t artist: " << p->artist << endl; q = p->next; count++; } } // Destructor de-allocates memory used by the list. LinkedList::~LinkedList() { node* p = head; node* q = head; while (q) { p = q; q = p->next; if (q) delete p; } }
Report

10/13/21

Richard C.

#include "LinkedList.h" using namespace std; int main() { // STEP 1: Create some unlinked song nodes. node* A = new node; A->song = "We Are"; A->artist = "Vertical Horizon"; node* B = new node; B->song = "I Stand Alone"; B->artist = "Godsmack"; node* C = new node; C->song = "Heir Apparent"; C->artist = "Opeth"; node* D = new node; D->song = "Fear of the Dark"; D->artist = "Iron Maiden"; node* E = new node; E->song = "Blue Monday"; E->artist = "New Order"; node* F = new node; F->song = "The Moth"; F->artist = "Aimee Mann"; // STEP 2: Build a list of three song nodes by appending to end of list. LinkedList myList; myList.insertNode(A, 1); myList.insertNode(B, 2); myList.insertNode(C, 3); myList.insertNode(D, 4); myList.printList(); // STEP 3: Insert a node into middle of list. myList.insertNode(E, 2); myList.printList(); // STEP 4: Insert node at the front of list. myList.insertNode(F, 1); myList.printList(); // STEP 5: Remove the last node from the list. myList.removeNode(6); myList.printList(); // STEP 6: Remove the first node from the list. myList.removeNode(1); myList.printList(); // STEP 7: Remove a node from the middle of the list. myList.removeNode(3); myList.printList(); return 0; }
Report

10/13/21

Richard C.

Due to formatting restrictions, I was only able to put the first comment in a nice to read format. If you need further explanation, fell free to contact me!
Report

10/13/21

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.