Define a class named Movie. Include private fields for the title,year, and name
ID: 3609741 • Letter: D
Question
Define a class named Movie. Include private fields for the title,year, and name of the director. Include three public functions withprototypes void Movie::setTitle(cstring); , voidMovie::setYear(int); , void Movie::setDirector(string);. Includeanother function that displays all the information about a Movie.Write a main() function that declares a movie object namedmyFavoriteMovie. Set and display the object's fields.This is what I have but know its wrong since it will notcompile:
#include<iostream>
#include<conio.h>
using namespace std;
//class declaration
class Movie
{
private:
string movieTitle ;
string movieYear;
string directorName;
public:
void setTitle(string title);
void setYear(string year);
void setDirector(string director);
void displayInfo();
};
//class Implementation
void Movie::setTitle(string title)
{
movieTitle = title;
cout<<"What is the title of themovie? "<<endl;
}
void Movie::setYear(string year)
{
movieYear = year;
cout<<"What year did the movie comeout? "<<endl;
}
void Movie::setDirector(string director)
{
directorName = director;
cout<<"Who directed themovie?"<<endl;
}
void Movie::displayInfo()
{
cout<<"Movie Title :"<<movieTitle<<endl;
cout<<"Year : "<<movieYear<<endl;
cout<<"Director :"<<directorName<<endl;
}
//main function
int main ()
{
Movie myFavoriteMovie;
string temp; //temporary stringvariable
cout<<"Enter movie title"<<endl;
cin>>temp;
myFavoriteMovie.setTitle(temp);
cout<<"Enter movie Year"<<endl;
cin>>temp;
myFavoriteMovie.setYear(temp);
cout<<"Enter director'sname"<<endl;
cin>>temp;
myFavoriteMovie.setDirector(temp);
//display all the data
myFavoriteMovie.displayInfo();
system("PAUSE");
return 0;
this code is not entirely mine someone on cramster edited my firstcode but then I try manipulating the new code and I still get acompile error message :
documentsisual studio 2008projectsmoviemoviemovie.cpp(46) :error C2679: binary '<<' : no operator found which takes aright-hand operand of type 'std::string' (or there is no acceptableconversion)
c:program files (x86)microsoft visual studio9.0cincludeostream(653): could be'std::basic_ostream<_Elem,_Traits> &std::operator<<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits>&,const char *)
what is wrong with this code? answer and ill give lifesaverpoints.
Explanation / Answer
please rate - thanks It was missing a } at the end of the program. works fine withmy Dev C++ In addition I made some other corrections. before title and director could be 1 word only, now they can bemany words sample run Enter movie title: Mary Poppins Enter movie Year: 1970 Enter director's name: who knows Movie Title :Mary Poppins Year :1970 Director :who knows Press any key to continue . . . #include using namespace std; //class declaration class Movie { private: string movieTitle ; string movieYear; string directorName; public: void setTitle(string title); void setYear(string year); void setDirector(string director); void displayInfo(); }; //class Implementation void Movie::setTitle(string title) { movieTitle = title; } void Movie::setYear(string year) { movieYear = year; } void Movie::setDirector(string director) { directorName = director; } void Movie::displayInfo() { coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.