Question
C++ Question I have to design a program and have chosen personal media library containing the following fields that will need to be filled in
C++ Question I have to design a program and have chosen personal media library containing the following fields that will need to be filled in by the user. Title, Starring, Format, Genre, Year Produced.
My menu display should have
1. Enter New Media Item
2. Display all Media Items
3. Sort all Media Items // This should be done by format and then title.
4. Display a particular Media Item.
5. Exit the program.
The program must meet the following criteria.
Include at least 3 functions, Use two-dimensional arrays, Use at least 2 member functions from the string library, provide a menu option for sorting and searching the two dimensional arrays.
This is the code i've come up with so far.
#include
#include
#include
using namespace std;
int index = 0; //Variable to how how many Media Items are entered.
struct Media { // Media
string title;
string starring;
string format;
string genre;
string yearProduced;
};
int displayMenu();
Media getMedia();
void showMedia(Media);
void allMedia(Media[]);
void sortMedia(Media[]);
void findMedia(Media[], int);
int main()
{
Media med[1000]; // Declare array of Media struct
while (true)
{
int choice = displayMenu();
switch (choice)
case 1:
med[index] = getMedia();
index++;
break;
case 2:
allMedia(med);
break;
case 3:
sortMedia(med);
break;
case 4:
findMedia(med, index);
break;
case 5:
cout << "You have selected to exit the program. Thanks you." << endl;
return 0;
break;
default:
cout << "That is not a valid choice. Please try again." << endl;
}
cout << endl;
}
return 0;
}
int displayMenu() //Display menu to user
{
cout << "Personal Media Library" << endl;
cout << endl;
cout << "Please select from the below menu." << endl;
cout << endl;
cout << "1. Enter New Media Item." << endl;
cout << "2. Display all Media Items." << endl;
cout << "3. Sort all Media Items." << endl;
cout << "4. Display a particular Media Item." << endl;
cout << "5. Exit the program." << endl;
int choice; //User selects what they want to do.
cout << "Enter choice:";
cin >> choice;
cin.ignore();
cout << endl;
return choice;
}
Media getMedia(); {
Media a;
cout << "Enter Title:";
getline(cin, a.title);
cout << "Enter Starring:";
getline <<(cin, a.starring);
cout << "Enter format: (DVD, VHS, CD)";
getline << (cin, a.format);
cout << "Enter genre: (Main theme followed by TV Show, Movie or Music)";
getline << (cin, a.genre);
cout << "Enter Year Produced:";
getline << (cin, a.yearProduced);
return a;
}
void showMedia(); { //Display Media Item Details
cout << "Title: " << c.title << endl;
cout << "Starring: " << c.starring << endl;
cout << "Format: " << c.format << endl;
cout << "Genre: " << c.genre << endl;
cout << "Year Produced: " << c.yearProduced << endl;
}
void allMedia(Media med[]) {
for (int i = 0; i < index; i++) {
showMedia(med[i]);
cout << endl;
}
}
void sortMedia //Need this to sort by format and then title
{
}
void findMedia(Media med[], int size) //Ask user to enter title
{
string title;
cout << "Enter Title: ";
getline(cin, title);
for (int i = 0; i < size; i++) {
if (med[i].title) {
showMedia(med[i]);
return;
}
}
cout << "This title cannot be found. It appears that you do not have this in your selection." << endl;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started