Just returned from spring break and I am still a little out of it.I was attempti
ID: 3609738 • Letter: J
Question
Just returned from spring break and I am still a little out of it.I was attempting to do an assignment that deals with classes.However I did horribly on the review questions and I am having areal difficult time in coding with classes. Could someone pleasehelp me with the follow 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 Movie
{
private:
string movieTitle;
int movieYear;
string directorName;
public:
void setTitle(string);
void setYear(int);
void setDirector(string);
void displayInfo(string,int);
};
void Movie::setTitle(string)
{
movieTitle = setTitle
cout<<"What is the title of themovie?"<<setTitle<<endl;
}
void Movie::setYear(int)
{
cout<<"What year did the movie comeout?"<<movieYear<<endl;
}
void Movie::setDirector(string)
{
cout<<"Who directed themovie?"<<directorName<<endl;
}
void Movie::displayInfo(string, int)
{
cout<<movieTitle <<movieYear <<directorName<<endl;
}
string main ()
{
Movie myFavoriteMovie;
}
{
system("pause");
}
Please help me and I will award lifesaver points. Thank you.
Explanation / Answer
#include #include using namespace std; //class declaration class Movie { private: string movieTitle; int movieYear; string directorName; public: void setTitle(stringtitle); void setYear(int year); void setDirector(stringdirector); void displayInfo();//youdon't have to pass anything because function has access to theclass }; //class Implementation void Movie::setTitle(string title) { movieTitle = title; coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.