You are viewing a single comment's thread. Return to all comments →
Solution in C++:
using namespace std; class Book{ protected: string title; string author; public: Book(string t,string a){ title=t; author=a; } virtual void display()=0;
};
// Write your MyBook class here
class MyBook : public Book{
int price; // Class Constructor // // Parameters: // title - The book's title. // author - The book's author. // price - The book's price. // // Write your constructor here public: MyBook(string title, string author, int price) : Book(title, author), price(price) { this->price = price; } // Function Name: display // Print the title, author, and price in the specified format. // // Write your method here void display() override { cout << "Title: " << title << endl; cout << "Author: " << author << endl; cout << "Price: " << price << endl; }
}; // End class
int main() { string title,author; int price; getline(cin,title); getline(cin,author); cin>>price; MyBook novel(title,author,price); novel.display(); return 0; }
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 →
Solution in C++:
include
include
include
include
include
include
using namespace std; class Book{ protected: string title; string author; public: Book(string t,string a){ title=t; author=a; } virtual void display()=0;
};
// Write your MyBook class here
class MyBook : public Book{
};
// End class
int main() { string title,author; int price; getline(cin,title); getline(cin,author); cin>>price; MyBook novel(title,author,price); novel.display(); return 0; }