Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<cstring>
- using namespace std;
- class PrintEdition
- {
- private:
- double pricePerPage;
- int pages;
- int issue;
- char* name;
- void copy(const PrintEdition& other)
- {
- this->pricePerPage=other.pricePerPage;
- this->pages=other.pages;
- this->issue=other.issue;
- this->name=new char[strlen(name)+1];
- strcpy(this->name,other.name);
- }
- void del()
- {
- delete[]name;
- }
- public:
- PrintEdition()
- {
- this->pricePerPage=0.0;
- this->pages=0;
- this->issue=0;
- this->name=nullptr;
- }
- PrintEdition(double pricePerPage,int pages,int issue,char* name)
- {
- this->pricePerPage=pricePerPage;
- this->pages=pages;
- this->issue=issue;
- this->name=new char[strlen(name)+1];
- strcpy(this->name,name);
- }
- PrintEdition(const PrintEdition& other)
- {
- this->copy(other);
- }
- PrintEdition& operator=(const PrintEdition& other)
- {
- if(this!=&other)
- {
- this->del();
- this->copy(other);
- }
- return* this;
- }
- ~PrintEdition()
- {
- this->del();
- }
- void setPricePerPage(double pricePerPage)
- {
- this->pricePerPage=pricePerPage;
- }
- double getPricePerPage() const
- {
- return this->pricePerPage;
- }
- void setPages (int pages)
- {
- this->pages=pages;
- }
- int getPages() const
- {
- return this->pages;
- }
- void setIssue(int issue)
- {
- this->issue=issue;
- }
- int getIssue() const
- {
- return this->issue;
- }
- void setName(const char* name)
- {
- delete[]name;
- this->name=new char[strlen(name)+1];
- strcpy(this->name,name);
- }
- const char* getName()const
- {
- return this->name;
- }
- double getPrintPrice()const;
- virtual void showInfo()const =0;
- double getSellPrice();
- virtual double getAdditionalPrice()=0;
- };
- void PrintEdition::showInfo()const
- {
- cout<<"Price per page:"<<pricePerPage<<endl;
- cout<<"Pages:"<<pages<<endl;
- cout<<"Issue:"<<issue<<endl;
- cout<<"Name:"<<name<<endl;
- }
- double PrintEdition::getPrintPrice()const
- {
- return pricePerPage*pages;
- }
- double PrintEdition::getSellPrice()
- {
- return getPrintPrice()+getAdditionalPrice();
- }
- class Newspaper:public PrintEdition
- {
- private:
- char printDate[128];
- int ads;
- public:
- double getSellPrice()
- {
- return getPrintPrice()+(ads*(-0.05));
- }
- };
- class Magazine:public PrintEdition
- {
- private:
- bool hasPosters;
- int numberOfInterviews;
- public:
- double getSellPrice();
- };
- double Magazine::getSellPrice()
- {
- if(hasPosters==true)
- {
- return getPrintPrice()+1.50+numberOfInterviews * 1 ;
- }
- return getPrintPrice() + numberOfInterviews * 1 ;
- }
- class Book:public PrintEdition
- {
- private:
- char authorName[128];
- bool hasHardcovers;
- int year;
- public:
- double getSellPrice()
- {
- if(hasHardcovers==true)
- {
- return getPrintPrice()+5;
- }
- return getPrintPrice()+2.50;
- }
- };
- int main()
- {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement