Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //plik.h
- #include <iostream>
- #include <ctime>
- #include <cmath>
- using namespace std;
- #pragma once
- struct Punkt {
- int x;
- int y;
- Punkt(int, int);
- Punkt(int, int, int);
- };
- class Odcinek {
- Punkt *poczatek;
- Punkt *koniec;
- public:
- double dlugoscodcinka();
- Odcinek(int, int, int, int, int);
- };
- class Okrag {
- friend int przeciecie(Okrag, Okrag);
- friend double Odcinek::dlugoscodcinka();
- friend void wypisz(Okrag, Okrag);
- static int licznik;
- Punkt *srodek;
- int promien;
- public:
- Okrag(int, int, int);
- Okrag(int, int, int, int);
- Okrag();
- static int getLicznik();
- ~Okrag();
- };
- //klasy.cpp
- #include <iostream>
- #include <ctime>
- #include <cmath>
- #include "plik.h"
- using namespace std;
- int Okrag::licznik = 0;
- Punkt::Punkt(int s, int e)
- {
- int zakres = e - s;
- x = rand() % zakres + s;
- y = rand() % zakres + s;
- }
- Punkt::Punkt(int a, int b, int c)
- {
- x = a;
- y = b;
- }
- Odcinek::Odcinek(int s, int e, int s1, int e1, int c)
- {
- poczatek = new Punkt(s, e, c);
- koniec = new Punkt(s1, e1, c);
- }
- double Odcinek::dlugoscodcinka()
- {
- return sqrt(pow((koniec->x - poczatek->x), 2) + pow((koniec->y - poczatek->y), 2));
- }
- Okrag::Okrag(int a, int b, int prom)
- {
- ++licznik;
- srodek = new Punkt(a, b, promien);
- promien = prom;
- }
- Okrag::Okrag(int s, int e, int s1, int e1)
- {
- ++licznik;
- srodek = new Punkt(s, e);
- int zakres = e1 - s1;
- promien = rand() % zakres + s1;
- }
- int Okrag::getLicznik()
- {
- return licznik;
- }
- Okrag::~Okrag()
- {
- --licznik;
- }
- //main.cpp
- #include <iostream>
- #include <ctime>
- #include <cmath>
- #include "plik.h"
- using namespace std;
- int icos = 0;
- void wypisz(Okrag A, Okrag B)
- {
- //if (przeciecie(A, B) == 1)
- //cout << "(" << A.srodek->x << ", " << A.srodek->y << ", " << A.promien << ") i (" << B.srodek->x << ", " << B.srodek->y << ", " << B.promien << ") - rozlaczne zewnetrznie" << endl;
- //if (przeciecie(A, B) == 2)
- //cout << "(" << A.srodek->x << ", " << A.srodek->y << ", " << A.promien << ") i (" << B.srodek->x << ", " << B.srodek->y << ", " << B.promien << ") - styczne zewnetrznie" << endl;
- if (przeciecie(A, B) == 3)
- {
- icos++;
- cout << "(" << A.srodek->x << ", " << A.srodek->y << ", " << A.promien << ") i (" << B.srodek->x << ", " << B.srodek->y << ", " << B.promien << ") - przecinajace sie" << endl;
- }
- //if (przeciecie(A, B) == 4)
- //cout << "(" << A.srodek->x << ", " << A.srodek->y << ", " << A.promien << ") i (" << B.srodek->x << ", " << B.srodek->y << ", " << B.promien << ") - styczne wewnetrznie" << endl;
- //if (przeciecie(A, B) == 5)
- //cout << "(" << A.srodek->x << ", " << A.srodek->y << ", " << A.promien << ") i (" << B.srodek->x << ", " << B.srodek->y << ", " << B.promien << ") - rozlaczne wewnetrznie" << endl;
- //if (przeciecie(A, B) == 6)
- //cout << "(" << A.srodek->x << ", " << A.srodek->y << ", " << A.promien << ") i (" << B.srodek->x << ", " << B.srodek->y << ", " << B.promien << ") - wspolsrodkowe" << endl;
- else if (icos == 0)
- cout << "Nie ma okregow przecinajacych sie" << endl;
- }
- int przeciecie(Okrag A, Okrag B)
- {
- Odcinek odc(A.srodek->x, A.srodek->y, B.srodek->x, B.srodek->y, 0);
- if ((odc.dlugoscodcinka() < (A.promien + B.promien)) && (odc.dlugoscodcinka()>abs(A.promien - B.promien)))
- return 3;
- else if (odc.dlugoscodcinka() > (A.promien + B.promien))
- return 1;
- else if (odc.dlugoscodcinka() == (A.promien + B.promien))
- return 2;
- else if (odc.dlugoscodcinka() == abs(A.promien - B.promien))
- return 4;
- else if (odc.dlugoscodcinka() < abs(A.promien - B.promien))
- return 5;
- else
- return 6;
- }
- int main()
- {
- srand(time(NULL));
- cout << "licznik: " << Okrag::getLicznik() << endl;
- Okrag A(0,0,5);
- Okrag B(3,4,5);
- wypisz(A, B);
- Okrag** sto1 = new Okrag*[100];
- Okrag** sto2 = new Okrag*[100];
- for (int i = 0; i < 100; i++)
- sto1[i] = new Okrag(-10, 10, 1, 20);
- for (int i = 0; i < 100; i++)
- sto2[i] = new Okrag(-10, 10, 1, 20);
- for (int i = 0; i < 100; i++)
- wypisz(*sto1[i], *sto2[i]);
- for (int i = 0; i < 100; i++)
- {
- delete sto1[i];
- delete sto2[i];
- }
- delete[] sto1;
- delete[] sto2;
- cout << "licznik: " << Okrag::getLicznik() << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement