C++: -------------------------------------------- #include <iostream> #include <
ID: 3591225 • Letter: C
Question
C++:
--------------------------------------------
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct movie
{
string title;
int viewed_year;
int rating;
movie* next;
};
void print_linked_list_arrow(const movie* head)
{
cout << "#" << setw(15) << "Movie Title" << setw(8) << "Viewed" << setw(8) << "Rating" << endl;
cout << "==========================================" << endl;
for (const movie* p = head; p; p = p->next)
{
cout << setw(15) << p->title;
cout << setw(6) << p->viewed_year;
cout << setw(6) << p->rating << endl;
}
}
int main()
{
movie* firstmovie = 0;
movie a = { "Movie1", 2000, 5 };
movie b = { "Movie2", 2015, 4 };
movie c = { "Movie3", 2017, 3 };
a.next = firstmovie;
firstmovie = &a;
b.next = firstmovie;
firstmovie = &b;
c.next = firstmovie;
firstmovie = &c;
print_linked_list_arrow(firstmovie);
}
--------------------------------------------
Not sure how to do the rest of the code, any help is appreciated, thank you
linked list to store your favorit Create a movie struct including the title, the year you viewed, and the rating you gave Prompt to the user to enter information of three movies, create a movie object for each of them, and store them into a se a vie linked list. Write a function to display the movie information by passing the pointer of the first movie object in the linked list: void list_movie(const Movie*); . Sample of Movie struct struct Movie string title; int viewed year; int rating; Movie* nexti Sample output: Please enter the title of the movie1(within 30-character) :Dangal Please enter the year you viewed Dangal [like 2017]:2016 Please your rating for Dangal [1, 2, 3, 4, 5]:5 Please enter the title of the movie2 (within 30-character):Now You See ME Please enter the year you viewed Now You See ME [like 2017]:2013 Please your rating for Now You See ME [1, 2, 3, 4, 5]:4 Please enter the title of the movie3(within 30-character):Inception Please enter the year you viewed Inception [like 2017]:2012 Please your rating for Inception [1, 2, 3, 4, 5]:4 Movie Title Viewed Rating 1 Inception 2 Now You See ME 3 Dangal 2012 2013 2016 5 Program ended with exit code:Explanation / Answer
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct movie
{
string title;
int viewed_year;
int rating;
movie* next;
};
void print_linked_list_arrow(const movie* head)
{
cout << "#" << setw(15) << "Movie Title" << setw(8) << "Viewed" << setw(8) << "Rating" << endl;
cout << "==========================================" << endl;
int i=1;
for (const movie* p = head; p; p = p->next)
{
cout << i++;
cout << setw(15) << p->title;
cout << setw(6) << p->viewed_year;
cout << setw(6) << p->rating << endl;
}
}
int main()
{
movie* firstmovie = 0;
/*3 Strings to store names of the movies*/
std::string title1,title2,title3;
/*3 intss to store viewed year of the movies*/
int viewed_year1,viewed_year2,viewed_year3;
/*3 intss to store rating of the movies*/
int rating1,rating2,rating3;
std::cout << "Please enter the title of the movie1:(within 30-character):" << endl;
std::getline(std::cin,title1);
std::cout << "Please enter the year you viewed " << title1 << " [like 2017]:" << endl;
cin >> viewed_year1;
std::cout << "Please enter your rating for " << title1 << " [1,2,3,4,5]:" << endl;
cin >> rating1;
std::cin.get();
std::cout << "Please enter the title of the movie2:(within 30-character):" << endl;
std::getline(std::cin,title2);
std::cout << "Please enter the year you viewed " << title2 << " [like 2017]:" << endl;
cin >> viewed_year2;
std::cout << "Please enter your rating for " << title2 << " [1,2,3,4,5]:" << endl;
cin >> rating2;
std::cin.get();
std::cout << "Please enter the title of the movie3:(within 30-character):" << endl;
std::getline(std::cin,title3);
std::cout << "Please enter the year you viewed " << title3 << " [like 2017]:" << endl;
cin >> viewed_year3;
std::cout << "Please enter your rating for " << title3 << " [1,2,3,4,5]:" << endl;
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*/
print_linked_list_arrow(firstmovie);
}
***********************************************************************************
END OF PROGRAM
***********************************************************************************
Sample input:
Dangal
2016
5
Now You See ME
2013
4
Inception
2012
4
Sample output:
Please enter the title of the movie1:(within 30-character):
Please enter the year you viewed Dangal [like 2017]:
Please enter your rating for Dangal [1,2,3,4,5]:
Please enter the title of the movie2:(within 30-character):
Please enter the year you viewed Now You See ME [like 2017]:
Please enter your rating for Now You See ME [1,2,3,4,5]:
Please enter the title of the movie3:(within 30-character):
Please enter the year you viewed Inception [like 2017]:
Please enter your rating for Inception [1,2,3,4,5]:
# Movie Title Viewed Rating
==========================================
1 Inception 2012 4
2 Now You See ME 2013 4
3 Dangal 2016 5
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.