We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<string>#include<iostream>usingnamespacestd;classBook{private:stringtitle;stringauthor;protected:stringgetTitle()const{returntitle;}stringgetAuthor()const{returnauthor;}public:Book(stringtitle,stringauthor):title(title),author(author){}virtualvoiddisplay()=0;};classMyBook:Book{private:intprice;public:MyBook(stringtitle,stringauthor,intprice):Book(title,author),price(price){}voiddisplay(){cout<<"Title: "<<getTitle()<<endl<<"Author: "<<getAuthor()<<endl<<"Price: "<<price<<endl;}};intmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT */stringtitle,author;getline(cin,title);getline(cin,author);intprice;cin>>price;MyBookb(title,author,price);b.display();return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 13: Abstract Classes
You are viewing a single comment's thread. Return to all comments →
My C++ solution: