Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Punkt{
- public:
- double x;
- double y;
- };
- class Wektor{
- private:
- double x;
- double y;
- Punkt s,k;
- public:
- friend ostream & operator << ( ostream &os, const Wektor &w);
- Wektor (double x , double y , Punkt s){
- setX(x);
- setY(y);
- setS(s);
- obliczK();
- }
- Wektor() {
- this->x=0;
- this->y=0;
- this->s.x=0;
- this->s.y=0;
- obliczK();
- }
- Wektor (const Wektor &w){
- this->x=w.x;
- this->y=w.y;
- this->s=w.s;
- this->k=w.k;
- obliczK();
- }
- void setX(int x){
- this->x=x;
- }
- void setY(int y){
- this->y=y;
- }
- void setS(Punkt s){
- this->s=s;
- }
- double getY(){
- return y;
- }
- double getX(){
- return x;
- }
- Punkt getS(){
- return s;
- }
- Punkt getK(){
- return k;
- }
- void obliczK(){
- Punkt k;
- this->k=k;
- this->k.x=this->s.x + this->x;
- this->k.y=this->s.y + this->y;
- }
- void show(){
- cout<<"Wektor o poczatku w punkcie P["<<this->s.x<<","<<this->s.y<<"] i o kierunku x="<<getX()<<", y="<<getY()<<endl;
- }
- void toString(){
- cout<<"Wektor o poczatku w punkcie P["<<this->s.x<<","<<this->s.y<<"] i o kierunku x="<<getX()<<", y="<<getY()<<endl;
- }
- Wektor operator + (const Wektor &w){
- Wektor tmp(x+w.x,y+w.y,s);
- return tmp;
- }
- Wektor operator - (void){
- Wektor tmp(-x , -y, s);
- return tmp;
- }
- };
- int main(){
- Punkt pktS;
- pktS.x = 1;
- pktS.y = 2;
- Wektor wek(2 , 3, pktS);
- Wektor wek1(wek);
- Wektor wek2;
- wek.show();
- wek1.show();
- wek2.show();
- Wektor wek3;
- wek3 = wek2 + wek;
- wek3.toString();
- wek3 = -wek3;
- wek3.toString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement