Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- /*
- Создать класс money для работы с денежными суммами. число должно быть представлено двумы полями:
- типа long для рублей и типа unsigned char для копеек. дробная часть(копейки) должна быть
- отделена от целой части запятой. реализовать сложение, вычитание, деление сумм, деление суммы
- на дробное число и операции сравнения.
- Создать класс Goods. В классе должны быть представлены поля нименование, дата ояормления,
- цена товара, кол-во единиц, номер накладной. реализовать методы изменения цены товара,
- изменения кол-ва товара(уеньшение и увеличение), вичислекния стоимости. метод toString
- должен выбавать в виде строки стоимость товара.
- */
- using namespace std;
- class CMoney
- {
- private:
- long ruble;
- uint8_t kop;
- public:
- CMoney(){};
- CMoney(long newRubles, uint8_t newKop)
- {
- this->ruble = newRubles + (newKop/100);
- this->kop = newKop%100;
- }
- string toString()
- {
- ostringstream temp;
- temp<<this->ruble<<","<<int(this->kop)<<" руб.";
- return temp.str();
- }
- CMoney operator+(CMoney &add)
- {
- CMoney temp;
- int resultInKop = (this->ruble*100+this->kop) + (add.ruble*100+add.kop);
- temp.ruble = resultInKop/100;
- temp.kop = resultInKop%100;
- return temp;
- }
- CMoney operator-(CMoney &diff)
- {
- CMoney temp;
- int resultInKop = (this->ruble*100+this->kop) - (diff.ruble*100+diff.kop);
- temp.ruble = resultInKop/100;
- temp.kop = resultInKop%100;
- return temp;
- }
- CMoney operator*(double const &mult)
- {
- CMoney temp;
- int resultInKop = (this->ruble*100+this->kop) * mult;
- temp.ruble = resultInKop/100;
- temp.kop = resultInKop%100;
- return temp;
- }
- CMoney operator*(int const &mult)
- {
- CMoney temp;
- int resultInKop = (this->ruble*100+this->kop) * mult;
- temp.ruble = resultInKop/100;
- temp.kop = resultInKop%100;
- return temp;
- }
- CMoney operator/(double const &div)
- {
- CMoney temp;
- int resultInKop = (this->ruble*100+this->kop) / div;
- temp.ruble = resultInKop/100;
- temp.kop = resultInKop%100;
- return temp;
- }
- CMoney operator/(int const &div)
- {
- CMoney temp;
- int resultInKop = (this->ruble*100+this->kop) / div;
- temp.ruble = resultInKop/100;
- temp.kop = resultInKop%100;
- return temp;
- }
- bool operator>(CMoney &op)
- {
- return ((this->ruble*100+this->kop)>(op.ruble*100+op.kop));
- }
- bool operator>=(CMoney &op)
- {
- return ((this->ruble*100+this->kop)>=(op.ruble*100+op.kop));
- }
- bool operator<(CMoney &op)
- {
- return ((this->ruble*100+this->kop)<(op.ruble*100+op.kop));
- }
- bool operator<=(CMoney &op)
- {
- return ((this->ruble*100+this->kop)<=(op.ruble*100+op.kop));
- }
- bool operator==(CMoney &op)
- {
- return ((this->ruble*100+this->kop)==(op.ruble*100+op.kop));
- }
- };
- class CGoodsOpen
- {
- private:
- string name;
- string receiptDate;
- CMoney price;
- int amount;
- unsigned int invoice;
- public:
- CGoodsOpen(){};
- CGoodsOpen(string newName, string newReceiptDate, CMoney newPrice,
- int newAmount, unsigned int newInvoice)
- {
- this->name = newName;
- this->receiptDate = newReceiptDate;
- this->price = newPrice;
- this->amount = newAmount;
- this->invoice = newInvoice;
- }
- string toString()
- {
- return this->cost().toString();
- }
- int increaseAmount(int incr)
- {
- this->amount += incr;
- return 0;
- }
- int decreaseAmount(int decr)
- {
- this->amount -= decr;
- return 0;
- }
- int setPrice(CMoney newPrice)
- {
- this->price = newPrice;
- return 0;
- }
- CMoney cost()
- {
- return this->price * this->amount;
- }
- int discount(unsigned int expirationDays)
- {
- if(expirationDays)
- this->price = this->price * (1-expirationDays*0.01);
- return 0;
- }
- };
- class CGoodsClose
- {
- private:
- string name;
- string receiptDate;
- CMoney price;
- int amount;
- unsigned int invoice;
- public:
- CGoodsClose(){};
- CGoodsClose(string newName, string newReceiptDate, CMoney newPrice,
- int newAmount, unsigned int newInvoice)
- {
- this->name = newName;
- this->receiptDate = newReceiptDate;
- this->price = newPrice;
- this->amount = newAmount;
- this->invoice = newInvoice;
- }
- string toString()
- {
- return this->cost().toString();
- }
- int increaseAmount(int incr)
- {
- this->amount += incr;
- return 0;
- }
- int decreaseAmount(int decr)
- {
- this->amount -= decr;
- return 0;
- }
- int setPrice(CMoney newPrice)
- {
- this->price = newPrice;
- return 0;
- }
- CMoney cost()
- {
- return this->price * this->amount;
- }
- int discount(unsigned int expirationDays)
- {
- if(expirationDays)
- this->price = this->price * (1-expirationDays*0.01);
- return 0;
- }
- };
- class CFoodsItem: public CGoodsOpen
- {
- public:
- CFoodsItem(){};
- CFoodsItem(string newName, string newReceiptDate, CMoney newPrice,
- int newAmount, unsigned int newInvoice)
- {
- CGoodsOpen(newName, newReceiptDate, newPrice, newAmount, newInvoice);
- }
- };
- class CNonFoodsItem: private CGoodsClose
- {
- public:
- CNonFoodsItem(){};
- CNonFoodsItem(string newName, string newReceiptDate, CMoney newPrice,
- int newAmount, unsigned int newInvoice)
- {
- CGoodsOpen(newName, newReceiptDate, newPrice, newAmount, newInvoice);
- }
- string toString()
- {
- return CGoodsClose::toString();
- }
- int increaseAmount(int incr)
- {
- return CGoodsClose::increaseAmount(incr);
- }
- int decreaseAmount(int decr)
- {
- return CGoodsClose::decreaseAmount(decr);
- }
- CMoney cost()
- {
- return CGoodsClose::cost();
- }
- int discount(unsigned int expirationDays)
- {
- return CGoodsClose::discount(expirationDays);
- }
- int setPrice(CMoney newPrice)
- {
- return CGoodsClose::setPrice(newPrice);
- }
- };
- int main()
- {
- setlocale(0,"Russian");
- CNonFoodsItem * test = new CNonFoodsItem("product", "2019-01-01", CMoney(10,30), 10, 12345);
- //test->setPrice(CMoney(10,0));
- cout<<test->toString()<<endl;
- //test->discount(5);
- //cout<<test->toString()<<endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment