Question: In this assignment you will complete the Video Playlist Manager that you started in PA 2. You must implement the following features: (4) insert (5)

In this assignment you will complete the Video Playlist Manager that you started in PA 2. You must implement the following features:

(4) insert (5) delete (7) sort (extra credit)

(10) shuffle

You will also be required to write 3 test functions.

a. Whatmustinsertdo?

The insert command must prompt the user for the details of a new movie record. The prompt must request the movie title, director, description, genre, running time, year, number of times played, and rating. The new record must be inserted at the front of the list.

b. Whatmustdeletedo?

The delete command must prompt the user for a movie title and remove the matching record from the list. If the movie title does not exist, then the list remains unchanged.

c. What must shuffle do?

The shuffle command must provide a random order in which the movies are played. This command must not modify the links in the list. It must just specify the order in which movies are played, based on the position of the movie in the list. For example, lets say we have a list with 5 movies at positions 1 5 in the list, shuffle must generate an order 1 5 in which the movies are played. An order 2, 5, 3, 1, 4 would require that the second movie in the list is played first, the fifth movie in the list is played second, the third movie in the list is played third, the first movie in the list is played fourth, and the fourth movie in the list is played fifth. The movies are accessed by traversing the list both forwards and backwards to satisfy the order. Hence, the need for a doubly linked list!

d. What must sort do? (EXTRA CREDIT)

The sort command must prompt the user for 4 different methods to sort the records in the list. These include:

1. Sortbasedondirector(A-Z) 2. Sortbasedonfilename(A-Z) 3. Sortbasedonrating(1-5) 4. Sortbasedontimesplayed(largest-smallest)

Once a sort method is selected by the user, the sort must be performed on the records in the list. Consider using bubble sort, insertion sort, or selection sort.

What test functions are required?

You must design and implement 3 test functions. These test functions must not accept any arguments or return any values. They should be self-sufficient. You should provide function declarations for them that are in a separate header file than your utility/application function declarations. You must implement one test function for insert, delete, and shuffle features for a total of 3 functions.

o For the insert test function you must provide a test case with the following test point: movie title = Bohemian Rhapsody, director = Bryan Singer, description= Freddie Mercury the lead singer of Queen defies stereotypes and convention to become one of history's most beloved entertainers., genre = Drama, running time = 2:13, year = 2018, times played = -1, rating = 6. You must think about what is your expected result? Should you able to insert a movie with -1 times played? Should you able to add a movie with rating 6? Is the head pointer of the list updated?

o For the delete test function you must provide a test case with the following test point: movie title = Bohemian Rhapsody, director = Bryan Singer, description= Freddie Mercury the lead singer of Queen defies stereotypes and convention to become one of history's most beloved entertainers., genre = Drama, running time = 2:13, year = 2018, times played = -1, rating = 6. You must think about what is your expected result? Has the head pointer been updated? Is it NULL? Did the memory get released?

o For the shuffle test function you must provide a test case with the following test point: list the play order that was randomly generated and list the movies. Example: play order = 3, 1, 2. List state = you provide 3 movies. Does the shuffle play in the correct order?

This assignment is worth 70 points. Your assignment will be evaluated based on a successful compilation and adherence to the program requirements. We will grade according to the following criteria:

5 pts Appropriate top-down design, style, and commenting according to class standards

  • 17 pts Correct insert command implementation (7 pts - 1pt/attribute) For prompting and getting the details of a new record from the user (10 pts) For correctly inserting the record at the front of the list

  • 23 pts For correct delete command implementation (3 pts) For prompting and getting the movie title from the user (5 pts) For searching for specific record matching the movie title (15 pts) For removing the matching record from the list, and reconnecting the list correctly

  • 15 pts Correct shuffle command implementation

    (5 pts) For generating the random order based on the number of movies in the list (10 pts) For moving through the list (forwards and backwards) and playing the movies in the order generated

  • 10 pts Robust test functions 3 required (4 pts) For a test function that challenges the bounds of r insert feature. (3 pts) For a test function that challenges the bounds of r delete feature. (3 pts) For a test function that challenges the bounds of your shuffle feature.

Extra Credit: 30 pts Correct sort command implementation o (3 pts) For prompting and getting the sort method from the user

o (7 pts) For sorting based on movie title (A-Z) o (7 pts) For sorting based on director (A-Z) o (6 pts) For sorting based on rating (1-5) o (6 pts) For sorting based on times played (largest-smallest)

implementation.c

#include "Header.h"

/* Function add new element to the front of the DLL */ void insertFront(struct Node** head, struct Record new_data) { //allocate memory struct Node* new_node = (struct Node*)malloc(sizeof(struct Node)); // add record new_node->data = new_data; //set next pointer new_node->next = (*head); new_node->prev = NULL; //set prev pointer of new record if ((*head) != NULL) // if head is not null (*head)->prev = new_node; //set prev of head to new node (*head) = new_node; // set head to new node } // function to print enitre doubly linked list void printList(struct Node* node) { struct Node* trav; int cnt=0; while (node != NULL) { printf(" ***** MOVIE %d ******** ",++cnt); printRecord(node->data); // print the single movie record trav = node; node = node->next; } }

void printListByDirector(struct Node* node,char dir[]) { struct Node* trav;

while (node != NULL) {

struct Record record=node->data; if(strcmp(record.director,dir) ==0 ) printRecord(node->data); trav = node; node = node->next; } } void printListByYear(struct Node* node,int year) { struct Node* trav;

while (node != NULL) {

struct Record record=node->data; if(record.year == year ) printRecord(node->data); trav = node; node = node->next; } }

void displayMenu() { printf(" (1) load (2) store (3) display (4) insert (5) delete (6) edit (7) sort (8) rate (9) play (10) shuffle (11) exit : "); }

//function to get num'th field from the line char* getField(char* line, int num) { char* token; //set token //find next field separated by comma for (token = strtok(line, ",");token && *token;token = strtok(NULL, ", ")) { if (!--num) // if nth field then return that token return token; } return NULL; // returns NULL if num of field not exist } // print the single movie record void printRecord(struct Record record) { printf(" Title :%s",record.title); printf(" Director :%s",record.director); printf(" Description :%s",record.desc); printf(" Genre :%s",record.genre); printf(" Hours :%d",record.runtime.hours); printf(" Minutes :%d",record.runtime.minutes); printf(" Release Year :%d",record.year); printf(" No of times played :%d",record.no_times_played); printf(" Rating :%d ",record.rating); }

void loadFile(struct Node** head) { FILE* fobj = fopen("moviePlayList.csv", "r"); // open file char line[1024]; char tempLine[1024]; while (fgets(line, 1024, fobj)) //read a line { strcpy(tempLine,line); // store temp copy of the line struct Record record; struct Duration dur; strcpy(record.title,getField(line,1)); //set title strcpy(line,tempLine); strcpy(record.director,getField(line,2)); //set director strcpy(line,tempLine); strcpy(record.desc,getField(line,3)); // set desc strcpy(line,tempLine); strcpy(record.genre,getField(line,4)); // set genre strcpy(line,tempLine); dur.hours=atoi(getField(line,5)); // set hours strcpy(line,tempLine); dur.minutes=atoi(getField(line,6)); //set min strcpy(line,tempLine); record.runtime=dur; record.year=atoi(getField(line,7)); // set year strcpy(line,tempLine); record.no_times_played=atoi(getField(line,8)); // no of times strcpy(line,tempLine); record.rating=atoi(getField(line,9)); // rating strcpy(line,tempLine);

insertFront(head,record); } fclose(fobj); }

//function to store DLL into the file void storeFile(struct Node* node) { FILE* fobj = fopen("moviePlayList.csv", "w"); struct Node* trav; char comma[]=","; char newline[]=" "; while (node != NULL) {

struct Record record; record=node->data; //printf(" Title : %s",record.title); fprintf(fobj,"%s",record.title); fprintf(fobj,"%s",comma); fprintf(fobj,"%s",record.director); fprintf(fobj,"%s",comma); fprintf(fobj,"%s",record.desc); fprintf(fobj,"%s",comma); fprintf(fobj,"%s",record.genre); fprintf(fobj,"%s",comma); fprintf(fobj,"%d",record.runtime.hours); fprintf(fobj,"%s",comma); fprintf(fobj,"%d",record.runtime.minutes); fprintf(fobj,"%s",comma); fprintf(fobj,"%d",record.year); fprintf(fobj,"%s",comma); fprintf(fobj,"%d",record.no_times_played); fprintf(fobj,"%s",comma); fprintf(fobj,"%d",record.year); fprintf(fobj,"%s",comma); fprintf(fobj,"%d",record.rating);

fprintf(fobj,"%s",newline); trav = node; node = node->next; } fclose(fobj); }

void display(struct Node* node) { printf(" 1.Display All movies : "); printf(" 2.Display movies of director : "); printf(" 3.Display movies of year : "); printf(" Enter your choice :");

int choice; scanf("%d",&choice);

switch(choice) { case 1: { printList(node); /// print all mpvies break; }

case 2: { // by director char dir[100]; printf(" Enter director Name : "); while ((getchar()) != ' '); scanf("%[^ ]%*c", dir); //get director name printf(" Enter year : %s",dir); printListByDirector(node,dir); break; } case 3: { //by year int year; printf(" Enter year : "); scanf("%d",&year); //get year printListByYear(node,year); break; } }

}

///fucnton to get rating to movie

void rateMovie(struct Node** node) {

struct Node* temp=*node; // to store head (start) pointer of DLL struct Node* trav; int cnt=0; while (*node != NULL) { //while all movies not visited

struct Record record=(*node)->data; printRecord(record); while ((getchar()) != ' '); printf(" Do you want to rate this movie ? (y/n) :"); char ch;

scanf("%c",&ch); if(ch=='y' || ch=='Y') { printf(" Please Enter rating between (0 to 5) : "); int rate; //while ((getchar()) != ' '); scanf("%d",&rate);

if(rate < 0 || rate > 5) { printf(" Invalid Rating"); return; } ///noe change thhe rating of record record.rating=rate; (*node)->data=record; printRecord(record); }

trav = *node; *node = (*node)->next; }

*node=temp; // to store head (start) pointer of DLL }

void playMovie(struct Node* node) { struct Node* trav; int cnt=0; while (node != NULL) {

system("cls"); // WINDOWS clears screen //system("clear"); // LINUX printf(" Playing Movies "); printf(" Movie Number : %d",++cnt); printRecord(node->data); getchar(); // when user enters enter new movie will start to play

trav = node; node = node->next; }

printf(" All movies played"); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!