31.12.2014 Views

Paskaitų konspektai - Matematikos ir Informatikos fakultetas ...

Paskaitų konspektai - Matematikos ir Informatikos fakultetas ...

Paskaitų konspektai - Matematikos ir Informatikos fakultetas ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Konstruktoriai <strong>ir</strong> tipų konversija<br />

Panagrin÷kime kompleksinius skaičius, kurie turi realiąją <strong>ir</strong> menamąją dalis:<br />

// typeconstr.cpp<br />

class Complex<br />

{<br />

private:<br />

double r;<br />

double i;<br />

public:<br />

Complex (double re=0, double im=0) : r(re), i(im) {}<br />

Complex add (const Complex& c);<br />

};<br />

void print();<br />

Trumput÷ klas÷s realizacija:<br />

Complex Complex::add (const Complex& c)<br />

{<br />

return Complex(r+c.r, i+c.i);<br />

}<br />

void Complex::print ()<br />

{<br />

cout

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!