Третья группа

Материал из SEWiki
Перейти к: навигация, поиск

Общее

Задания

Компиляция

Сортировка слиянием

Выделение памяти

Расширяющийся массив

Обертка над FILE

String

Smart FILE

Streams

Наследуясь от класса OutputStream реализовать Иерархию классов FileOutputStream, StringOutputStream, ConsoleOutputStream имеющие соответствующую функциональность.

struct OutputStream
{
    virtual void print( std::string const& s ) = 0;

    virtual void print( int t ) 
    {
        char buff[16] = {};
        sprintf(buff, "%d", t);
        print(buff);
    }

    virtual void print( double t ) 
    {
        char buff[16] = {};
        sprintf(buff, "%f", t);
        print(buff);
    }

    virtual void flush() = 0;

    virtual ~OutputStream() {}
};


Rationals


// Rational.h

class Rational {

    Rational & operator+=( Rational const& b );

    Rational & operator-=( Rational const& b );

    Rational & operator/=( Rational const& b );

    Rational & operator*=( Rational const& b );

    Rational operator-() const;

    double to_double() const;

    int nom();
    int den();

};

ostream & operator<<(ostream & os, Rational const& r);
istream & operator>>(istream & is, Rational & r);

Rational  operator+( Rational a, Rational const& b );
Rational  operator-( Rational a, Rational const& b );
Rational  operator/( Rational a, Rational const& b );
Rational  operator*( Rational a, Rational const& b );

bool operator==( Rational const& a, Rational const& b );
bool operator!=( Rational const& a, Rational const& b );
bool operator<( Rational const& a, Rational const& b );
bool operator<=( Rational const& a, Rational const& b );
bool operator>( Rational const& a, Rational const& b );
bool operator>=( Rational const& a, Rational const& b );
~