Question
C++: Display sorted favorite movies. Use a linked list to store your favorite movies. Store the movie objects into a linked list, display the movie
C++:
Display sorted favorite movies.
Use a linked list to store your favorite movies.
Store the movie objects into a linked list, display the movie information by sorting with the title, viewed year, and rating.
You may need three more functions to display the sorted movie information by passing the pointer of the first movie object in the linked list:
So far, I have gotten this far in my code:
-----------------------------------------------
#include
#include
#include
using namespace std;
struct movie
{
string title;
int viewed_year;
int rating;
movie* next;
};
void list_movie(const movie* head)
{
cout
cout
int i = 1;
for (const movie* p = head; p; p = p->next)
{
cout
cout title;
cout viewed_year;
cout rating
}
}
int main()
{
movie* firstmovie = 0;
string title1, title2, title3;//3 Strings to store names of the movies
int viewed_year1, viewed_year2, viewed_year3; //3 ints's to store viewed year of the movies
int rating1, rating2, rating3; //3 ints's to store rating of the movies
cout
getline(std::cin, title1);
cout
cin >> viewed_year1;
cout
cin >> rating1;
cin.get();
cout
getline(std::cin, title2);
cout
cin >> viewed_year2;
cout
cin >> rating2;
cin.get();
cout
getline(std::cin, title3);
cout
cin >> viewed_year3;
cout
cin >> rating3;
//3 movie objects to store the movies
movie a = { title1, viewed_year1, rating1 };
movie b = { title2, viewed_year2, rating2 };
movie c = { title3, viewed_year3, rating3 };
a.next = firstmovie;
firstmovie = &a;
b.next = firstmovie;
firstmovie = &b;
c.next = firstmovie;
firstmovie = &c;
//Function call to print the movies
list_movie(firstmovie);
}
-----------------------------------------------
Any help is greatly appreciated, thank you.
void arrange_ by title(Movie) void arrange_by rating(Movie* void arrange_by viewed(Movie* - Sample output, Please enter the title of the movie1(within 30-character):Now You See Me Please enter the year you viewed Now You See Me [like 2017]:2014 Please your rating for Now You See Me [1, 2, 3, 4, 5]:4 Please enter the title of the movie2 (within 30-character):X-Men: First Class Please enter the year you viewed X-Men: First Class [like 20171:2011 Please your rating for X-Men: First Class [1, 2, 3, 4, 5]:3 Please enter the title of the movie3(within 30-character):Hidden Figures Please enter the year you viewed Hidden Figures [like 2017]:2016 Please your rating for Hidden Figures [1, 2, 3, 4, 5]:5 *Display Movies info sorted by titles** Movie Title Viewed Rating 5 3 Viewed Rating 3 5 Viewed Rating 1 Hidden Figures 2 Now You See Me 2016 2014 2011 Display Movies info sorted by rating* X-Men: First Class Movie Title 1 X-Men: First Class 2 Now You See Me 3 Hidden Figures 2011 2014 2016 *Display Movies info sorted by viewed years** Movie Title 1 X-Men: First Class 2 Now You See Me 3 Hidden Figures 2011 2014 2016 5 Program ended with exit code:eStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored 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