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=0);
- float Max(int &ktora);
- ~Zbiór();
- }
- punkcik.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 = 0)
- {
- }
- float Zbiór::Max(int &ktora)
- {
- float odl;
- float max;
- 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(){
- //Punkt punkt1(5,5);
- //Punkt punkt2(8,8);
- //cout << punkt1.odl(punkt2) << endl;
- //Punkt *x1, *x2;
- //x1 = new Punkt(4, 4);
- //x2 = new Punkt(6, 6);
- //x1->dodaj(*x2);
- //delete x1;
- //delete x2;
- float *ta_x;
- float *ta_y;
- int indeks = 0;
- float odleglosc = 0.0;
- ta_x = new float[3];
- ta_y = new float[3];
- for (int i = 0; i < 3; i++)
- {
- ta_x[i] = i + 1;
- ta_y[i] = i + 2;
- }
- Zbiór punkcik(5, ta_x, ta_y);
- Zbiór nowywektor(punkcik);
- nowywektor.Max(indeks, odl);
- cout << "Indeks: " << indeks << " Odleglosc od 0,0: " << odl << endl;
- delete ta_x;
- delete ta_y;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement