Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- //#include
- using namespace std;
- //---------------------
- //------- Class -------
- //---------------------
- class tNadoba{
- private:
- string napln;
- int kapacita, objem;
- public:
- tNadoba(int);
- bool Napln(string, int);
- tNadoba operator+=(int);
- tNadoba operator-=(int);
- tNadoba operator+=(tNadoba);
- tNadoba operator-=(tNadoba);
- };
- //------- konstr -------
- tNadoba::tNadoba(int k = 0){
- this->kapacita = k;
- }
- //--------------------
- //------- Func -------
- //--------------------
- bool tNadoba::Napln(string nap, int obj){
- if(this->kapacita >= obj + this->objem){
- this->objem += obj;
- return true;
- }
- else return false;
- }
- //---------------------
- //------- MAIN --------
- //---------------------
- int main(int argc, char** argv) {
- tNadoba bandaska(10), flasa(1.5), sudok(5), pivny_pohar(0.5);
- if (sudok.Napln("pivo", 5))
- cout << "Kupili sme plny sudok: " << sudok << endl;
- int i = 0;
- while (sudok -= pivny_pohar)
- {
- cout << "Uliali sme " << ++i << " pohar: " << pivny_pohar << endl;
- while (pivny_pohar -= 0.25)
- cout << "Splachli sme do hrdla 1/4 litra, stav: " << pivny_pohar << endl;
- }
- while (bandaska.Napln("benzin", 2))
- cout << "Bandasku sme naplnili 2 l, stav: " << bandaska << endl;
- while (bandaska -= flasa)
- {
- cout << "Odliali sme z bandasky do flase:\n";
- cout << " - stav bandasky: " << bandaska << "\n";
- cout << " - stav flase: " << flasa << "\n";
- while (flasa -= 1)
- cout << "Z flase sme odliali 1 l, stav: " << flasa << endl;
- }
- cout << "Zaverecny stav bandasky: " << bandaska << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement