Answered Essay: Please Code in C language.

Please Code in C language.

III. Overview & Requirements: 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: * Artist – a string * Album title – a string * Song title – a string * Genre – a string * Song length – a struct Duration type consisting of seconds and minutes, both integers * Number times played – an integer * Rating – an integer (1 – 5) 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: * Minutes – an integer * Seconds – an integer Finally, each struct Node in the doubly linked list must be defined as follows: * Data – a Record * Pointer to the next node * Pointer to the previous node

Ø 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: 1. Print all records. 2. 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.

Expert Answer

 

Given below is the implementation of load, store, play, display, edit , rate and exit functions as mentioned in the question. The question specifies to implement only these functionalities. Please do rate the answer if it helped. Thank you very much.

DoublyLL.h

#ifndef DoublyLL_h
#define DoublyLL_h
#include <string.h>
#include <stdio.h>
struct Duration
{
int min;
int sec;
};
struct Record
{
char artist[30];
char album[50];
char song[80];
char genre[12];
struct Duration duration;
int timesPlayed;
int rating;
};

struct Node
{
struct Record data;
struct Node* prev;
struct Node* next;
};

struct Node* addInFront(struct Node* head, char *artist, char* album, char* song, char* genre, int min, int sec, int times, int rating)
{
struct Node* n = (struct Node*)malloc(sizeof(struct Node));
n->prev = NULL;
n->next = head;
if(head != NULL)
head->prev = n;
strcpy(n->data.artist, artist);
strcpy(n->data.album, album);
strcpy(n->data.song, song);
strcpy(n->data.genre, genre);
n->data.duration.min = min;
n->data.duration.sec = sec;
n->data.timesPlayed = times;
n->data.rating = rating;
return n;

}

struct Node* findSong(struct Node* head, char* title)
{
struct Node* curr = head;
if(head == NULL)
return NULL;

while(curr != NULL)
{
if(strcmp(curr->data.song, title) == 0)
return curr;
curr = curr->next;
}
return NULL;
}

struct Node* findNextByArtist(struct Node* start, char *artist)
{
struct Node* curr = start;
if(start == NULL)
return NULL;

while(curr != NULL)
{
if(strcmp(curr->data.artist, artist) == 0)
return curr;
curr = curr->next;
}
return NULL;

}

void displaySong(struct Node* node)
{
printf(“Artist: %sn”, node->data.artist);
printf(“Album Title: %sn”, node->data.album);
printf(“Song Title: %sn”, node->data.song);
printf(“Genre: %sn”, node->data.genre);
printf(“Duration: %02d:%02dn”, node->data.duration.min, node->data.duration.sec); //display in mm:ss format
printf(“Times Played: %dn”, node->data.timesPlayed);
printf(“Rating: %dnn”, node->data.rating);
}

void displayAll(struct Node* head)
{
if(head == NULL)
printf(“List is empty n”);
else
{
struct Node* curr = head;
while(curr != NULL)
{
displaySong(curr);
curr = curr->next;
}
}
}
#endif /* DoublyLL_h */

PlaylistMain.cpp

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include “DoublyLL.h”
struct Node* load(char *filename);
void store(struct Node* head, char *filename);
void show(struct Node* head);
void edit(struct Node* head);
void rate(struct Node* head);
void play(struct Node* head);
char* inputline(char* str, int len);//helper function to get a line of input from keyboard and remove ending n
int main()
{
struct Node* head = NULL;
int choice = 0;
while(choice != 11)
{
printf(“1. loadn”);
printf(“2. storen”);
printf(“3. displayn”);
printf(“4. insertn”);
printf(“5. deleten”);
printf(“6. editn”);
printf(“7. sortn”);
printf(“8. raten”);
printf(“9. playn”);
printf(“10. shufflen”);
printf(“11. exitn”);
printf(“Enter your choice: “);
scanf(“%d”, &choice);
getchar();//remove newline
switch(choice)
{
case 1:
head = load(“musicPlayList.csv”);
break;
case 2:
store(head, “musicPlayList.csv”);
break;
case 3:
show(head);
break;
case 4:
break;
case 5:
break;
case 6:
edit(head);
break;
case 7:
break;
case 8:
rate(head);
break;
case 9:
play(head);
break;
case 10:
break;
case 11:
break;
}
}
}

struct Node* load(char *filename)
{
FILE *fp = fopen(filename, “r”);
struct Node *head = NULL;
char line[512];
char *token;
char artist[30];
char album[50];
char song[80];
char genre[12];
int min , sec;
int timesPlayed;
int rating;

if(fp == NULL)
printf(“Error opening file %sn”, filename);
else
{
while(fgets(line, 512, fp) != NULL)
{
token = strtok(line, “,”);
strcpy(artist, token);

token = strtok(NULL, “,”);
strcpy(album, token);

token = strtok(NULL, “,”);
strcpy(song, token);

token = strtok(NULL, “,”);
strcpy(genre, token);

token = strtok(NULL, “,”);
min = atoi(token);
token = strtok(NULL, “,”);
sec = atoi(token);

token = strtok(NULL, “,”);
timesPlayed = atoi(token);

token = strtok(NULL, “n”);
rating = atoi(token);

head = addInFront(head, artist, album, song, genre, min, sec, timesPlayed, rating);
}
}
fclose(fp);
return head;
}

void store(struct Node* head, char* filename)
{
FILE *fp = fopen(filename, “w”);
if(fp == NULL)
{
printf(“Error opening file %s for writingn”, filename);
return;
}
struct Node* curr = head;
while(curr != NULL)
{
fprintf(fp, “%s,%s,%s,%s,%d,%d,%d,%dn”, curr->data.artist, curr->data.album , curr->data.song, curr->data.genre,
curr->data.duration.min,curr->data.duration.sec, curr->data.timesPlayed, curr->data.rating);
curr = curr->next;
}
printf(“List stored to file %sn”, filename);
fclose(fp);
}

void show(struct Node* head)
{
int choice;
struct Node* curr = head;
char artist[30];
printf(“1. display alln”);
printf(“2. display by artistn”);
printf(“Enter your choice: “);
scanf(“%d”, & choice);
if(choice == 1)
displayAll(head);
else
{
printf(“Enter artist name: “);
getchar();//remove newline
inputline(artist, 30);
while((curr = findNextByArtist(curr, artist)) != NULL)
{
displaySong(curr);
printf(“n”);
curr = curr->next;
}
}
}

char* inputline(char* str, int len)
{
fgets(str, len, stdin);
len = strlen(str);
if(str[len-1] == ‘n’)
str[len-1] = ‘’;
return str;
}

void edit(struct Node* head)
{
int choice;
struct Node* curr = head;
char artist[30];
char ans;

printf(“Enter artist name: “);
inputline(artist, 30);

while((curr = findNextByArtist(curr, artist)) != NULL)
{
displaySong(curr);
printf(“Edit this record? y/n: “);
scanf(“%c”, &ans);
getchar(); //remove newline
if(ans == ‘y’ || ans == ‘Y’)
{
printf(“Enter new details -n”);
printf(“Album Name: “);
inputline(curr->data.album, 50);

printf(“Song Title: “);
inputline(curr->data.song, 80);

printf(“Genre: “);
inputline(curr->data.genre, 12);

printf(“Duration (min sec):” );
scanf(“%d %d”, &curr->data.duration.min, &curr->data.duration.sec);

printf(“Times played: “);
scanf(“%d”, &curr->data.timesPlayed);

printf(“Rating: “);
scanf(“%d”, &curr->data.rating);

printf(“Modified the record.n”);
break;
}
curr = curr->next;
printf(“n”);
}
}

void rate(struct Node* head)
{
char title[80];
struct Node* curr = NULL;
printf(“Enter song title: “);
inputline(title, 80);
curr = findSong(head, title);
if(curr == NULL)
printf(“No such songn”);
else
{
printf(“Current rating: %dn”, curr->data.rating);
printf(“Enter new rating: “);
scanf(“%d”, &curr->data.rating);
printf(“Updated rating for the song.n”);
}

}

void play(struct Node* head)
{
char title[80];
struct Node* curr = NULL;
printf(“Enter song title: “);
inputline(title, 80);
curr = findSong(head, title);
if(curr == NULL)
printf(“No such songn”);
else
{
while(curr != NULL)
{
printf(“Now playing…n”);
displaySong(curr);
curr = curr->next;
printf(“n”);
}
}

}

input file: musicPlayList.csv

Janet Jackson,Unbreakable,Black Eagle,Pop,2,45,1,2
Michael Jackson,Thriller,Baby be Mine,Rock,4,10,2,5
Janet Jackson,All for You,All for You,Pop,2,10,2,4

output

1. load
2. store
3. display
4. insert
5. delete
6. edit
7. sort
8. rate
9. play
10. shuffle
11. exit
Enter your choice: 1
1. load
2. store
3. display
4. insert
5. delete
6. edit
7. sort
8. rate
9. play
10. shuffle
11. exit
Enter your choice: 3
1. display all
2. display by artist
Enter your choice: 1
Artist: Janet Jackson
Album Title: All for You
Song Title: All for You
Genre: Pop
Duration: 02:10
Times Played: 2
Rating: 4

Artist: Michael Jackson
Album Title: Thriller
Song Title: Baby be Mine
Genre: Rock
Duration: 04:10
Times Played: 2
Rating: 5

Artist: Janet Jackson
Album Title: Unbreakable
Song Title: Black Eagle
Genre: Pop
Duration: 02:45
Times Played: 1
Rating: 2

1. load
2. store
3. display
4. insert
5. delete
6. edit
7. sort
8. rate
9. play
10. shuffle
11. exit
Enter your choice: 3
1. display all
2. display by artist
Enter your choice: 2
Enter artist name: Janet Jackson
Artist: Janet Jackson
Album Title: All for You
Song Title: All for You
Genre: Pop
Duration: 02:10
Times Played: 2
Rating: 4

Artist: Janet Jackson
Album Title: Unbreakable
Song Title: Black Eagle
Genre: Pop
Duration: 02:45
Times Played: 1
Rating: 2

1. load
2. store
3. display
4. insert
5. delete
6. edit
7. sort
8. rate
9. play
10. shuffle
11. exit
Enter your choice: 6
Enter artist name: Janet Jackson
Artist: Janet Jackson
Album Title: All for You
Song Title: All for You
Genre: Pop
Duration: 02:10
Times Played: 2
Rating: 4

Edit this record? y/n: n

Artist: Janet Jackson
Album Title: Unbreakable
Song Title: Black Eagle
Genre: Pop
Duration: 02:45
Times Played: 1
Rating: 2

Edit this record? y/n: y
Enter new details –
Album Name: Unbreakable
Song Title: Black Eagle
Genre: Pop
Duration (min sec):3 45
Times played: 2
Rating: 4
Modified the record.
1. load
2. store
3. display
4. insert
5. delete
6. edit
7. sort
8. rate
9. play
10. shuffle
11. exit
Enter your choice: 3
1. display all
2. display by artist
Enter your choice: 1
Artist: Janet Jackson
Album Title: All for You
Song Title: All for You
Genre: Pop
Duration: 02:10
Times Played: 2
Rating: 4

Artist: Michael Jackson
Album Title: Thriller
Song Title: Baby be Mine
Genre: Rock
Duration: 04:10
Times Played: 2
Rating: 5

Artist: Janet Jackson
Album Title: Unbreakable
Song Title: Black Eagle
Genre: Pop
Duration: 03:45
Times Played: 2
Rating: 4

1. load
2. store
3. display
4. insert
5. delete
6. edit
7. sort
8. rate
9. play
10. shuffle
11. exit
Enter your choice: 8
Enter song title: All for You
Current rating: 4
Enter new rating: 3
Updated rating for the song.
1. load
2. store
3. display
4. insert
5. delete
6. edit
7. sort
8. rate
9. play
10. shuffle
11. exit
Enter your choice: 11

Buy Essay
Calculate your paper price
Pages (550 words)
Approximate price: -

Help Me Write My Essay - Reasons:

Best Online Essay Writing Service

We strive to give our customers the best online essay writing experience. We Make sure essays are submitted on time and all the instructions are followed.

Our Writers are Experienced and Professional

Our essay writing service is founded on professional writers who are on stand by to help you any time.

Free Revision Fo all Essays

Sometimes you may require our writers to add on a point to make your essay as customised as possible, we will give you unlimited times to do this. And we will do it for free.

Timely Essay(s)

We understand the frustrations that comes with late essays and our writers are extra careful to not violate this term. Our support team is always engauging our writers to help you have your essay ahead of time.

Customised Essays &100% Confidential

Our Online writing Service has zero torelance for plagiarised papers. We have plagiarism checking tool that generate plagiarism reports just to make sure you are satisfied.

24/7 Customer Support

Our agents are ready to help you around the clock. Please feel free to reach out and enquire about anything.

Try it now!

Calculate the price of your order

Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

HOW OUR ONLINE ESSAY WRITING SERVICE WORKS

Let us write that nagging essay.

STEP 1

Submit Your Essay/Homework Instructions

By clicking on the "PLACE ORDER" button, tell us your requires. Be precise for an accurate customised essay. You may also upload any reading materials where applicable.

STEP 2

Pick A & Writer

Our ordering form will provide you with a list of writers and their feedbacks. At step 2, its time select a writer. Our online agents are on stand by to help you just in case.

STEP 3

Editing (OUR PART)

At this stage, our editor will go through your essay and make sure your writer did meet all the instructions.

STEP 4

Receive your Paper

After Editing, your paper will be sent to you via email.

× How can I help you?