Advertisement
Guest User

asd

a guest
Jan 23rd, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. struct Complesso
  6. {
  7.     double Re;
  8.     double Imm;
  9. };
  10. void leggiComplex(Complesso &);
  11. double moduloComplex(const Complesso &);
  12. Complesso sommaComplex(const Complesso, const Complesso);
  13. Complesso prodottoComplex(const Complesso, const Complesso);
  14. void stampaComplex(const Complesso);
  15. const int NMAX=100;
  16. typedef Complesso Vettore[NMAX];
  17. void LeggiElementi(Vettore ,int &);
  18. void StampaVettore(const Vettore,const int &);
  19. int main(int argc, char** argv) {
  20.    
  21.  
  22. Complesso c1, c2, somma, prodotto;
  23. //acquisizione dati
  24. cout << "\n Lettura di C1: ";
  25. leggiComplex(c1);
  26. cout << "\n Lettura di C2: ";
  27. leggiComplex(c2);
  28. //modulo
  29. cout << "\n Il modulo di C1: " << moduloComplex(c1);
  30. cout << "\n Il modulo di C2: " << moduloComplex(c2);
  31. //somma
  32. somma=sommaComplex(c1,c2);
  33. cout << "\n somma: ";
  34. stampaComplex(somma);
  35. //prodotto
  36. prodotto=prodottoComplex(c1,c2);
  37. cout << "\n prodotto: ";
  38. stampaComplex(prodotto);
  39.  
  40. system("PAUSE");
  41. return 0; }
  42.  
  43. void leggiComplex(Complesso & c){
  44.    
  45.     cin>>c.Re;
  46.     cin>>c.Imm;
  47. }
  48.  
  49. double moduloComplex(const Complesso & c){
  50.     return sqrt(c.Re*c.Re+c.Imm*c.Imm);
  51. }
  52.  
  53. Complesso sommaComplex(const Complesso c1, const Complesso c2){
  54.     Complesso c;
  55.     c.Re=c1.Re+c2.Re;
  56.     c.Imm=c1.Imm+c2.Imm;
  57.     return c;
  58. }
  59.  
  60. Complesso prodottoComplex(const Complesso c1, const Complesso c2){
  61.     Complesso c;
  62.     c.Re=c1.Re*c2.Re;
  63.     c.Imm=c1.Imm*c2.Imm;
  64.     return c;
  65. }
  66.  
  67. void stampaComplex(const Complesso c){
  68.    
  69.     cout<<"("<<c.Re<<";"<<c.Imm<<")";
  70. }
  71.  
  72. void LeggiElementi(Vettore Vet,int & nelem){
  73.  
  74. do{
  75.  
  76.     cout<<"Inserisci in numero di elementi del vettore di massimo "<<NMAX<<" \n ";
  77.     cin>>nelem;
  78. while(nelem>NMAX || nelem<=0);
  79. }
  80. for (int i=0;i<nelem;i++)
  81.     leggiComplex(Vet[i]);
  82.    
  83. }
  84.  
  85. void StampaVettore(Vettore Vet, const int & nelem){
  86.    
  87.     for(i=0;i<nelem;i++)
  88.     stampaComplex(Vet[i]);
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement