Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //h
- #ifndef L4P2_H
- #define L4P2_H
- #include<iostream>
- using namespace std;
- class Complex
- {
- int re, im;
- public:
- Complex()
- {
- re=0;
- im=0;
- }
- Complex(int re, int im)
- {
- this->re = re;
- this->im = im;
- }
- int Complex::egal(Complex c2)
- {
- if((this->re==c2.re)&&(this->im==c2.im))
- return 1;
- else
- return 0;
- }
- void Complex::citire()
- {
- cout<<"Re=";
- cin>>this->re;
- cout<<"\nIm=";
- cin>>this->im;
- }
- Complex(const Complex &c)
- {
- this->re = c.re;
- this->im = c.im;
- }
- void Complex::afisare()
- {
- cout<<"("<<this->re<<","<<this->im<<")"<<endl;
- }
- };
- class MultimeComplexe
- {
- int n,dim;
- Complex *v;
- public:
- void MultimeComplexe::init()
- {
- this->n=0;
- this->dim=20;
- this->v=new Complex[dim];
- }
- void MultimeComplexe::adauga(Complex c2)
- {
- int i,c=1;
- for(i=0;i<this->n;i++)
- if(v[i].egal(c2))
- c=0;
- if(c==1)
- {
- v[n]=c2;
- n++;
- }
- }
- void MultimeComplexe::extrage(Complex c2)
- {
- int i;
- for(i=0;i<this->n;i++)
- if(v[i].egal(c2))
- {
- for(i;i<this->n-1;i++)
- v[i]=v[i+1];
- n--;
- }
- }
- void MultimeComplexe::afisare()
- {
- int i;
- for(i=0;i<this->n;i++)
- {
- v[i].afisare();
- cout<<" ";
- }
- }
- };
- #endif
- //main
- #include "l4p2.h"
- int main()
- {
- cout<<"dfasdf";
- MultimeComplexe m;
- Complex c1(2,3), c2(3,4), c3(2,-1);
- m.init();
- m.adauga(c1);
- m.adauga(c2);
- m.afisare();
- m.extrage(c1);
- m.extrage(c3);
- m.afisare();
- m.adauga(c3);
- m.adauga(c3);
- m.afisare();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement