Define a class with the following properties. a) Class name : movie b) Private v
ID: 3840296 • Letter: D
Question
Define a class with the following properties. a) Class name : movie b) Private variables should store two movie names and years of release. c) Define a function to set the names and years. Call the functions to set the names and years from the main function. d) For read function, read out which movie is the older one and which is the newer one. For eg. print out "Movie 1 is released in aaa year and Movie 2 is released in bbb year. So 1 is older than 2." e) If you want to be more creative, try to ask the movie details from the user. (There are multiple submissions to this assignment. So Please complete above task, better submit it and then try to modify the code for the input from user.)
write in c++
Explanation / Answer
// classes example
#include <iostream>
#include <string>
using namespace std;
class movie {
private:
string movieName;
int year;
public:
void setNames (string ,int );
string getMovieName() { return movieName;};
int getMovieYear() {return year;};
};
void movie::setNames (string movieN, int yr) {
movieName = movieN;
year = yr;
}
int main () {
movie mv;
movie mv1;
mv.setNames("Baadshah",1978);
mv1.setNames("Nippu",1989);
string movieName1 = mv.getMovieName() ;
string movieName2 = mv1.getMovieName() ;
int movieYear1 = mv.getMovieYear();
int movieYear2 = mv1.getMovieYear();
if(movieYear1 >movieYear2 ){
cout << movieName1 << " is released in " << movieYear1 << " and " << movieName2 << " is released in " <<movieYear2 << " year. So " <<movieName2 << " is older than " << movieName1 ;
}
else if (movieYear1 <movieYear2){
cout << movieName1 << " is released in " << movieYear1 << " and " << movieName2 << " is released in " <<movieYear2 << " year. So " <<movieName1 << " is older than " << movieName2 ;
}else{
cout << "Both the movies are released in the same year.";
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.