4. Use this C+tcode to answer question 4 CS280 Spring 2015 Final Ex class Film s
ID: 3835540 • Letter: 4
Question
4. Use this C+tcode to answer question 4 CS280 Spring 2015 Final Ex class Film string name float rtpct public: Film (string name float rtpct 1) this name name this >rtpct. rtpct; virtual s tring filmtype return "unspecified" float rtp return rtpct; class comedy public Film int chuckles; public: Comedy (string name float rtpct-0, int chuckles 0) Film (name rtpct) this chuckles chuckles string filmtype return Comedy" int get laughs return chuckles main Film films new Film Battle of Five Armies 0.88) new Film ("Frozen", 0.97) new comedy Wedding Crashers o 74 47) printf ("Here In")Explanation / Answer
a)
class Cartoon : public Film{
string studio;
public:
Cartoon(string name, float rtpct = 0, string s) :
Film(name, rtpct) {
studio = s;
}
string getStudio(){
return studio;
}
string filmtype(){
return "Cartoon";
}
};
b)
i)
films[0]->filmtype()
output: unspecified
ii)
films[2]->rtpct();
output: Error, there is no method name rtpct() in Film class
c)
films[2]->getlaughs() will generate compiler error because
getlaughs() method is not avaialble in Film class.
So, we can add a pure virtual function in Film class:
virtual getlaughs() = 0; // add this in Film class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.