Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 2 task
- #include <iostream>
- class Coiner {
- int nominal, count;
- public:
- Coiner() {};
- Coiner(int nominal, int count) {
- this->nominal = nominal;
- this->count = count;
- }
- void print() {
- std::cout << "<Coiner nominal: " << this->nominal << " count: " << this->count << ">";
- }
- int sum() {
- return this->nominal * this->count;
- }
- };
- class Exchanger : Coiner {
- double grivnas_in_dollar;
- public:
- Exchanger(int nominal, int count, double grivnas_in_dollar) :
- Coiner(nominal, count) {
- this->grivnas_in_dollar = grivnas_in_dollar;
- }
- double sum_in_cents() {
- return this->sum() / this->grivnas_in_dollar * 100;
- }
- };
- int main() {
- int n, c;
- std::cout << "Введите номинал монеты: ";
- std::cin >> n;
- std::cout << "Введите количество монет: ";
- std::cin >> c;
- Coiner coiner(n, c);
- std::cout << "Строка с информацией о родительском объекте:" << std::endl;
- coiner.print();
- std::cout << std::endl << "Сумма монет: " << coiner.sum() << std::endl;
- double d;
- std::cout << "Введите стоимость 1 доллара в гривнах: ";
- std::cin >> d;
- Exchanger e(n, c, d);
- std::cout << "Стоимость монет в центах: " << e.sum_in_cents();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement