All pastes #796903 Raw Edit

Unnamed

public cpp v1 · immutable
#796903 ·published 2007-11-25 15:45 UTC
rendered paste body
#include <cstdlib>#include <iostream>using namespace std;/*1. Podaj przykład i omów przeładowanie operatora ++* przyrostkowego* przedrostkowego */class wektor {      public:      int x;      int y;      int z;      wektor(int a = 0, int b = 0, int c = 0)         : x(a), y(b), z(c) {}; // konstruktor domniemany      };// This increment operator is rather odd.// It takes an wektor by value and then makes a new local wektor that to witch// the elements of A, each with 1 added, is added. Then the local wektor is// returned.// Usuallay - and that seems to be indicated by the main function as well -// increment operator updates the argument in place. This operation I would// describe as A + 1 and implement using operator+.wektor operator++(wektor A){       wektor temp;       temp.x = A.x+1;       temp.y = A.y+1;       temp.z = A.z+1;       return temp;       }// In the postincrement case it is normal to tke a copy of the argument, but still// update the argument inplace and then return the unaltered copy.wektor operator++(wektor A, int){       wektor temp;       temp.x = A.x+1;       temp.y = A.y+1;       temp.z = A.z+1;       return temp;       }       ostream& operator<<(ostream& ekran, wektor odc){      // przeladowany operator <<         ekran<<"x= "<<odc.x<<endl;         ekran<<"y= "<<odc.y<<endl;         ekran<<"z= "<<odc.z<<endl;         return ekran;         }               int main(int argc, char *argv[]){    wektor pierwszy;    cout<<pierwszy;    cout << // Added to show what is going on    ++pierwszy;    cout<<pierwszy;    cout << // Added to show what is going on    pierwszy++;     cout<<pierwszy;        system("PAUSE");    return EXIT_SUCCESS;}