Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

you can take a day to give me the answer, but please give me an answer that work

ID: 3786414 • Letter: Y

Question

you can take a day to give me the answer, but please give me an answer that works.

Many of us have large digital music collections that are not always very well organized. It would be nice to have a program that would manipulate our music collection based on attributes such as artist, album title, song title, genre, song length, number times played, and rating. For this assignment you will write a basic digital music manager (DMM).

Your DMM program must have a text-based interface which allows the user to select from a main menu of options including: (1) load, (2) store, (3) display, (4) insert, (5) delete, (6) edit, (7) sort, (8) rate, (9) play, (10) shuffle, and (11) exit. For Part I of the assignment, you will only need to complete the main menu, (1) load, (2) store, (3) display, (6) edit, (8) rate, (9) play, and (11) exit features. The other features will be completed in the next part of the assignment.

What must the main menu contain?

The main menu must display the following commands:

(1)   load

(2)   store

(3)   display

(4)   insert

(5)   delete

(6)   edit

(7)   sort

(8)   rate

(9)   play

(10) shuffle

(11) exit

After a command is selected and completed, your program must display the main menu again. This procedure will continue until the “exit” command is selected.

What must “load” do?

The “load” command must read all records from a file called musicPlayList.csv (you may find a sample file here) into a dynamic doubly linked list. The doubly linked list is considered the main playlist. As each record is read from the file, it must be inserted at the front of the list. Each record consists of the following attributes:

Each attribute, in a single record, will be separated by a comma in the .csv (comma separated values) file. This means that you will need to design an algorithm to extract the required attributes for each record. Each field in each record will have a value. You do not need to check for null or empty values.

You must define a struct called Record to represent the above attributes. Also, do not forget that the Song Length must be represented by another struct called Duration. Duration is defined as follows:

Finally, each struct Node in the doubly linked list must be defined as follows:

What must “store” do?

The “store” command writes the current records, in the dynamic doubly linked list, to the musicPlayList.csv file. The store will completely overwrite the previous contents in the file.

What must “display” do?

The “display” command prints records to the screen. This command must support two methods, one of which is selected by the user:

Print all records.

Print all records that match an artist.

What must “edit” do?

The “edit” command must allow the user to find a record in the list by artist. If there are multiple records with the same artist, then your program must prompt the user which one to edit. The user may modify all of the attributes in the record.

What must “rate” do?

The “rate” command must allow the user to assign a value of 1 – 5 to a song; 1 is the lowest rating and 5 is the highest rating. The rating will replace the previous rating.

What must “play” do?

The “play” command must allow the user to select a song, and must start “playing” each song in order from the current song. “Playing” the song for this assignment means displaying the contents of the record that represents the song for a short period of time, clearing the screen and showing the next record in the list, etc. This continues until all songs have been played.

What must “exit” do?

The “exit” command saves the most recent list to the musicPlayList.csv file. This command will completely overwrite the previous contents in the file.

IV. Logical Block Diagram

The logical block diagram for your doubly linked list should look like the following:

As you can see from the illustration a doubly linked list has a pointer to the next node and the previous node in the list. The first node’s previous node pointer is always NULL and the last node’s next pointer is always NULL. When you insert and delete nodes from a doubly linked list, you must always carefully link the previous and next pointers.

here is a sample csv file

Swift, Taylor 1989 Shake it Off Pop 3:35 12 3 Drake NOTHING WAS THE SAME Own it Rap 3:23 3 3 Drake YOU WELCOME The Motto Rap 4:13 7 4 Perri, Christina HEAD OF HEART Trust Pop 2:35 3 5 Bieber, Justin PURPOSE No Sense Pop 4:12 6 1 Eminem SHADYXV Vegas Rap 3:37 8 3 Adele 25 Remedy Pop 4:11 24 4 Swift, Taylor RED Stay Stay Stay Pop 4:42 5 1 Brooks, Garth FRESH HORSES The Old Stuff Country 2:57 11 2

Explanation / Answer

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define strlength 25;

struct node {

            struct node *prev;

            char artist[strlength];

            char albumtitle[strlength];

            char songtitle[strlength];

            char genre[strlength];

           int songlen;

            int num_ts_played;

            int rating;

            struct node *next;

}   *h, *temp, *temp1, *temp2, *temp4, *temp3;

void insert();

void delete();

void sort();

void edit();

void store(int);

void load();

void display();

void rate();

int count = 0;

int count1=0;

void main()

{

            int ch;

            h = NULL;

            temp = temp1 = NULL;

            printf(" 1 - load");

            printf(" 2 - store");

            printf(" 3 - display");

            printf(" 4 - insert");

            printf(" 5 - delete");

            printf(" 6 - sort");

            printf(" 7 - edit");

            printf(" 8 - rate");

            printf(" 9 - exit");

            while (1)

            {

                        printf(" Enter choice : ");

                        scanf("%d", &ch);

                        switch (ch)

                        {

                                    case 1:

                                                load();

                                                break;

                                    case 2:

                                                store();

                                                break;

                                    case 3:

                                                display();

                                                break;

                                    case 4:

                                                insert();

                                                sort();

                                                break;

                                    case 5:

                                                delete();

                                                break;

                                    case 6:

                                                sort();

                                                break;

                                    case 7:

                                                edit();

                                                break;

                                    case 8:

                                                rate();

                                                break;

                                    case 9:

                                                exit(0);

                                                break;

                                    default:

                                                printf(" Wrong choice menu");

                        }

            }

}

/* TO create an empty node */

void create()

{

            int data;

            temp = (struct node *)malloc(sizeof(struct node));

            temp->prev = NULL;

            temp->next = NULL;

            printf("Artist Name: ");

            scanf("%s", temp->artist);

            printf("Album title: ");

            scanf("%s", temp->albumtitle);

            printf("Song title: ");

            scanf("%s", temp->songtitle);

            printf("Generic name: ");

            scanf("%s", temp->genre);

            printf("Length of the song: ");

            scanf("%d", temp->songlen);

            printf("Number of times played: ");

            scanf("%d", temp->num_ts_played);

            printf("Rating: ");

            scanf("%d", temp->rating);

            count++;

}

/* TO insert at beginning */

void insert1()

{

            if (h == NULL)

            {

                        create();

                        h = temp;

                        temp1 = h;

            }

            else

            {

                        create();

                        temp->next = h;

                        h->prev = temp;

                        h = temp;

            }

}

/* To delete an element */

void delete()

{

            int i = 1;

            char song[strlength];

            printf(" Enter title of the song : ");

            scanf("%s", song);

            temp2 = h;

            if (strcmp(temp2->songtitle, song) == 0)

            {

                        printf(" Error : Position out of range to delete");

                        return;

            }

            if (h == NULL)

            {

                        printf(" Error : Empty list no elements to delete");

                        return;

            }

            else

            {

                        while (temp2->songtitle, song)

                                    == 0)

                        {

                                    temp2 = temp2->next;

                                    i++;

                        }

                        if (i == 1)

                        {

                                    if (temp2->next == NULL)

                                    {

                                                printf("Node deleted from list");

                                                free(temp2);

                                                temp2 = h = NULL;

                                                return;

                                    }

                        }

                        if (temp2->next == NULL)

                        {

                                    temp2->prev->next = NULL;

                                    free(temp2);

                                    printf("Node deleted from list");

                                    return;

                        }

                        temp2->next->prev = temp2->prev;

                        if (i != 1)

                                    temp2->prev->next = temp2->next;   /* Might not need this statement if i == 1 check */

                        if (i == 1)

                                    h = temp2->next;

                        printf(" Node deleted");

                        free(temp2);

            }

            count--;

}

/* Traverse from beginning */

void display() {

            temp2 = h;

            if (temp2 == NULL)

            {

                        printf("List empty to display ");

                        return;

            }

            printf(" Linked list elements from begining : ");

            while (temp2->next != NULL)

            {

                        printf(" %s ", temp2->artist);

                        printf(" %s ", temp2->albumtitle);

                        printf(" %s ", temp2->songtitle);

                        printf(" %s ", temp2->genre);

                        printf(" %d ", temp2->songlen);

                        printf(" %d ", temp2->num_ts_played);

                        printf(" %d ", temp2->rating);

                        temp2 = temp2->next;

            }

            printf(" %s ", temp2->songtitle);

}

/* To search for an element in the list */

void search() {

            int count = 0;

            char artist[strlength];

            temp2 = h;

            if (temp2 == NULL)

            {

                        printf(" Error : List empty to search for data");

                        return;

            }

            printf(" Enter value to search : ");

            scanf("%s", artist);

            while (temp2 != NULL)

            {

                        if (strcmp(temp2->artist, artist) == 0)

                        {

                                    printf(" Data found in %d position", count + 1);

                                    return;

                        }

                        else

                                    temp2 = temp2->next;

                        count++;

            }

            printf(" Error : %d not found in list", data);

}

/* To update a node value in the list */

void edit()

{

            char album[strlength];

            char album1[strlength];

            printf(" Enter album title to be updated : ");

            scanf("%d", &album);

            printf(" Enter new data : ");

            scanf("%d", &album1);

            temp2 = h;

            if (temp2 == NULL)

            {

                        printf(" Error : List empty no node to update");

                        return;

            }

            while (temp2 != NULL)

            {

                        if (strcmp(temp2->albumtitle, album) == 0)

                        {

                                    temp2->albumtitle = album;

                                    display();

                                    return;

                        }

                        else

                                    temp2 = temp2->next;

            }

            printf(" Error : %d not found in list to update", data);

}

/* To sort the linked list */

void sort()

{

            int i, j, x;

            temp2 = h;

            temp4 = h;

            temp3 = h;

            if (temp2 == NULL)

            {

                        printf(" List empty to sort");

                        return;

            }

            for (temp2 = h; temp2 != NULL; temp2 = temp2->next)

            {

                        for (temp4 = temp2->next; temp4 != NULL; temp4 = temp4->next)

                        {

                                    if (strcmp(temp2->genre, temp4->genre) > 0)

                                    {

                                                temp3 = temp2;

                                                temp2 = temp4;

                                                temp4 = temp3;

                                    }

                        }

            }

            display();

}

void load()

{

            FILE *fp;

          

            char ch;

            fp = fopen("test.txt", "r");

            while ((ch = getc(file)) != EOF)

            {

                        temp = (struct node *)malloc(sizeof(struct node));

                        temp->prev = NULL;

                        temp->next = NULL;

                      

                        fscanf("%s", temp->artist);

                        fscanf("%s", temp->albumtitle);

                        fscanf("%s", temp->songtitle);

                        fscanf("%s", temp->genre);

                      fscanf("%d", temp->songlen);

                        fscanf("%d", temp->num_ts_played);

                        fscanf("%d", temp->rating);

                        temp->next = h;

                        h->prev = temp;

                        h = temp;

                        count1++;

            }

            fclose(fp);

}

void store()

{

            FILE *fp;

            temp = (struct node *)malloc(sizeof(struct node));

            temp->prev = NULL;

            temp->next = NULL;

            char ch;

            fp = fopen("test.txt", "w");

            if (fp)

            {

                        for (i = 0; i <= count1; ++i)

                        {

                                    fprintf("%s ", temp->artist);

                                    fprintf("%s ", temp->albumtitle);

                                    fprintf("%s ", temp->songtitle);

                                    fprintf("%s ", temp->genre);

                                    fprintf("%d ", temp->songlen);

                                    fprintf("%d ", temp->num_ts_played);

                                    fprintf("%d ", temp->rating);

                                    fprintf(" ");

                        }

            }

            fclose(fp);

}

void rate()

{

    temp2 = h;

            char song[strlength];

            int r;

            printf("rate the songs: ");

            printf("enter the song to rate: ");

            scanf("%s", &song);

    if (temp2 == NULL)

    {

        printf("List empty to display ");

        return;

    }

  

    while (temp2->next != NULL)

    {

        if(strcmp(temp2->songtitle,song)==0)

            {

                        printf("enter the rate(1-5): ");

                                    scanf("%d", r);

            temp2->rating=r;

            }

                        else

                        {

                                    temp2=temp2->next;

                        }

            }

}