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

For this assignment you will write a digital music manager (DMM). Your DMM progr

ID: 640120 • Letter: F

Question

For this assignment you will write a digital music manager (DMM).

Your DMM program must have a text-based interface which allows the user to select from a menu of options including: load, store, display, insert, delete, edit, sort, rate, and exit. The load option reads records from a file into a dynamic doubly linked list. The store command writes records, in a dynamic doubly linked list, to a file. Display prints records, and its attributes to the screen. This command must print either all records or a single record based on a search field. A search field may be any of the attributes belonging to a record. If a search field matches multiple records, then print the first match to the screen. The insert option collects information for each new song record and attributes from the user. The new song record must be placed into the list based on a selected sort option. By default, songs are inserted into the list alphabetically (a z) according to artist. Other possible sort options include alphabetical ordering based on genre, or increasing numeric value based on rating. Delete removes a record from the list. Deletion is based on song title. The edit option must allow the user to find a record in the list with any search field. The user may modify any of the attributes in the record. The rate action 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. Lastly, exit saves the most recent list to a file.

*** Please write the program in C language

A record is a struct type which consists of the following attributes:

Artist a string

Album title a string

Song title a string

Genre a string

Song length a struct type consisting of seconds and minutes, both integers

Number times played an integer

Rating an integer (1 5)

Explanation / Answer

// the following is the C program for the DMM

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>

#define max 50 // defines max=50
// struct for song length
typedef struct song_length{
   int seconds;
   int minutes;
}song_length;

// Record struct
typedef struct Record{
   char artist[max];
   char albumTitle[max];
   char songTitle[max];
   char genre[max];
   song_length* songLength;
   int timesPlayed;
   int rating;  
}Record;

// doubly linked list
typedef struct DLnode{
   Record* record;
   struct DLnode* next;
   struct DLnode* prev;
}DLnode;

// create a node of Doubly linked list
DLnode* createNode(Record* rec)
{
   DLnode* node=(DLnode*)malloc(sizeof(DLnode)); //allocate memory
   node->record=rec;
   node->next=NULL; //set next pointer to NULL
   node->prev=NULL; // set prev pointer to NULL  
}

DLnode* load(char* fname)
{
   FILE* fp=fopen(fname,"r");
   Record* rec=(Record*)malloc(sizeof(Record));
   DLnode* head=NULL,*prev=NULL;  
   if(fp==NULL) return;
   while(1)
   {
      
       if(fgets(rec->artist,max,fp)!=NULL);
       else break;
       if(fgets(rec->albumTitle,max,fp)!=NULL);
       else break;
       if(fgets(rec->songTitle,max,fp)!=NULL);
       else break;
       if(fgets(rec->genre,max,fp)!=NULL);
       else break;
       if(fscanf(fp,"%d",&rec->songLength->seconds)!=EOF);
       else break;
       if(fscanf(fp,"%d",&rec->songLength->minutes)!=EOF);
       else break;
       if(fscanf(fp,"%d",&rec->timesPlayed)!=EOF);
       else break;
       if(fscanf(fp,"%d",&rec->rating)!=EOF);
       else break;
       DLnode* temp=createNode(rec);
       if(head==NULL)
       {
           head=temp;
           prev=head;
       }
       prev->next=temp;
       temp->prev=prev;
       prev=temp;
       Record* rec=(Record*)malloc(sizeof(Record));  

   }
   fclose(fp);
   return head;      
}

// function which stores records from doubly linked list
void store(DLnode* head,char* fname)
{
   FILE* fp=fopen(fname,"a"); // open file in append mode to write in the file
   if(fp==NULL)return;  
   DLnode* temp=head;
   while(temp)
   {
       fprintf(fp,"%s ",head->record->artist);
       fprintf(fp,"%s ",head->record->albumTitle);
       fprintf(fp,"%s ",head->record->songTitle);
       fprintf(fp,"%s ",head->record->genre);
       fprintf(fp,"%d ",head->record->songLength->seconds);
       fprintf(fp,"%d ",head->record->songLength->minutes);
       fprintf(fp,"%d ",head->record->timesPlayed);
       fprintf(fp,"%d ",head->record->rating);
       temp=temp->next;      
   }
   fclose(fp);
}

// function to print records in Doubly linked list
void display(DLnode* head)
{
   printf("enter the search field 1. artist, 2. album Title,3.song titles, 4.Gener, 5.Times Played, 6.Ratings");
   int searchField;
   scanf("%d",searchField);
   int value=0;
   char s[max];
   if(searchField==1||searchField==2||searchField==3||searchField==4)
   {
       scanf("%[^ ]s",s);
   }
   else
   {
       scanf("%d",&value);
   }
   switch(searchField)
       {
           case 1:
               while(head)
               {
                   if(strcmp(head->record->artist,s)==0)
                   {
                       printf("%s ",head->record->artist);
                       printf("%s ",head->record->albumTitle);
                       printf("%s ",head->record->songTitle);
                       printf("%s ",head->record->genre);
                       printf("%d ",head->record->songLength->seconds);
                       printf("%d ",head->record->songLength->minutes);
                       printf("%d ",head->record->timesPlayed);
                       printf("%d ",head->record->rating);
                       //head=head->next;
                       printf(" ");
                       break;
                   }
                   head=head->next;                  
               }
               break;
           case 2:
                   while(head)
               {
                   if(strcmp(head->record->albumTitle,s)==0)
                   {
                       printf("%s ",head->record->artist);
                       printf("%s ",head->record->albumTitle);
                       printf("%s ",head->record->songTitle);
                       printf("%s ",head->record->genre);
                       printf("%d ",head->record->songLength->seconds);
                       printf("%d ",head->record->songLength->minutes);
                       printf("%d ",head->record->timesPlayed);
                       printf("%d ",head->record->rating);
                       //head=head->next;
                       printf(" ");
                       break;
                   }
                   head=head->next;
               }
               break;
           case 3:
               while(head)
               {
                   if(strcmp(head->record->songTitle,s)==0)
                   {
                       printf("%s ",head->record->artist);
                       printf("%s ",head->record->albumTitle);
                       printf("%s ",head->record->songTitle);
                       printf("%s ",head->record->genre);
                       printf("%d ",head->record->songLength->seconds);
                       printf("%d ",head->record->songLength->minutes);
                       printf("%d ",head->record->timesPlayed);
                       printf("%d ",head->record->rating);
                       //head=head->next;
                       printf(" ");
                       break;
                   }
                   head=head->next;
               }
               break;
           case 4:
               while(head)
               {
                   if(strcmp(head->record->genre,s)==0)
                   {
                       printf("%s ",head->record->artist);
                       printf("%s ",head->record->albumTitle);
                       printf("%s ",head->record->songTitle);
                       printf("%s ",head->record->genre);
                       printf("%d ",head->record->songLength->seconds);
                       printf("%d ",head->record->songLength->minutes);
                       printf("%d ",head->record->timesPlayed);
                       printf("%d ",head->record->rating);
                       //head=head->next;
                       printf(" ");
                       break;
                   }
                   head=head->next;
               }
               break;
           case 5:
               while(head)
               {
                   if(strcmp(head->record->timesPlayed,value)==0)
                   {
                       printf("%s ",head->record->artist);
                       printf("%s ",head->record->albumTitle);
                       printf("%s ",head->record->songTitle);
                       printf("%s ",head->record->genre);
                       printf("%d ",head->record->songLength->seconds);
                       printf("%d ",head->record->songLength->minutes);
                       printf("%d ",head->record->timesPlayed);
                       printf("%d ",head->record->rating);
                       //head=head->next;
                       printf(" ");
                       break;
                   }
                   head=head->next;
               }
               break;
           case 6:
               while(head)
               {
                   if(strcmp(head->record->rating,value)==0)
                   {
                       printf("%s ",head->record->artist);
                       printf("%s ",head->record->albumTitle);
                       printf("%s ",head->record->songTitle);
                       printf("%s ",head->record->genre);
                       printf("%d ",head->record->songLength->seconds);
                       printf("%d ",head->record->songLength->minutes);
                       printf("%d ",head->record->timesPlayed);
                       printf("%d ",head->record->rating);
                       //head=head->next;
                       printf(" ");
                       break;
                   }
                   head=head->next;
               }
               break;
           default:
               while(head)
               {
               printf("%s ",head->record->artist);
               printf("%s ",head->record->albumTitle);
               printf("%s ",head->record->songTitle);
               printf("%s ",head->record->genre);
               printf("%d ",head->record->songLength->seconds);
               printf("%d ",head->record->songLength->minutes);
               printf("%d ",head->record->timesPlayed);
               printf("%d ",head->record->rating);
               head=head->next;
               printf(" ");
               }
       }      
}

// function to collect information from user
Record* insert()
{
   Record* rec=(Record*)malloc(sizeof(Record)); //memory allocation
   printf("Enter the Artist : ");
   scanf("%[^ ]s",rec->artist);
   printf("Enter the Album Title : ");
   scanf("%[^ ]s",rec->albumTitle);
   printf("Enter the Song Title : ");
   scanf("%[^ ]s",rec->songTitle);
   printf("Enter the Genre : ");
   scanf("%[^ ]s",rec->genre);
   printf("Enter the Song Length : ");
   printf("Enter the seconds : ");
   scanf("%d",rec->songLength->seconds);
   printf("Enter minutes : ");
   scanf("%d",rec->songLength->minutes);
   printf("Enter the Times Played : ");
   scanf("%d",rec->timesPlayed);
   printf("Enter the Rating : ");
   scanf("%d",rec->rating);
   return rec;  
}

// fuction for deletion
DLnode* _delete(DLnode* head,char* song_title)
{
   DLnode* temp=head, *found;
   while(temp)
   {
       if(strcmp(temp->record->songTitle,song_title)==0)
       {
           if(temp->prev)
           {
               if(temp->next)
               {
                   temp->prev->next=temp->next;
               }
               else
               {
                   temp->prev->next=NULL;
               }
           }
           else
           {
               if(temp->next)
               {
                   temp->next->prev=NULL;
                   head=temp->next;
               }
               else
               {
                   head=NULL;
               }
           }
           free(temp);
           break;
       }
   }
   return head;
}

void edit(DLnode* head)
{
   printf("Enter the field based on which you want to find the record ");
   printf("1. artist, 2. album Title,3.song titles, 4.Gener, 5.Ratings");
   int searchField;
   scanf("%d",searchField);
   int value;
   char s[max];
   if(searchField==1||searchField==2||searchField==3||searchField==4)
   {
       scanf("%[^ ]s",s);
   }
   else {
       scanf("%d",&value);
   }
   switch(searchField)
   {
       case 1:
           while(head)
           {
               if(strcmp(head->record->artist,s)==0)
               {
                   printf("Enter new artist ");
                   char artist[max];
                   scanf("%[^ ]s",artist);
                   int i=0;
                   for(i=0;i<strlen(artist);i++)
                   {
                           head->record->artist[i]=artist[i];
                   }
                   head->record->artist[i]='';
                   break;
               }
               head=head->next;
           }
           case 2:
           while(head)
           {
               if(strcmp(head->record->albumTitle,s)==0)
               {
                   printf("Enter new album title ");
                   char title[max];
                   int i=0;
                   scanf("%[^ ]s",title);
                   for(i=0;i<strlen(title);i++)
                   {
                           head->record->albumTitle[i]=title[i];
                   }
                   head->record->albumTitle[i]='';
                   break;
               }
               head=head->next;
           }
           case 3:
           while(head)
           {
               if(strcmp(head->record->songTitle,s)==0)
               {
                   printf("Enter new song title ");
                   char title[max];
                   scanf("%[^ ]s",title);
                   int i=0;
                   for(i=0;i<strlen(title);i++)
                   {
                           head->record->songTitle[i]=title[i];
                   }
                   head->record->songTitle[i]='';
                   break;
               }
               head=head->next;
           }
           case 4:
           while(head)
           {
               if(strcmp(head->record->genre,s)==0)
               {
                   printf("Enter new genre ");
                   char title[max];
                   scanf("%[^ ]s",title);
                   int i=0;
                   for(i=0;i<strlen(title);i++)
                   {
                           head->record->genre[i]=title[i];
                   }
                   head->record->genre[i]='';
                   break;
               }
               head=head->next;
           }
           case 5:
           while(head)
           {
               if(strcmp(head->record->rating,value)==0)
               {
                   printf("Enter new rating ");
                   int rating;
                   scanf("%d",&rating);
                   if(rating>=1&&rating<=5)
                   head->record->rating=rating;
                   else
                   {
                       continue;
                   }
                   break;
               }
               head=head->next;
           }
           default: break;
   }
}
int main()
{
   DLnode* head=NULL;
   printf("Please enter your choice ");
   printf("1. load 2.Insert 3. Edit, 4. Delete 5.Display, 6.Store ");
   int choice;
   scanf("%d",&choice);
  
   switch(choice)
   {
       case 1:
           {
               printf("Enter the File name you want to load : ");
               char filename[max];
               scanf("%s",filename);
               head=load(filename);
               break;
           }
       case 2:
           {
               insert();
               break;
           }
       case 3:
           {
               if(head==NULL)
               {
                   printf("Please load the file you want ");
                   break;                  
               }
               else
               {
                   edit(head);
                   break;
               }              
           }
       case 4:
           {
               if(head==NULL)
               {
                   printf("Please, first load the file you want ");
                   break;                  
               }
               else{
                   printf("please enter the song you want to delete ");
                   char song[max];
                   _delete(head,song);
                   break;
               }              
           }
       case 5:
           {
               if(head==NULL)
               {
                   printf("Please, first load the file you want ");
                   break;                  
               }
               else
               {
                   display(head);
               }
           }
       default:
           break;
          
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote