Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

In this assignment you will complete the Video Playlist Manager that you started in PA 2. You must implement the following features: o (4) insert o (5) delete o (7) sort (extra credit) o (10) shuffle You will also be required to write 3 test functions. a. What must insert do? 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. What must delete do? 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. Sort based on director (A-Z) 2. Sort based on file name(A-Z) 3. Sort based on rating (1-5) 4. Sort based on times played (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?

From PA2

Header.h

#ifndef HEADER_H #define HEADER_H #include #include #include #include "Header.h"

//to store time struct Duration{ int hours; int minutes; }; //to store movie record struct Record{ char title[100]; char director[100]; char desc[200]; char genre[20]; struct Duration runtime; int year; int no_times_played; int rating; }; // to store single node in DLL struct Node{ struct Record data; struct Node* prev; struct Node* next; }; //related to Double linked list void insertFront(struct Node** head_ref, struct Record new_data); //insert node to first of list void printList(struct Node* node); // print list // related to your Movie player char* getField(char*,int); // extract numth field from line void displayMenu(); // void loadFile(struct Node** head); // load contents from file void storeFile(struct Node* head); // store contents into file void printRecord(struct Record record); // print a songle movie record void display(struct Node* node); // void printListByYear(struct Node* node,int year); void printListByDirector(struct Node* node,char dir[]); void rateMovie(struct Node** head); // to rate movie void playMovie(struct Node* head); //play movie in order //void storeFile(); #endif

----------------------------------------

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"); }

--------------------------------

main.c

#include #include #include "Header.h"

int main() {

struct Node* head = NULL; // loadFile(&head);

int choice=0; while(choice != 11) { displayMenu(); scanf("%d",&choice);

switch(choice) { case 1: //load

loadFile(&head); break;

case 2: //store storeFile(head); break;

case 3: //display display(head); break;

case 4: //insert

break;

case 5: //delete break;

case 6: //edit break;

case 7://sort break;

case 8://rate rateMovie(&head); break;

case 9: playMovie(head); break;

case 10: break;

case 11: //exit storeFile(head); break; } }

return 0; }

-------------------------------

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

AWS Certified Database Study Guide Specialty DBS-C01 Exam

Authors: Matheus Arrais, Rene Martinez Bravet, Leonardo Ciccone, Angie Nobre Cocharero, Erika Kurauchi, Hugo Rozestraten

1st Edition

1119778956, 978-1119778950

More Books

Students also viewed these Databases questions

Question

choriw

Answered: 1 week ago

Question

1. Understand how verbal and nonverbal communication differ.

Answered: 1 week ago