Advertisement
Adytzu04

l4p2

Nov 5th, 2012
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. //h
  2.  
  3. #ifndef L4P2_H
  4. #define L4P2_H
  5.  
  6. #include<iostream>
  7.  
  8. using namespace std;
  9.  
  10. class Complex
  11. {
  12.       int re, im;
  13. public:
  14.         Complex()
  15.         {
  16.                 re=0;
  17.                 im=0;
  18.         }
  19.  
  20.         Complex(int re, int im)
  21.         {
  22.                 this->re = re;
  23.                 this->im = im;
  24.         }
  25.  
  26.         int Complex::egal(Complex c2)
  27.         {      
  28.                 if((this->re==c2.re)&&(this->im==c2.im))
  29.                         return 1;
  30.                 else
  31.                         return 0;
  32.         }
  33.  
  34.  
  35.         void Complex::citire()
  36.         {              
  37.  
  38.                 cout<<"Re=";
  39.                 cin>>this->re;
  40.                 cout<<"\nIm=";
  41.                 cin>>this->im;
  42.         }
  43.        
  44.         Complex(const Complex &c)
  45.         {
  46.             this->re = c.re;
  47.             this->im = c.im;
  48.         }
  49.  
  50.         void Complex::afisare()
  51.         {
  52.             cout<<"("<<this->re<<","<<this->im<<")"<<endl;
  53.         }
  54.  
  55. };
  56.  
  57. class MultimeComplexe
  58. {
  59.     int n,dim;
  60.     Complex *v;
  61.  
  62. public:
  63.  
  64.     void MultimeComplexe::init()
  65.     {  
  66.         this->n=0;
  67.         this->dim=20;
  68.         this->v=new Complex[dim];
  69.  
  70.     }
  71.  
  72.     void MultimeComplexe::adauga(Complex c2)
  73.     {
  74.         int i,c=1;
  75.  
  76.         for(i=0;i<this->n;i++)
  77.             if(v[i].egal(c2))
  78.                 c=0;
  79.  
  80.         if(c==1)
  81.         {
  82.             v[n]=c2;
  83.             n++;
  84.                
  85.         }
  86.  
  87.     }
  88.  
  89.     void MultimeComplexe::extrage(Complex c2)
  90.     {
  91.         int i;
  92.  
  93.         for(i=0;i<this->n;i++)
  94.             if(v[i].egal(c2))
  95.             {
  96.                 for(i;i<this->n-1;i++)
  97.                     v[i]=v[i+1];
  98.                     n--;
  99.             }
  100.  
  101.     }
  102.  
  103.     void MultimeComplexe::afisare()
  104.     {
  105.         int i;
  106.         for(i=0;i<this->n;i++)
  107.         {
  108.             v[i].afisare();
  109.             cout<<" ";
  110.         }
  111.     }
  112.  
  113. };
  114. #endif
  115.  
  116. //main
  117. #include "l4p2.h"
  118.  
  119. int main()
  120. {
  121.    cout<<"dfasdf";
  122.     MultimeComplexe m;
  123.     Complex c1(2,3), c2(3,4), c3(2,-1);
  124.     m.init();
  125.     m.adauga(c1);
  126.     m.adauga(c2);
  127.     m.afisare();
  128.     m.extrage(c1);
  129.     m.extrage(c3);
  130.     m.afisare();
  131.     m.adauga(c3);
  132.     m.adauga(c3);
  133.     m.afisare();
  134.  
  135. return 0;
  136.  
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement