Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- struct Complesso
- {
- double Re;
- double Imm;
- };
- void leggiComplex(Complesso &);
- double moduloComplex(const Complesso &);
- Complesso sommaComplex(const Complesso, const Complesso);
- Complesso prodottoComplex(const Complesso, const Complesso);
- void stampaComplex(const Complesso);
- const int NMAX=100;
- typedef Complesso Vettore[NMAX];
- void LeggiElementi(Vettore ,int &);
- void StampaVettore(const Vettore,const int &);
- int main(int argc, char** argv) {
- Complesso c1, c2, somma, prodotto;
- //acquisizione dati
- cout << "\n Lettura di C1: ";
- leggiComplex(c1);
- cout << "\n Lettura di C2: ";
- leggiComplex(c2);
- //modulo
- cout << "\n Il modulo di C1: " << moduloComplex(c1);
- cout << "\n Il modulo di C2: " << moduloComplex(c2);
- //somma
- somma=sommaComplex(c1,c2);
- cout << "\n somma: ";
- stampaComplex(somma);
- //prodotto
- prodotto=prodottoComplex(c1,c2);
- cout << "\n prodotto: ";
- stampaComplex(prodotto);
- system("PAUSE");
- return 0; }
- void leggiComplex(Complesso & c){
- cin>>c.Re;
- cin>>c.Imm;
- }
- double moduloComplex(const Complesso & c){
- return sqrt(c.Re*c.Re+c.Imm*c.Imm);
- }
- Complesso sommaComplex(const Complesso c1, const Complesso c2){
- Complesso c;
- c.Re=c1.Re+c2.Re;
- c.Imm=c1.Imm+c2.Imm;
- return c;
- }
- Complesso prodottoComplex(const Complesso c1, const Complesso c2){
- Complesso c;
- c.Re=c1.Re*c2.Re;
- c.Imm=c1.Imm*c2.Imm;
- return c;
- }
- void stampaComplex(const Complesso c){
- cout<<"("<<c.Re<<";"<<c.Imm<<")";
- }
- void LeggiElementi(Vettore Vet,int & nelem){
- do{
- cout<<"Inserisci in numero di elementi del vettore di massimo "<<NMAX<<" \n ";
- cin>>nelem;
- while(nelem>NMAX || nelem<=0);
- }
- for (int i=0;i<nelem;i++)
- leggiComplex(Vet[i]);
- }
- void StampaVettore(Vettore Vet, const int & nelem){
- for(i=0;i<nelem;i++)
- stampaComplex(Vet[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement