trojanxem

Untitled

Jun 17th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.75 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.         ~book()            // Destruktor
  110.     {
  111.     // ...
  112.     delete p;
  113.     delete pom;
  114.     }
  115.  
  116.  
  117.     //
  118.         };
  119.  
  120.         class komp{
  121.  
  122.  
  123.         private:
  124.         int pamiec;
  125.         float procesor;
  126.         int dysk;
  127.  
  128.         public:
  129.  
  130.             int rok_produkcji;
  131.             int zmienna;
  132.  
  133.             komp(int rok_produkcji)
  134.          {
  135.               cout<<"Wybrałeś komputer z roku: "<<rok_produkcji<<endl;
  136.  
  137.          }
  138.  
  139.         int DzielWiek( int rok_produkcji, int zmienna );
  140.  
  141.         komp( int a, float b, int c){
  142.         pamiec=a;
  143.         procesor=b;
  144.         ustawdysk(c);
  145.         char *pBuffer = new char[1024];
  146.         delete[] pBuffer;
  147.  
  148.  
  149.  
  150.         }
  151.  
  152.  
  153.         void ustawdysk(int x){
  154.         dysk = x;
  155.         }
  156.  
  157.  
  158.         void CoZaKomp(){
  159.  
  160.         cout<<"Pamiec: "<<pamiec<<" Mb, Procesor: "<<procesor<<" GHz,Dysk: "<<dysk<<" Gb."<<endl<<endl;
  161.  
  162.         }
  163.         protected:
  164.             int karta_graficzna;
  165.  
  166.         };
  167.  
  168.         int komp::DzielWiek( int rok_produkcji, int zmienna )
  169.         {
  170.             return rok_produkcji/zmienna;
  171.         }
  172.  
  173.         class Grafa : public komp
  174.      {
  175.         public:
  176.             int a,b,c;
  177.  
  178.  
  179.             Grafa();
  180.  
  181.  
  182.           void posiadam()
  183.           {
  184.              std::cout << "Mam grafike geforce, a ty? \n";
  185.           }
  186.  
  187.           void przegrzewam()
  188.           {
  189.              std::cout << "Przegrzewa mi sie grafika\n";
  190.           }
  191.      };
  192.      class Myszka : public komp
  193.      {
  194.         public:
  195.  
  196.           void posiadam1()
  197.           {
  198.              std::cout << "Mam myszke logitech, a ty? \n";
  199.           }
  200.  
  201.           void bateria()
  202.           {
  203.              std::cout << "Slaba bateria\n";
  204.           }
  205.      };
  206.  
  207.  
  208.  
  209.         int main(int argc, char *argv[])
  210.         {
  211.         komp acer(1024, 2.3, 250);
  212.         komp hp(512, 2.8,1000);
  213.         hp.rok_produkcji = 2013;
  214.         hp.zmienna = 3;
  215.         komp asus(2048, 3.0, 500);
  216.         cout << "Wynik to: " << hp.DzielWiek(2012, 4) << endl;
  217.         cout << endl;
  218.         cout<<"Acer: "<<endl;
  219.         acer.CoZaKomp();
  220.         cout<<"Asus: "<<endl;
  221.         asus.CoZaKomp();
  222.         cout<<"Rok produkcji to: " << hp.rok_produkcji <<endl;
  223.         cout << endl;
  224.         book math;
  225.     cout<<"("<<math.name<<" "<<math.pages<<" "<<math.price<<")";
  226.     book cpp(300,50000);
  227.     cout << endl;
  228.     cout<<"("<<cpp.name<<" "<<cpp.pages<<" "<<cpp.price<<" )";
  229.     book art("word art",300,50000);
  230.     cout << endl;
  231.     cout<<"("<<art.name<<" "<<art.pages<<" "<<art.price<<" )";
  232.     cout << endl;
  233.  
  234.     cout<< "Zmienna statyczna dzialanie przez referencje klasy: \n";
  235.     int i=Statyczna::LiczbaInstancji();
  236.     cout << i << endl;
  237.     Statyczna referencja;
  238.     int d=0,e=2, f=0;
  239.       referencja.nie_zwieksz (d);
  240.     referencja.zwieksz_c (&e);
  241.      referencja.zwieksz_cpp (f);
  242.      cout << "Pokazuje dzialanie referencji: " << d << " " <<  e << " " << f << endl;
  243.      cout << "Przeciazam operatory: \n";
  244.      complex a(1,2), b(3,4), c;
  245.     c = a+b;
  246.     cout << c << endl;
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.         system("PAUSE");
  257.         return EXIT_SUCCESS;
  258.         }
Advertisement
Add Comment
Please, Sign In to add comment