Q#3)a. Define a class named Movie. Include private fields for the title, year, and name of the director.
Include three public functions with the prototypes
void Movie::setTitle(string);
void Movie::setYear(int);
void Movie::setDirector(string);
Include another function that displays all the information about a Movie.
b. Include a function which accepts 2 objects of type Movie and displays whether or not they were
released in the same year and also whether the Directors are same. String functions may be used.
#include<iostream>
using namespace std;
class Movie{
private :
string title, director;
int year;
public:
void setTitle(string t){
title = t;
}
void setYear(int y){
year = y;
}
void setDirector(string d){
director = d;
}
void display(){
cout<<"The title is: "<<title<<"\nThe director is: "<<director<<"\nThe year released is:Â "<<year<<endl;
}
void check(Movie d){
if(year==d.year){
cout<<"The movies were released in the same year\n";
}
else{
cout<<"The movies were not released in the same year\n";
}
}
};
int main(){
Movie m1, m2;
m1.setTitle("Bad girl");
m1.setDirector("Michael");
m1.setYear(2021);
m2.setTitle("Prison Break");
m2.setDirector("Lincoln");
m2.setYear(2021);
m1.check(m2);
}
Comments
Leave a comment