120k views
2 votes
Write a menu-driven program for a user to store information about the media collection they own. This requires using an array of struct type called Media. Every element in the array represents one media item in a person's collection. Represent the information as an array of structs that needs to able to hold up to 100 media entries. However, the actual number of entries is probably much smaller so the program needs to keep track of how many actual entries are in the collection.

1 Answer

3 votes

Answer:

Check Explanation and attachment.

Step-by-step explanation:

Since the site does not allow me to submit my work(for you to easily copy and paste it), I will post some additional attachments.

Please, note that there is category, unique ID, description for each media item.

#include <stdio.h>

#include <string.h>

struct Media {

int id;

int year;

char title[250];

char description[250];

char category[50];

};

void show_menu();

void add_item(struct Media arr[], int *c);

void print_all(struct Media arr[], int c);

void print_category(struct Media arr[], int c);

void delete_entry(struct Media arr[], int *c);

int main() {

struct Media collection[100];

int ch, count = 0;

// loop until user wants to quit

while (1) {

show_menu(); // display the menu

printf("Enter your choice: ");

scanf("%d", &ch);

if (ch == 1)

add_item(collection, &count);

else if (ch == 2)

print_all(collection, count);

else if (ch == 3)

print_category(collection, count);

else if (ch == 4)

delete_entry(collection, &count);

else if (ch == 0)

break;

else

printf("Invalid choice. Try again!\\");

}

return 0;

}

void show_menu() {

printf("1. Add a media item to the collection\\");

printf("2. Print all media in the collection\\");

printf("3. Print all media in a given category\\");

printf("4. Delete an entry\\");

printf("0. Quit\\");

}

void add_item(struct Media arr[], int *cnt) {

Write a menu-driven program for a user to store information about the media collection-example-1
Write a menu-driven program for a user to store information about the media collection-example-2
Write a menu-driven program for a user to store information about the media collection-example-3
Write a menu-driven program for a user to store information about the media collection-example-4
Write a menu-driven program for a user to store information about the media collection-example-5
User Dols
by
4.6k points