/*
* File: main.cpp
* Author: Micren
*
* Created on 15 Февраль 2011 г., 16:31
*/
#include <iostream>
#include <iomanip>
// Классы согласно условия
class num
{
public:
num(int value = 0);
virtual void show(std::ostream &stream) const;
int value() const;
protected:
int _value;
};
class outhex : public num
{
public:
outhex(int value = 0);
outhex(const num& value);
virtual void show(std::ostream &stream) const;
};
class outoct : public num
{
public:
outoct(int value = 0);
outoct(const num& value);
virtual void show(std::ostream &stream) const;
};
// Ф-я для вывода результатов
// Для демонстрирации полиморфизма используем ссылку или указатель
void print(const char* const msg, const num& val)
{
std::cout << msg;
val.show(std::cout);
std::cout << std::endl;
}
/*
*
*/
int main()
{
num number(10);
outhex hex(number);
outoct oct(number);
print("number=", number);
print("outhex=", hex);
print("outoct=", oct);
#ifdef _WIN32
system("pause");
#endif
return 0;
}
num::num(int value)
: _value(value)
{
}
void num::show(std::ostream &stream) const
{
stream << _value;
}
int num::value() const
{
return _value;
}
outhex::outhex(int value)
: num(value)
{
}
outhex::outhex(const num& value)
: num(value)
{
}
void outhex::show(std::ostream& stream) const
{
stream << std::hex << _value;
}
outoct::outoct(int value)
: num(value)
{
}
outoct::outoct(const num& value)
: num(value)
{
}
void outoct::show(std::ostream& stream) const
{
stream << std::oct << _value;
}
number=10
outhex=a
outoct=12
Если Вы уже зарегистрированы на Портале - войдите в систему, если Вы еще не регистрировались - пройдите простую процедуру регистрации.