Publications
SAT
c_cpp
a year ago
1.0 kB
5
Indexable
#include <iostream>
#include <string>
using namespace std;
class Publication {
protected:
string title;
int copies;
int price;
public:
virtual void saleCopy() {
// Base class method, can be overridden in derived classes
}
};
class Book : public Publication {
private:
string author;
public:
void saleCopy() override {
price = 250;
cout << "Total sale of Books: " << copies * price << endl;
}
void orderCopy() {
cout << "Enter number of book copies: ";
cin >> copies;
}
};
class Magazine : public Publication {
public:
void saleCopy() override {
price = 250;
cout << "Total sale of Magazine: " << copies * price << endl;
}
void orderQuantity() {
cout << "Enter number of magazine copies: ";
cin >> copies;
}
};
int main() {
Book b;
b.orderCopy();
b.saleCopy();
Magazine m;
m.orderQuantity();
m.saleCopy();
return 0;
}
Editor is loading...
Leave a Comment