Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////MAIN.CPP//////////////
- #include <iostream>
- #include <math.h>
- #include "header.h"
- using namespace std;
- ostream &operator <<(ostream &wyjscie, const Punkt &o_)
- {
- wyjscie << "x= " << o_.x << " y=" << o_.y << endl;
- return wyjscie;
- }
- int main() {
- cout<<"Sprawdzanie operatora +"<<endl;
- Punkt dod1(1,1);
- Punkt dod2(3,2);
- Punkt dodw;
- dodw=dod1+dod2;
- cout<<"Wynik dodawania punktu ("<<dod1.x<<","<<dod1.y<<") oraz ("<<dod2.x<<","<<dod2.y<<") to ("<<dodw.x<<","<<dodw.y<<")";
- cout<<endl<<endl<<"Sprawdzenie operatora == "<<endl;
- Punkt spr1(1,3);
- Punkt spr2(1,7);
- if (spr1==spr2){
- cout<<"Porownane punkty sa rowne!"<<endl<<endl;
- }else{
- cout<<"Porownane punkty nie sa rowne!"<<endl<<endl;
- }
- cout<<"Sprawdzenie operatora = "<<endl;
- Punkt rown1(3,12);
- Punkt rown2(11,2);
- cout<<"Podstawiam w miejsce punktu pierwszego ("<<rown1.x<<","<<rown1.y<<") punkt ("<<rown2.x<<","<<rown2.y<<")"<<endl;
- rown1=rown2;
- cout<<"Pierwszy punkt to teraz ("<<rown1.x<<","<<rown1.y<<")"<<endl<<endl;
- cout<<"Sprawdzenie operatora +="<<endl;
- Punkt pr1(3,2);
- Punkt pr2(1,1);
- cout<<"Wynik operatora += z punktow ("<<pr1.x<<","<<pr1.y<<") oraz ("<<pr2.x<<","<<pr2.y;
- pr1+=pr2;
- cout<<") to ("<<pr1.x<<","<<pr1.y<<")";
- /*
- float *ta_x;
- float *ta_y;
- int indeks = 0;
- float odleglosc = 0.0;
- ta_x = new float[5];
- ta_y = new float[5];
- for (int i = 0; i < 5; i++)
- {
- ta_x[i] = i + 2;
- ta_y[i] = i + 3;
- }
- Vector punkcik(5, ta_x, ta_y);
- Vector nowywektor(punkcik);
- nowywektor.min(indeks, odleglosc);
- cout << "Indeks: " << indeks << " Odleglosc od 0,0: " << odleglosc << endl;
- */
- return 0;
- }
- //////////////header.h//////////////
- #include <iostream>
- #include <stdio.h>
- #include <ctype.h>
- using namespace std;
- class Punkt{
- friend class Vector;
- friend ostream &operator <<(ostream &wyjscie, const Punkt &o_);
- public: int x, y;
- Punkt(){
- x=0;
- y=0;
- }
- Punkt(int a, int b){
- x=a;
- y=b;
- }
- Punkt &operator +(Punkt &p){
- Punkt pp;
- pp.x= x+p.x;
- pp.y= y+p.y;
- return pp;
- }
- bool operator ==(Punkt &p){
- if ((x==p.x) && (y==p.y)){
- return true;
- }else
- return false;
- }
- Punkt &operator =(Punkt &p){
- x=p.x;
- y=p.y;
- }
- Punkt &operator +=(Punkt &p){
- x=x+p.x;
- y=y+p.y;
- }
- };
- class Vector
- {
- int ile;
- Punkt *wp;
- public:
- //konstruktor
- Vector(int il, float *t_x, float *t_y)
- {
- ile = il;
- wp = new Punkt[ile];
- for (int i = 0; i < ile; i++)
- {
- wp[i].x = t_x[i];
- }
- for (int i = 0; i < ile; i++)
- {
- wp[i].y = t_y[i];
- }
- }
- Vector(Vector &new_w)
- {
- ile = new_w.ile;
- wp = new Punkt[ile];
- for (int i = 0; i < ile; i++)
- {
- wp[i].x = new_w.wp[i].x;
- wp[i].y = new_w.wp[i].y;
- }
- }
- //operatory
- //metody
- void min(int &indeks, float &mini)
- {
- float odleglosc = 0.0;
- for (int i = 0; i < (this->ile); i++)
- {
- odleglosc = sqrt(((this->wp[i].x)*(this->wp[i].x)) + ((this->wp[i].y)*(this->wp[i].y)));
- if (i==0)
- {
- mini = odleglosc;
- indeks = i;
- }
- else
- if (odleglosc < mini)
- {
- mini = odleglosc;
- indeks = i;
- }
- }
- }
- //destruktor
- ~Vector()
- {
- delete wp;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement