Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //punkt.h
- #include <iostream>
- #include <math.h>
- using namespace std;
- class Punkt
- {
- friend class Zbiór;
- float x, y;
- public:
- Punkt(float x_ = 0, float y_ = 0)
- {
- x = x_;
- y = y_;
- }
- double odl(Punkt &p);
- void dodaj(Punkt &p){
- x += p.x;
- y += p.y;
- }
- ~Punkt()
- {
- cout<<"Destruktor"<<endl;
- }
- };
- class Zbiór
- {
- Punkt *p;
- int ile;
- public:
- Zbiór(float *t_x, float *t_y, int roz);
- Zbiór(Zbiór &k);
- Zbiór(int roz);
- void Max(int &ktora, float &max);
- ~Zbiór();
- };
- //punkt.cpp
- #include "punkt.h"
- #include <math.h>
- using namespace std;
- double Punkt::odl(Punkt &p){
- double odl;
- odl = sqrt((p.x - x) * (p.x - x) + (p.y - y) * (p.y - y));
- return odl;
- }
- Zbiór::Zbiór(float *t_x, float *t_y, int roz)
- {
- ile = roz;
- p = new Punkt[ile];
- for(int i=0; i<ile; i++)
- {
- p[i].x = t_x[i];
- p[i].y = t_y[i];
- }
- }
- Zbiór::Zbiór(Zbiór &nowy)
- {
- ile = nowy.ile;
- p = new Punkt[ile];
- for (int i=0; i<ile; i++)
- {
- p[i].x = nowy.p[i].x;
- p[i].y = nowy.p[i].y;
- }
- }
- Zbiór::Zbiór(int roz):ile(roz)
- {
- p = new Punkt[ile];
- }
- void Zbiór::Max(int &ktora, float &max)
- {
- float odl;
- for(int i; i<ile; i++)
- {
- odl = sqrt((this -> p[i].x) * (this -> p[i].x) + (this -> p[i].y) * (this -> p[i].y));
- if(i==0)
- {
- max = odl;
- ktora = i;
- }
- else
- if(odl > max)
- {
- max = odl;
- ktora = i;
- }
- }
- }
- //main.cpp
- #include "punkt.h"
- using namespace std;
- int main(){
- // p1(8, 8);
- //Punkt p2(9, 9);
- //cout << p1.odleglosc(p2) << endl;
- //Punkt *x1, *x2;
- //x1 = new Punkt(2, 2);
- //x2 = new Punkt(5, 5);
- //x1->dodawanie(*x2);
- //delete x1;
- //delete x2;
- float *t_x;
- float *t_y;
- int index = 0;
- float odlg = 0.0;
- t_x = new float[3];
- t_y = new float[3];
- for (int i = 0; i < 3; i++)
- {
- t_x[i] = i + 1;
- t_y[i] = i + 2;
- }
- Zbiór p1(t_x, t_y, 6);
- Zbiór w1(p1);
- w1.Max(index, odlg);
- cout << "Indeks: " << index << " Odleglosc od 0,0: " << odlg << endl;
- delete t_x;
- delete t_y;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement