Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <string>
- #include <cstdlib>
- #include <iostream>
- #include <fstream>
- #include <conio.h>
- using namespace std;
- class Statyczna
- {
- protected:
- static int liczbaInstancji; // pole statyczne
- public:
- double x,y;
- Statyczna()
- {
- liczbaInstancji++;
- }
- virtual ~Statyczna()
- {
- liczbaInstancji--;
- }
- static int LiczbaInstancji()
- {
- return liczbaInstancji;
- }
- void nie_zwieksz (int ref) /*Referencje*/
- {
- ++ref;
- }
- void zwieksz_c (int *ref)
- {
- ++(*ref);
- }
- void zwieksz_cpp (int& ref)
- {
- ++ref;
- }
- };
- class complex {
- protected:
- double Re, Im;
- public:
- complex() : Re(0.0), Im(0.0) {}
- complex(double Re, double Im) : Re(Re), Im(Im) {}
- double getRe() const { return Re; }
- double getIm() const { return Im; }
- friend complex operator+(const complex&, const complex&);
- friend ostream& operator<<(ostream&, const complex&); //
- };
- complex operator+(const complex& a, const complex& b) {
- double r, i;
- r = a.getRe() + b.getRe();
- i = a.getIm() + b.getIm();
- return complex(r, i);
- }
- ostream& operator<<(ostream& out, const complex &a) {
- out << "(" << a.getRe() << ", " << a.getIm() << ")" << endl;
- return out;
- }
- int Statyczna::liczbaInstancji=0;
- class book{
- private:
- static int destruktor;
- public:
- static int konstuktor;
- string name;
- int * p; // Do dynamicznej alokacji
- int * pom;
- int pages,price;
- book()
- {
- cout<<"\nTworze ksiazke z 1 parametrem";
- name = "star wars";
- pages = 0;
- price = 0;
- }
- book(int _pages,int _price)
- {
- cout<<"\nDwa parametry";
- pages = _pages;
- price = _price;
- name = "star wars 2";
- p = new int;
- *p = price; // aby cos zniszczyc, destruktor etc
- }
- book(string _name,int _pages, int _price)
- {
- cout<<"\nTrzy parametry";
- name = _name;
- pages = _pages;
- price = _price;
- pom = new int;
- *pom = price;
- }
- ~book() // Destruktor
- {
- // ...
- delete p;
- delete pom;
- }
- //
- };
- class komp{
- private:
- int pamiec;
- float procesor;
- int dysk;
- public:
- int rok_produkcji;
- int zmienna;
- komp(int rok_produkcji)
- {
- cout<<"Wybrałeś komputer z roku: "<<rok_produkcji<<endl;
- }
- int DzielWiek( int rok_produkcji, int zmienna );
- komp( int a, float b, int c){
- pamiec=a;
- procesor=b;
- ustawdysk(c);
- char *pBuffer = new char[1024];
- delete[] pBuffer;
- }
- void ustawdysk(int x){
- dysk = x;
- }
- void CoZaKomp(){
- cout<<"Pamiec: "<<pamiec<<" Mb, Procesor: "<<procesor<<" GHz,Dysk: "<<dysk<<" Gb."<<endl<<endl;
- }
- protected:
- int karta_graficzna;
- };
- int komp::DzielWiek( int rok_produkcji, int zmienna )
- {
- return rok_produkcji/zmienna;
- }
- class Grafa : public komp
- {
- public:
- int a,b,c;
- Grafa();
- void posiadam()
- {
- std::cout << "Mam grafike geforce, a ty? \n";
- }
- void przegrzewam()
- {
- std::cout << "Przegrzewa mi sie grafika\n";
- }
- };
- class Myszka : public komp
- {
- public:
- void posiadam1()
- {
- std::cout << "Mam myszke logitech, a ty? \n";
- }
- void bateria()
- {
- std::cout << "Slaba bateria\n";
- }
- };
- int main(int argc, char *argv[])
- {
- komp acer(1024, 2.3, 250);
- komp hp(512, 2.8,1000);
- hp.rok_produkcji = 2013;
- hp.zmienna = 3;
- komp asus(2048, 3.0, 500);
- cout << "Wynik to: " << hp.DzielWiek(2012, 4) << endl;
- cout << endl;
- cout<<"Acer: "<<endl;
- acer.CoZaKomp();
- cout<<"Asus: "<<endl;
- asus.CoZaKomp();
- cout<<"Rok produkcji to: " << hp.rok_produkcji <<endl;
- cout << endl;
- book math;
- cout<<"("<<math.name<<" "<<math.pages<<" "<<math.price<<")";
- book cpp(300,50000);
- cout << endl;
- cout<<"("<<cpp.name<<" "<<cpp.pages<<" "<<cpp.price<<" )";
- book art("word art",300,50000);
- cout << endl;
- cout<<"("<<art.name<<" "<<art.pages<<" "<<art.price<<" )";
- cout << endl;
- cout<< "Zmienna statyczna dzialanie przez referencje klasy: \n";
- int i=Statyczna::LiczbaInstancji();
- cout << i << endl;
- Statyczna referencja;
- int d=0,e=2, f=0;
- referencja.nie_zwieksz (d);
- referencja.zwieksz_c (&e);
- referencja.zwieksz_cpp (f);
- cout << "Pokazuje dzialanie referencji: " << d << " " << e << " " << f << endl;
- cout << "Przeciazam operatory: \n";
- complex a(1,2), b(3,4), c;
- c = a+b;
- cout << c << endl;
- system("PAUSE");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment