Treceți la conținutul principal

clasa nr complexe

#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#include <math.h>

class complex
{
public:
 float a,b,modul,modulul,unghic,unghis;
 int semnc,semns;

 complex()
 {
  a=0;
  b=0;
  semnc=0;
  semns=0;
 }
 complex(float x,float y)
 {
  a=x;
  b=y;
  semnc=0;
  semns=0;
 }
 complex(float mo,float unc,float uns,int sem1,int sem2)
 {
  modulul=mo;
  unghic=unc;
  unghis=uns;
  semnc=sem1;
  semns=sem2;
 }
 void convert();
 complex operator + (complex);
 complex operator - (complex);
 complex operator * (complex);
 complex operator / (complex);
 void afisare();
 void calc_mod()
 { 
  if(semnc==0)
   modul=(float)sqrt(a*a+b*b);
  else
  {
   convert();
   modul=(float)sqrt(a*a+b*b);
   convert();
  }
 }
 friend FILE * operator >> (FILE *fis1,complex &c)
 {
  float *ex;

  if(c.semnc==0)
  {
   fread(ex,sizeof(c.a),1,fis1);
   c.a=*ex;
   fread(ex,sizeof(c.b),1,fis1);
   c.b=*ex;
  }
  else
  {
   c.convert();
   fread(ex,sizeof(c.a),1,fis1);
   c.a=*ex;
   fread(ex,sizeof(c.b),1,fis1);
   c.b=*ex;
   c.convert();
  }

  return fis1;
 }
 friend FILE * operator << (FILE *fis1,complex c)
 {
  float *ex;

  if(c.semnc==0)
  {
   ex=&c.a;
   fwrite(ex,sizeof(c.a),1,fis1);
   ex=&c.b;
   fwrite(ex,sizeof(c.b),1,fis1);
  }
  else
  {
   c.convert();
   ex=&c.a;
   fwrite(ex,sizeof(c.a),1,fis1);
   ex=&c.b;
   fwrite(ex,sizeof(c.b),1,fis1);
   c.convert();
  }

  return fis1;
 }

 complex conjug()
 {
  complex t;
  
  if(semnc==0)
  {
   t.a=a;
   t.b=-b;
  }
  else
  {
   convert();
   t.a=a;
   t.b=-b;
   convert();
  }

  return t;
 }
};

void complex::convert()
{
 const float pi=3.1415926535897932384626433832795;

 if(semnc==0)
 {
  calc_mod();
  modulul=modul;
  unghic=(float)acos(a/modul);
  unghis=(float)asin(b/modul);
  if(cos(unghic)<0)
  {
   semnc=-1;
   unghic=pi-unghic;
  }
  else
   semnc=1;
  if(sin(unghis)<0)
  {
   semns=-1;
   unghis=pi+unghis;
  }
  else
   semns=1;
 }
 else
 {
  a=(float)(modulul*semnc*cos(unghic));
  b=(float)(modulul*semns*sin(unghis));
  semnc=semns=0;
 }
}

complex complex::operator + (complex y)
{
 complex t;

 if((semnc!=0)&&(y.semnc!=0))
 {
  convert();
  y.convert();
  t.a=a+y.a;
  t.b=b+y.b;
  convert();
  y.convert();
  t.convert();
 }
 else
  if((semnc==0)&&(y.semnc==0))
  {
   t.a=a+y.a;
   t.b=b+y.b;
  }
  else
  {
   printf("\nEROARE ! Formele de reprezentare ale celor doi termeni nu coincid !!!");
   t.a=t.b=0;
  }
 return t;
}

complex complex::operator - (complex y)
{
 complex t;

 if((semnc!=0)&&(y.semnc!=0))
 {
  convert();
  y.convert();
  t.a=a-y.a;
  t.b=b-y.b;
  convert();
  y.convert();
  t.convert();
 }
 else
  if((semnc==0)&&(y.semnc==0))
  {
   t.a=a-y.a;
   t.b=b-y.b;
  }
  else
  {
   printf("\nEROARE ! Formele de reprezentare ale celor doi termeni nu coincid !!!");
   t.a=t.b=0;
  }

 return t;
}

complex complex::operator * (complex y)
{
 complex t;

 if((semnc!=0)&&(y.semnc!=0))
 {
  convert();
  y.convert();
  t.a=a*y.a-b*y.b;
  t.b=a*y.b+b*y.a;
  convert();
  y.convert();
  t.convert();
 }
 else
  if((semnc==0)&&(y.semnc==0))
  {
   t.a=a*y.a-b*y.b;
   t.b=a*y.b+b*y.a;
  }
  else
  {
   printf("\nEROARE ! Formele de reprezentare ale celor doi termeni nu coincid !!!");
   t.a=t.b=0;
  }

 return t;
}

complex complex::operator / (complex y)
{
 complex t;

 if((semnc!=0)&&(y.semnc!=0))
 {
  convert();
  y.convert();
  t.a=(a*y.a+b*y.b)/(y.a*y.a+y.b*y.b);
  t.b=(-a*y.b+b*y.a)/(y.a*y.a+y.b*y.b);
  convert();
  y.convert();
  t.convert();
 }
 else
  if((semnc==0)&&(y.semnc==0))
  {
   t.a=(a*y.a+b*y.b)/(y.a*y.a+y.b*y.b);
   t.b=(-a*y.b+b*y.a)/(y.a*y.a+y.b*y.b);
  }
  else
  {
   printf("\nEROARE ! Formele de reprezentare ale celor doi termeni nu coincid !!!");
   t.a=t.b=0;
  }

 return t;
}

void complex::afisare()
{
 char lp='+';

 if(b<0) lp=' ';
 if(semnc==0)
 {
  if(a>=0.1) //conversia este cu pierderi si a poate fi 0.0...01 in loc de 0
   printf("\n%.1f%c",a,lp);
  else
   printf("\n");
  if(b!=0)
   printf("%.1fi",b);
 }
 else
 {
  char ch1,ch2;

  ch1=' ';
  ch2='+';
  if(semnc==-1)
   ch1='-';
  if(semns==-1)
   ch2='-';
  if(modulul>=0.1)
   printf("\n%.1f*(%ccos(%.1f)%ci*sin(%.1f))",modulul,ch1,unghic,ch2,unghis);
  else
   printf("\n0");
 }
}

void main()
{
 complex z(1,1),t(0,2.5),u;
 FILE *fisier;

 z.afisare();
 t.afisare();
 z=z+t;
 z.afisare();
 u=t;
 u.afisare();
 fisier=fopen("test","wb");
 fisier << u << z;
 fclose(fisier);
 z.afisare();
 fisier=fopen("test","rb");
 fisier >> z >> u;
 fclose(fisier);
 z.afisare();
 u.afisare();
 z=z.conjug();
 z.afisare();
 z.calc_mod();
 printf("\n%.1f",z.modul);
 z.convert();
 z.afisare();
 t.convert();
 t.afisare();
 z=z+t;
 z.afisare();
 z.convert();
 z.afisare();
}

Comentarii

Postări populare de pe acest blog

program principal cpp

#include "clasa.h" #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> #define DELAY 9000000 void delay() { for(long i=0;i<DELAY;i++); } //constructor cu initializare de la tastatura BigInt::BigInt() {char x; signed char t[400]; int i; printf("\nNumarul cu semn "); do s=getche(); while((s!='+')&&(s!='-')); n=0; do {x=getche(); t[n]=x-'0'; n++; } while((x>='0')&&(x<='9')); n--; for(i=0;i<n;i++) nr[i]=t[n-i-1]; } //constructor cu initializare prin parametri BigInt::BigInt(char semn,signed char numar[],int dim) {int i; s=semn; n=dim; for(i=0;i<n;i++) nr[i]=numar[n-i-1]; } //transform un int negativ in pozitiv int BigInt::Pozitiv(int x) {int a,vb; a=0; vb=0; while(vb==0) if((x+a)==0) vb=1; else a=a+1; x=a; return x; } //constructor dintr-un nr int obisnuit BigInt::BigInt(int x) {int i; if(x>=0) s='+'…

NUMERE PRIME ALGORITM C++

// NUMERE PRIME ALGORITM C++//  reediting from scratch //on this page is just the study for a next algoritm for generating the parime nr series like Fibonnaci or ....if possibile

74111121313417374414124343447 if u know the red part you can generate the orange part
1 0 1 111112222 1 1 23

o aplicatie php localitati romania

//APLICATIA SE REFERA LA BAZA DE DATE SIRUTA

//dragtable.js


/* dragtable v1.0 June 26, 2008 Dan Vanderkam, http://danvk.org/dragtable/ http://code.google.com/p/dragtable/ \Bsortabledraggable\B Instructions: - Download this file - Add <script src="dragtable.js"></script> to your HTML. - Add class="draggable" to any table you might like to reorder. - Drag the headers around to reorder them. This is code was based on: - Stuart Langridge's SortTable (kryogenix.org/code/browser/sorttable) - Mike Hall's draggable class (http://www.brainjar.com/dhtml/drag/) - A discussion of permuting table columns on comp.lang.javascript Licensed under the MIT license. */ // Here's the notice from Mike Hall's draggable script: //***************************************************************************** // Do not remove this notice. // // Copyright 2001 by Mike Hall. // See http…