#include<iostream> using namespace std; class book { protected: string title; string author; float price; string isbn; public: Book(string title, string author, float price, string isbn) : title(title), author(author), price(price), isbn(isbn) {} virtual ~Book() {} string getTitle() { return title; } string getAuthor() { return author; } float getPrice() { return price; } string getISBN() { return isbn; } void setTitle(string title) { title = title; } void setAuthor(string author) { author = author; } void setPrice(float price) { price = price; } void setISBN(string isbn) { isbn = isbn; } virtual void displayInfo() { cout << "Title: " << title << endl; cout << "Author: " << author << endl; cout << "Price: $" << price << endl; cout << "ISBN: " << isbn << endl; } friend float calculateDiscount(book); }; class eBook : public Book { private: string format; float size; public: eBook(string title, string author, float price, string isbn, string format, float size) : book(title, author, price, isbn), format(format), size(size) {} virtual void displayInfo() { book::displayInfo(); cout << "Format: " << format << endl; cout << "Size: " << size << " MB" << endl; } }; float calculatediscount(book b) { int bk=b.price; if(500<bk<1000) { cout<<"Discount :"<< bk-(bk*0.3)<<endl; } else if(bk>1500) { cout<<"Discount :"<< bk-(bk*0.5)<<endl; } else { cout<<"No Discount"<<endl; } return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter