In: Computer Science
Using C++
Many software applications use comma-separated values to store and transfer data.
In this program, you are asked to implement the movie_call function that will parse a string of the above structure into the corresponding movie name, rating, and movie length.
ex: In "movie name, rating, length", the movie name is "movie name", the rating is "rating", and the length of the movie is "lenght".
This is the code:
#include <iostream>
#include <string>
using namespace std;
/*
Replace the function body with appropriate statements to movie_call
a string of movie details into its corresponding movie name, rating,
and length.
*/
void movie_call (string movie, string& name, string& rating, string& length) {
int comma, comma1;
comma = movie.find(",");
name = movie.substr(0, comma);
movie = movie.substr(comma + 1);
comma1 = movie.find(",");
rating = movie.substr(0, comma1);
length = movie.substr(comma1 + 1);
}
int main() {
string movie_details;
cout << "Please enter information for one movie of your choice: ";
getline(cin, movie_details);
//Add appropriate statement(s) to call the movie_call function
//and display the name, rating, and length
return 0;
}
#include<iostream.h>
#include<string.h>
void movie_call (string movie, string& name, string& rating, string& length) {
int comma, comma1;
comma = movie.find(",");
string name = movie.substr(0, comma);
string movie = movie.substr(comma + 1);
comma1 = movie.find(",");
int rating = movie.substr(0, comma1);
int length = movie.substr(comma1 + 1);
}
int main() {
string movie_details;
cout << "Please enter information for one movie of your choice: ";
getline(cin, movie_details);
movie_call (string movie, string& name, string& rating, string& length);
cout<<name<<endl;
cout<<rating<<endl;
cout<<length<<endl;
return 0;
}
Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions. Thank You! ===========================================================================