Третья группа — различия между версиями

Материал из SEWiki
Перейти к: навигация, поиск
(Streams)
Строка 43: Строка 43:
 
     virtual ~OutputStream() {}
 
     virtual ~OutputStream() {}
 
};
 
};
 +
</pre>
 +
 +
 +
== Rationals ==
 +
 +
<pre>
 +
 +
// 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 );
 +
~                                                               
 
</pre>
 
</pre>

Версия 15:08, 23 ноября 2012

Общее

Задания

Компиляция

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

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

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

Обертка над 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 );
~