trojanxem

Untitled

Jun 17th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.39 KB | None | 0 0
  1.         #include <cstdio>
  2.         #include <string>
  3.         #include <cstdlib>
  4.         #include <iostream>
  5.         #include <fstream>
  6.         #include <conio.h>
  7.         using namespace std;
  8.  
  9.  
  10.  
  11.         class Statyczna
  12.    {
  13.         protected:
  14.              static int liczbaInstancji; // pole statyczne
  15.         public:
  16.             double x,y;
  17.  
  18.              Statyczna()
  19.              {
  20.                   liczbaInstancji++;
  21.              }
  22.              virtual ~Statyczna()
  23.              {
  24.                   liczbaInstancji--;
  25.              }
  26.              static int LiczbaInstancji()
  27.              {
  28.                   return liczbaInstancji;
  29.              }
  30.              void nie_zwieksz (int ref)     /*Referencje*/
  31. {
  32.    ++ref;
  33. }
  34. void zwieksz_c (int *ref)
  35. {
  36.    ++(*ref);
  37. }
  38. void zwieksz_cpp (int& ref)
  39. {
  40.    ++ref;
  41. }
  42.    };
  43.  
  44.    class complex {
  45.     protected:
  46.     double Re, Im;
  47.  
  48.     public:
  49.     complex() : Re(0.0), Im(0.0) {}
  50.     complex(double Re, double Im) : Re(Re), Im(Im) {}
  51.     double getRe() const { return Re; }
  52.     double getIm() const { return Im; }
  53.     friend complex operator+(const complex&, const complex&);
  54.     friend ostream& operator<<(ostream&, const complex&); //
  55. };
  56. complex operator+(const complex& a, const complex& b) {
  57.     double r, i;
  58.     r = a.getRe() + b.getRe();
  59.     i = a.getIm() + b.getIm();
  60.     return complex(r, i);
  61. }
  62.  
  63. ostream& operator<<(ostream& out, const complex &a) {
  64.     out << "(" << a.getRe() << ", " << a.getIm() << ")" << endl;
  65.     return out;
  66. }
  67.  
  68.    int Statyczna::liczbaInstancji=0;
  69.  
  70.         class book{
  71.         private:
  72.             static int destruktor;
  73.              public:
  74.                  static int konstuktor;
  75.  
  76.     string name;
  77.     int * p;        // Do dynamicznej alokacji
  78.     int * pom;
  79.     int pages,price;
  80.     book()
  81.         {
  82.             cout<<"\nTworze ksiazke z 1 parametrem";
  83.             name = "star wars";
  84.             pages = 0;
  85.             price = 0;
  86.  
  87.  
  88.         }
  89.     book(int _pages,int _price)
  90.         {
  91.             cout<<"\nDwa parametry";
  92.             pages = _pages;
  93.             price = _price;
  94.             name = "star wars 2";
  95.             p = new int;
  96.     *p = price;     // aby cos zniszczyc, destruktor etc
  97.  
  98.         }
  99.     book(string _name,int _pages, int _price)
  100.         {
  101.             cout<<"\nTrzy parametry";
  102.             name = _name;
  103.             pages = _pages;
  104.             price = _price;
  105.             pom = new int;
  106.             *pom = price;
  107.  
  108.         }
  109.  
  110.         ~book()            // Destruktor
  111.     {
  112.     // ...
  113.     delete p;
  114.     delete pom;
  115.     }
  116.  
  117.  
  118.     //
  119.         };
  120.         class A {
  121.            double x;
  122.         public:
  123.           A(double x = 1) {
  124.                 this->x = x;
  125.               cout << "W konstruktorze domyslnym"  << endl;
  126.           }
  127.  
  128.            A(const A& a) {
  129.               x = a.x;
  130.              cout << "W konstruktorze kopiujacym" << endl;
  131.           }
  132.     };
  133.  
  134.        A fun(A a) {
  135.            cout << "W funkcji fun" << endl;
  136.           return a;
  137.        }
  138.  
  139.         class komp{
  140.  
  141.  
  142.         private:
  143.         int pamiec;
  144.         float procesor;
  145.         int dysk;
  146.  
  147.         public:
  148.  
  149.             int rok_produkcji;
  150.             int zmienna;
  151.  
  152.             komp(int rok_produkcji)
  153.          {
  154.               cout<<"Wybrałeś komputer z roku: "<<rok_produkcji<<endl;
  155.  
  156.          }
  157.  
  158.         int DzielWiek( int rok_produkcji, int zmienna );
  159.  
  160.         komp( int a, float b, int c){
  161.         pamiec=a;
  162.         procesor=b;
  163.         ustawdysk(c);
  164.         char *pBuffer = new char[1024];
  165.         delete[] pBuffer;
  166.  
  167.  
  168.  
  169.         }
  170.  
  171.  
  172.         void ustawdysk(int x){
  173.         dysk = x;
  174.         }
  175.  
  176.  
  177.         void CoZaKomp(){
  178.  
  179.         cout<<"Pamiec: "<<pamiec<<" Mb, Procesor: "<<procesor<<" GHz,Dysk: "<<dysk<<" Gb."<<endl<<endl;
  180.  
  181.         }
  182.         protected:
  183.             int karta_graficzna;
  184.  
  185.         };
  186.  
  187.         int komp::DzielWiek( int rok_produkcji, int zmienna )
  188.         {
  189.             return rok_produkcji/zmienna;
  190.         }
  191.  
  192.         class Grafa : public komp
  193.      {
  194.         public:
  195.             int a,b,c;
  196.  
  197.  
  198.             Grafa();
  199.  
  200.  
  201.           void posiadam()
  202.           {
  203.              std::cout << "Mam grafike geforce, a ty? \n";
  204.           }
  205.  
  206.           void przegrzewam()
  207.           {
  208.              std::cout << "Przegrzewa mi sie grafika\n";
  209.           }
  210.      };
  211.      class Myszka : public komp
  212.      {
  213.         public:
  214.  
  215.           void posiadam1()
  216.           {
  217.              std::cout << "Mam myszke logitech, a ty? \n";
  218.           }
  219.  
  220.           void bateria()
  221.           {
  222.              std::cout << "Slaba bateria\n";
  223.           }
  224.      };
  225.  
  226.  
  227.  
  228.         int main(int argc, char *argv[])
  229.         {
  230.         komp acer(1024, 2.3, 250);
  231.         komp hp(512, 2.8,1000);
  232.         hp.rok_produkcji = 2013;
  233.         hp.zmienna = 3;
  234.         komp asus(2048, 3.0, 500);
  235.         cout << "Wynik to: " << hp.DzielWiek(2012, 4) << endl;
  236.         cout << endl;
  237.         cout<<"Acer: "<<endl;
  238.         acer.CoZaKomp();
  239.         cout<<"Asus: "<<endl;
  240.         asus.CoZaKomp();
  241.         cout<<"Rok produkcji to: " << hp.rok_produkcji <<endl;
  242.         cout << endl;
  243.         book math;
  244.     cout<<"("<<math.name<<" "<<math.pages<<" "<<math.price<<")";
  245.     book cpp(300,50000);
  246.     cout << endl;
  247.     cout<<"("<<cpp.name<<" "<<cpp.pages<<" "<<cpp.price<<" )";
  248.     book art("word art",300,50000);
  249.     cout << endl;
  250.     cout<<"("<<art.name<<" "<<art.pages<<" "<<art.price<<" )";
  251.     cout << endl;
  252.  
  253.     cout<< "Zmienna statyczna dzialanie przez referencje klasy: \n";
  254.     int i=Statyczna::LiczbaInstancji();
  255.     cout << i << endl;
  256.     Statyczna referencja;
  257.     int d=0,e=2, f=0;
  258.       referencja.nie_zwieksz (d);
  259.     referencja.zwieksz_c (&e);
  260.      referencja.zwieksz_cpp (f);
  261.      cout << "Pokazuje dzialanie referencji: " << d << " " <<  e << " " << f << endl;
  262.      cout << "Przeciazenie operatorow: \n";
  263.      complex a(1,2), b(3,4), c;
  264.     c = a+b;
  265.     cout << c << endl;
  266.     cout << "Konstruktor kopiujacy! \n";
  267.  cout << "**1**" << endl;
  268.       A aa;
  269.       cout << "**2**" << endl;
  270.           A bb= aa;
  271.          cout << "**3**" << endl;
  272.          A cc(bb);
  273.          cout << "**4**" << endl;
  274.           cc = fun(aa);
  275.  
  276.  
  277.         system("PAUSE");
  278.         return EXIT_SUCCESS;
  279.         }
Advertisement
Add Comment
Please, Sign In to add comment