Hackerrank | 30 days of code | Day 13-Solution in c++| Abstract-Classes-hackerrank-Solution-in-c++


Hackerrank | 30 days of code | Day 13-Solution in c++| Abstract-Classes-hackerrank-Solution-in-c++

Hackerrank Solution 30-days-of-code
https://www.hackerrank.com/challenges/30-abstract-classes/problem
Day 13 Abstract Classes Solution in Cpp
#include <iostream> using namespace std; class Book { protected: string title; string author; public: Book(string t, string a) { title = t; author = a; } virtual void display()=0; }; class MyBook : public Book { private: int price; public: MyBook(string title, string author, int price) : Book(title, author) { this->price = price; } void display() { cout << "Title: " << this->title << endl; cout << "Author: " << this->author << endl; cout << "Price: " << this->price << endl; } }; int main() { string title, author; int price; getline(cin, title); getline(cin, author); cin >> price; MyBook novel(title, author, price); novel.display(); return 0; } }

Post a Comment

0 Comments