Question

Please use C programming to write the code to solve the following problem. Also, please use the i...

Please use C programming to write the code to solve the following problem. Also, please use the instructions, functions, syntax and any other required part of the problem. Thanks in advance. Use these functions below especially:

void inputStringFromUser(char *prompt, char *s, int arraySize);

void songNameDuplicate(char *songName);

void songNameFound(char *songName);

void songNameNotFound(char *songName);

void songNameDeleted(char *songName);

void artistFound(char *artist);

void artistNotFound(char *artist);

void printMusicLibraryEmpty(void);

void printMusicLibraryTitle(void);

const int MAX_LENGTH = 1024;

You will write a program that maintains information about your personal music library using a Linked List data structure. The program will allow you to add and delete entries from your personal music library, to search your personal music library for songs by song name, and to print out the entire list of your library. This lab will be due in the week of April 1.

Your Personal Music Library. The data in your personal music library will be stored in memory with the use of a linked list, with one list node per song. Each node will contain three strings: a song’s name, its artist, and its genre (the type of music). The linked list must be kept in sorted alphabetical order, by song name, beginning with A through Z (i.e. increasing alphabetical order). No two songs in your personal music library should have the same name. Your program should be “menu” driven, with the user being offered a choice of the following five “commands”:
Command I. Insert a new song into the library. The program should prompt the user for a new song name, its artist’s name, and its genre. This information must be placed in a new node that has been created using the malloc function (to be clear, you must use malloc for this purpose). This node should then be inserted at the appropriate (alphabetical) position in the linked list. Don’t forget that the music library must be stored in increasing order, by song name. If a node with the given song name is already in the music library, an error message should be output, and the new node should not be inserted into the linked list.
Command D. Delete an entry from your the library. The program should prompt the user for the name of the song to be deleted, and then find and delete the node containing that song name from the library. If no node with the given song name is found, an error message should be output. All memory allocated for a deleted entry must be released back to the system using the free function. This includes not only the memory allocated for the node, but also the strings in the node that would have been separately allocated.
Command S. Search for a user supplied song name in the library. The program should print the name, artist, and genre of the song, with each piece of information on a separate line. If no node with the given song name is found, an error message should be output.
Command P. Print your personal music library, in alphabetical order by song name. Print the song name, artist, and genre of each song, each on a separate line. A blank line should be printed between each song.
Command Q. Quit the program. When the program is given the Q command, it should delete all of the nodes in the linked list, including all the strings contained

in each node. Deletion means both removing from the list, but also freeing all dynamically allocated memory using call the free function. It should then print the (what should be an empty) linked list.
To assist you in the production of your program, we have provided you with a file, musiclibrary.c, that contains part of the complete program. This program is provided on the course website along with this lab. This “skeleton” of the lab 9 program includes all of the C statements required to implement the menu driven parts of the program. It also includes a few helpful functions for reading data and printing messages. You should take this file and edit it to become your version of Lab9.c. Note, however, that you may not change any of the code in the existing implementation of the skeleton program, except where indicated in comments. In particular, you must use the inputStringFromUser() function and the prompts provided to obtain inputs from the user, and you must use the given Node structure. In addition we strongly recommend that you do your work for this lab in the following way:

• Read the entire skeleton program carefully. Take note of the provided functions for reading strings, printing the name, artist and genre of a song, and for printing error messages. Using these functions will make it easier for you to satisfy the exercise and marker programs.
• Add the function for inserting a new node(the I command) into the linked list. Your function will need to read the name, artist, and genre of a song. Test your program by trying to insert nodes into the linked list. Try to insert nodes with both new and duplicate song names.
• Add a function for printing the linked list (the P command). Test your program by inserting songs into the linked list and then printing them out. Are the entries in the correct order? • Add a function that searches the linked list for a given song name and then either prints the appropriate song or, if a node is not found, prints an error message. This is the S command.
• Add the statements that need to be executed when the Q command is entered. These statements should delete the linked list by using calls to the free function. To check your work, print the linked list after the elements have been deleted. • Add a function for deleting a song from the personal music library. It will need to search the linked list for a given song name, delete the appropriate node from the linked list, and then use the free function to release the memory used to store the node, as well as all the memory that the node uses for storing strings. If the given song name is not found in the music library, print an error message.
We recommend that you test your program after attempting to complete each step. This way, if your program no longer works, you will know which statements are causing the error. Complete each step before moving on to the next one.

Sample Output From Executing The Program
Here is a sample output from an execution of the program that you are to prepare.

Personal Music Library.
Commands are I (insert), D (delete), S (search by song name), P (print), Q (quit).
Command --> P
The music library is empty.
Command --> I
Song name --> The Shade
Artist --> Metric
Genre --> Rock

Command --> I
Song name --> Heads Will Roll
Artist --> Yeah Yeah Yeahs
Genre --> Punk

Command --> I
Song name --> Bad Boys Need Love Too
Artist --> Bahamas (Afie Jurvanen)
Genre --> Folk

Command --> P

My Personal Music Library:

Bad Boys Need Love Too
Bahamas (Afie Jurvanen)
Folk

Heads Will Roll
Yeah Yeah Yeahs
Punk

The Shade
Metric
Rock

Command --> I
Song name --> Heads Will Roll
Artist --> Yeah Yeah Yeahs
Genre --> Punk

A song with the name 'Heads Will Roll' is already in the music library.
No new song entered.

Command --> I
Song name --> Adult Diversion
Artist --> Alvvays
Genre --> Pop

Command --> P

My Personal Music Library:

Adult Diversion
Alvvays
Pop

Bad Boys Need Love Too
Bahamas (Afie Jurvanen)
Folk

Heads Will Roll
Yeah Yeah Yeahs
Punk

The Shade
Metric
Rock

Command --> S

Enter the name of the song to search for --> Bad Boys Need Love Too

The song name 'Bad Boys Need Love Too' was found in the music library.

Bad Boys Need Love Too
Bahamas (Afie Jurvanen)
Folk

Command --> S

Enter the name of the song to search for --> Young Blood

The song name 'Young Blood' was not found in the music library.

Command --> D

Enter the name of the song to be deleted --> The Shade

Deleting a song with name 'The Shade' from the music library.

Command --> P

My Personal Music Library:

Adult Diversion
Alvvays
Pop

Bad Boys Need Love Too
Bahamas (Afie Jurvanen)
Folk

Heads Will Roll
Yeah Yeah Yeahs
Punk

Command --> Q

Deleting a song with name 'Adult Diversion' from the music library.

Deleting a song with name 'Bad Boys Need Love Too' from the music library.

Deleting a song with name 'Heads Will Roll' from the music library.

The music library is empty.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node   
{
char name[40],artist[40],genre[40];
struct node *next;
};
struct node *head=NULL;   
struct node *getnode(char *n,char *a,char *g)
{
struct node *ptr;
ptr=(struct node *)malloc(sizeof(struct node));
strcpy(ptr->name,n);
strcpy(ptr->artist,a);
strcpy(ptr->genre,g);
ptr->next=NULL;
return ptr;
}
struct node* search(char *n)   
{
struct node *s;
int flag=0;
if(head==NULL)
return NULL;
s=head;
while(s!=NULL)
{
if(strcmp(s->name,n)==0)
return s;
s=s->next;
}
return NULL;
}
void insert()   
{
char n[40],a[40],g[40];
struct node *ptr,*s,*s1;
int flag=0;
fflush(stdin);
printf("\nEnter the song name:");
gets(n);
printf("\nEnter the artist name: ");
gets(a);
printf("\nEnter the genre: ");
gets(g);
s=search(n);
if(s!=NULL)
{
printf("\nSong already present in list. Insertion not possible.\n");
return;
}
ptr=getnode(n,a,g);
if(head==NULL)
head=ptr;
else if(strcmp(ptr->name,head->name)<0)
{
ptr->next=head;
head=ptr;
}
else
{
s=head;
s1=head->next;
while(s1!=NULL)
{
if((strcmp(ptr->name,s->name)>=0)&&((strcmp(ptr->name,s1->name)<0)))
{
s->next=ptr;
ptr->next=s1;
flag=1;
break;
}
else
{
s=s->next;
s1=s1->next;
}
}
if(flag==0)
s->next=ptr;
}
}
void deletesong(char *s)   
{
struct node *a1,*a2,*a3;
int flag=0;
printf("\nDeleting song named %s from music library\n",s);
a1=head;
a2=head->next;
if(a1->next==NULL)
{
head=NULL;
free(a1);
}
else if(a2->next==NULL)
{
if(strcmp(s,a1->name)==0)
{
head=a2;
free(a1);
}
else
{
head=a1;
head->next=NULL;
free(a2);
}
}
else
{
if(strcmp(s,a1->name)==0)
{
head=a2;
free(a1);
}
else
{
while((a2->next)!=NULL)
{
if(strcmp(s,a2->name)==0)
{
a3=a2->next;
a1->next=a3;
free(a2);
flag=1;
break;
}
else
{
a1=a1->next;
a2=a2->next;
}
}
if(flag==0)
{
a1->next=NULL;
free(a2);
}
}
}
}
void display()
{
struct node *s;
if(head==NULL)
printf("\nMusic Library is empty\n");
else
{
s=head;
printf("\nMusic library contents: ");
while(s!=NULL)
{
printf("\nSong: %s\nArtist: %s\nGenre: %s\n\n",s->name,s->artist,s->genre);
s=s->next;
}
}
}
void emptylibrary()   
{
struct node *s,*p;
p=head;
while(p!=NULL)
{
s=p;
p=p->next;
deletesong(s->name);
}
display();
}
main()
{
char ch,s[40];
struct node *p;
while(1)   
{
printf("\nPersonal music library.");
printf("\nI.Insert a new song");
printf("\nD.Delete a song existing in library.");
printf("\nS.Search a song in library.");
printf("\nP.Print entire music library");
printf("\nQ.Empty Music Library");
printf("\nE.Exit");
printf("\nEnter your choice: ");
fflush(stdin);
scanf("%c",&ch);
switch(ch)
{
case 'I':
insert();
break;
  
case 'D':
fflush(stdin);
printf("\nEnter song name to delete: ");
gets(s);
p=search(s);
if(p==NULL)
printf("\nSorry,song not found in library");
else
deletesong(s);
break;
  
case 'S':
fflush(stdin);
printf("\nEnter song name to search: ");
gets(s);
p=search(s);
if(p==NULL)
printf("\nSorry,song not found in library");
else
{
printf("\nSong %s found in library.\n",s);
printf("\nSong name: %s\nArtist name: %s\nGenre: %s\n",p->name,p->artist,p->genre);
}
break;
  
case 'P':
display();
break;
  
case 'Q':
emptylibrary();
break;
  
case 'E':
exit(0);
  
default:
printf("\nInvalid case.\n");
}
}
}

Add a comment
Know the answer?
Add Answer to:
Please use C programming to write the code to solve the following problem. Also, please use the i...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Many of us have large digital music collections that are not always very well organized. It...

    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:...

  • Fix my code, if I the song or the artist name is not on the vector,...

    Fix my code, if I the song or the artist name is not on the vector, I want to user re-enter the correct song or artist name in the list, so no bug found in the program #include <iostream> #include <vector> #include <string> #include <algorithm> using namespace std; class musicList{ private: vector<string> songName; vector<string> artistName; public: void addSong(string sName, string aName){ songName.push_back(sName); artistName.push_back(aName); } void deleteSongName(string sName){ vector<string>::iterator result = find(songName.begin(), songName.end(), sName); if (result == songName.end()){ cout << "The...

  • Introduction In this final programming exercise, you'll get a chance to put together many of the...

    Introduction In this final programming exercise, you'll get a chance to put together many of the techniques used during this semester while incorporating OOP techniques to develop a simple song playlist class. This playlist class allows a user to add, remove and display songs in a playlist. The Base Class, Derived Class and Test Client Unlike the other PAs you completed in zyLabs, for this PA you will be creating THREE Java files in IntelliJ to submit. You will need...

  • Please use C++ CS3358 Insert and delete a node Programming Project 2: The linked list -...

    Please use C++ CS3358 Insert and delete a node Programming Project 2: The linked list - Reference: chapter 18: Create an array of 15 student records that should not be sorted Create a liked list of 15 student record nodes. Each node is a node of one student record from the above unsorted array. The list of student records should be sorted by student ID. (Insert function without sort function to create a linked list.) (If you insert correctly, the...

  • I need c++ code Given the complete main() function, partial playlist class header playlist.h, and playlist.cpp,...

    I need c++ code 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...

  • This is a c programming problem. Would you please help me to write this problem??? I...

    This is a c programming problem. Would you please help me to write this problem??? I really appreciate it if you add comments for explanation step by step. Thank you. Reverse a Doubly linked list using recursion: Given a doubly linked list. Reverse it using recursion. Original Doubly linked list: next pointer - DDHIHI Null prev painter Reversed Doubly linked list: next pointer Start Pointer Null prev pointer Include: a) A struct for a node of the doubly linked list....

  • C programming A linked list is a linear data structure that allows us to add and remove items fro...

    c programming A linked list is a linear data structure that allows us to add and remove items from the list very quickly, by simply changing a few pointers. There are many different variations of linked lists. We have studied the doubly-linked, circular, with a dummy-header-node version of a linked list. In the class notes we studied several functions to manipulate a Linked List. For this assignment you must write the code for the following additional linked list functions: addFirst,...

  • // C code // If you modify any of the given code, the return types, or...

    // C code // If you modify any of the given code, the return types, or the parameters, you risk getting compile error. // Yyou are not allowed to modify main (). // You can use string library functions. #include <stdio.h> #include <stdlib.h> #include <string.h> #pragma warning(disable: 4996) // for Visual Studio #define MAX_NAME 30 // global linked list 'list' contains the list of patients struct patientList {    struct patient *patient;    struct patientList *next; } *list = NULL;  ...

  • Programming in C: I am trying to modify this linked list to be doubly linked list....

    Programming in C: I am trying to modify this linked list to be doubly linked list. I’m also trying to add a print in reverse function. I’m really struggling with how to change the insert function to doubly link the nodes without effecting the alphabetical sorting mechanism. Example of desired output: Enter your choice: 1 to insert an element into the list. 2 to delete an element from the list. 3 to end. ? 1 Enter a character: a The...

  • can someone please double check my code here are the requirements please help me fulfill the...

    can someone please double check my code here are the requirements please help me fulfill the requirements Using the material in the textbook (NumberList) as a sample, design your own dynamic linked list class (using pointers) to hold a series of capital letters. The class should have the following member functions: append, insert (at a specific position, return -1 if that position doesn't exist), delete (at a specific position, return -1 if that position doesn't exist), print, reverse (which rearranges...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT