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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Objektų tarpusavio sąryšiai<br />

Ankstesniuose pavyzd÷liuose mes tur÷jome vienintelę klasę Food. Tam, kad maisto<br />

parduotuv÷ gal÷tų prad÷ti pardavin÷ti produktus, aprašykime pardavimo klasę<br />

Selling. Čia mes saugome informaciją apie vieną pardavimą: kurį maisto produktą<br />

kada pardav÷me, kiek vienetų pardav÷me <strong>ir</strong> kokia buvo vieno produkto vieneto<br />

kaina.<br />

// selling.h<br />

class Food; // forward declaration<br />

class Selling<br />

{<br />

private:<br />

const Food* food;<br />

std::string date;<br />

int itemCount;<br />

double itemPrice;<br />

public:<br />

Selling (const Food* food,<br />

const std::string& date,<br />

int itemCount,<br />

double itemPrice);<br />

const Food* getFood () const {return food;}<br />

std::string getDate () const {return date;}<br />

int getItemCount () const {return itemCount;}<br />

double getItemPrice () const {return itemPrice;}<br />

double getProfit () const;<br />

void print () const;<br />

};<br />

Klas÷je Food uždraud÷me keisti kainas <strong>ir</strong> palikome tik naujų p<strong>ir</strong>kimų registravimą:<br />

// food.h<br />

class Food<br />

{<br />

private:<br />

std::string name;<br />

double price;<br />

std::vector sellings;<br />

public:<br />

Food (const std::string& name, double price);<br />

std::string getName () const {return name;}<br />

double getPrice () const {return price;}<br />

double getProfit () const;<br />

void print () const;<br />

void addSelling (Selling* selling);<br />

int getSellingCount () const {return sellings.size();}<br />

Selling* getSelling (int i) {return sellings[i];}<br />

};<br />

38

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

Saved successfully!

Ooh no, something went wrong!