b) Să se creeze tipul abstract de date (structura) – vector, care se compune dintr-un pointer spre int şi din numărul de elemente

. Să se definească funcţiile de iniţializare, de eliminare a unui vector; de setare/ modificare a dimensiunii vectorului; de acces la elementele vectorului; de calcul a modulului unui vector. În funcţia main să se realizeze adunarea a doi vectori.

Codul sursa:

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

using namespace std;

struct complex {

double re; double im;

void getData();

};

void complex::getData() {

cout<<"La partie reele - "; cin>>re; cout<<"La partie imaginaire - "; cin>>im;

re + nr2.im = nr1.re. complex nr2) { complex dif. complex nr2) { complex sum.im . else cout<<endl<<"Le resultat de la somme est : "<<sum.im = nr1.re .re = nr1.nr2.im.im >= 0 ) cout<<endl<<"Le resultat de la somme est : "<<sum.im + nr2.nr2.} //Functia pentru suma numerelor complexe void suma(complex nr1.im<<"i"<<endl<<endl. sum.im<<"i"<<endl<<endl.re. dif.re = nr1. if ( dif. if (sum. sum. } //Functia pentru diferenta numerelor complexe void diferenta (complex nr1. dif.re<<" "<<sum.im.im >= 0 ) .re<<"+"<<sum.

im + nr1.re = nr1.im))/((nr2.im = nr1.im*nr2.re)+(nr2.im * nr2.im)). imp.re<<""<<dif. prod.re*nr2. complex nr2) { complex imp.im * nr2. if ( prod.im*nr2.re<<" "<<prod.re*nr2.re * nr2.im. prod.im<<"i"<<endl<<endl.im<<"i"<<endl<<endl.cout<<endl<<"Le resultat de la difference est : "<<dif.re. } //Functia pentru impartirea numerelor complexe void impartire(complex nr1.complex nr2){ complex prod.re<<"+"<<prod.nr1.re)+(nr1.im<<"i"<<endl<<endl.im<<"i"<<endl<<endl.re * nr2. } // Functia pentru produsul numerelor complexe void produs(complex nr1.re<<"+"<<dif.im >= 0 ) cout<<endl<<"Le resultat de la multiplicatione est : "<<prod. . else cout<<endl<<"Le resultat de la multiplication est : "<<prod. else cout<<endl<<"Le resultat de la diference est : "<<dif.re .re= ((nr1.

mod1 = sqrt(pow(nr1.complex nr2) { double mod1.re*nr2. if ( imp.im.mod2.re*nr2."<<endl<<endl. mod2 = sqrt(pow(nr2."<<endl<<endl.imp.im= ((nr1.im. if (mod1>mod2) cout<<"Le premier nombre est plus grand que le 2.re)-(nr1. else if(mod1<mod2) cout<<"Le deuxiem nombre est plus grand que la 1.re. "<<endl<<endl.im*nr2. else cout<<endl<<"Le resultat de la division est : "<<imp.re<<" "<<imp.2) + pow(nr2.re.im*nr2.2) + pow(nr1.2)).im<<"i"<<endl<<endl.im))/((nr2. } //Functia pentru compararea si calcularea modulului numerelor complexe void modCompar (complex nr1. cout<<"Le module de 2 nombre est: "<<mod2<<endl<<endl.im)).2)).re)+(nr2. } .re<<"+"<<imp. cout<<"Le module de 1 nombre est: "<<mod1<<endl<<endl.im >= 0 ) cout<<endl<<"Le resultat de la division est : "<<imp. else if(mod1==mod2) cout<<"Les nombres sont egales.im<<"i"<<endl<<endl.

diferenta(nr1. impartire(nr1. cout<<"Le premier nombre : "<<endl.int main () { complex nr1. nr2.nr2).getData().nr2).nr2). nr1. produs(nr1.getData(). cout<<endl<<"Le deuxiem nombre : "<<endl. suma(nr1. } .nr2).nr2. modCompar(nr1.nr2). return 0.

Codul sursa: #include <iostream> #include <stdio. împărţire şi de comparaţie( mai mic. mai mare.h> #include <math. . Să se definească toate funcţiile ca fiind globale. tipul abstract de date pentru reprezentarea numerelor complexe.h> #include <stdlib. scădere. utilizînd structura. de adunare.h> using namespace std. Să se definească funcţia ce calculează şi returnează modulul unui număr complex.La rularea programului se va afisa: а) Să se creeze. înmulţire.) a două numere complexe. etc. Să se definească funcţiile de setare/citire a părţii reale şi imaginare a unui număr complex.

}. void creare(vector *vector. cin>>vector->point[i]. for( int i = 0. i++){ . i < vector->n. int n. i. int n. if( n < 1 ) vector->n = 1. i < vector->n. N'est pas entre le vecteur. n2. int n){ int j = 0. if(vector->point == NULL)cout<<"Erreure. vector->point = new int[n]. float value."<<endl. else vector->n = n. i++) { cout<<"Entrez les elements: "<<++j<<" : ". else if( n > 20) vector->n = 20. else { for(int i = 0. } } void afisare(vector *vector){ cout<<endl<<endl.char option. struct vector { int *point.

vector->n=0. } void modMarime(vector *vector.cout<<vector->point[i]<<" ". i < newSize. } } void sterge(vector *vector) { delete[] vector->point. . newArray = new int[newSize]. vector->point=NULL.int id) { return vector->point[id]. i++) newArray[i] = vector->point[i]. } float getData(vector *vector.int id. int newSize){ int *newArray. } cout<<endl<<endl. } void setData(vector *vector. for (int i = 0.int value) { vector->point[id]=value.

La modification d'un elemente du vecteur"<<endl. 3 .L'affichage du vecteur"<<endl. for(int i = 0.La somme de deux vecteurs"<<endl. } } for(int i = 0.La creation du vecteur"<<endl. i <vector->n. 2 . modul = sqrt(x). i++ ) x+=pow(vector->point[i]. delete[]newArray. } double calcModul(vector *vector) { double modul. for (int i = vector->n. return modul. 4 . vector->n = newSize. } void menu () { system("cls").2). i++) vector->point[i] = newArray[i]. . i++){ cin>>newArray[i]. x = 0. i < newSize. cout<<endl<<endl.if(newSize > vector->n) { cout<<"Entrez les nouvelles elements : "<<endl. i < newSize. cout<<" cout<<" cout<<" cout<<" 1 .

8 . int newSize. .cout<<" cout<<" cout<<" cout<<" 5 . vector2.La modification de dimension du vecteur"<<endl. } int main () { vector vector. creare(&vector. system("pause"). vector. 7 . do { system("cls"). option=getchar().L'eliberation de la memoire"<<endl. cout<<endl<<"Choix : ". menu(). break. cin>>n.point = NULL.Sortie"<<endl. 6 .point = NULL.Le module de vecteur"<<endl. cout<<"\nEntrez la dimension de premier vecteur\n n = ".n). vector2. switch(toupper(option)) { case '1': system("cls").

cout<<"\n Entrez la nouvelle valeur : ". cout<<"Le vecteur modifie est : "<<endl. } else { cout<<"Erreure!"<<endl.case '2': system("cls"). setData(&vector.point != NULL) { afisare(&vector). cout<<"\n L'element avec de indice "<<i<<" est "<<getData(&vector.i-1. break. case '3': system("cls"). system("pause"). system("pause"). afisare(&vector).n). if(vector.value). do { cout<<endl<<"Entrez de id que vous voudrez modifiez : ". } while(i>vector. cin>>i. . afisare(&vector). cin>>value.i-1).

if(vector. :". cin>>n2. creare(&vector.n2). cout<<"La somme de vecteurs est : ". creare(&vector2. case '4': system("cls"). system("pause"). i < n2 && i<n. case'5': system("cls").system("pause").point[i]+vector2. cout<<endl. break. . for (i = 0. cout<<"Vecteur 1 est : ".point[i]<<" ". } break. } cout<<"Entrez la dimension de deuxiem vecteur. i++) cout<<vector. cout<<endl<<"Vecteur 2 est : ".point == NULL) { cout<<"Entrez le premier vecteur. afisare(&vector2). afisare(&vector).n)."<<endl.

n <<" les dates sont perdues. } system("pause"). case '7': ."<<endl. if(vector.newSize).} else { cout<<"Erreure. cout<<"Entrez une nouvelle dimension :". cin>>newSize. break. } system("pause"). break."<<endl. case'6': system("cls").if(vector."<<endl. afisare(&vector).point != NULL) { cout<<endl<<endl<<"Le module de premier vecteur est : "<<calcModul(&vector)<<endl<<endl. } else { cout<<"Erreure.point != NULL) { cout<<"ATANTION! Si vous entrez une dimension plus petite que "<<vector. modMarime(&vector.

default: cout<<endl<<"********** Mauvaise option ************\n". } else { cout<<"Ne sont pas des dates enregistrees. if(vector. } .system("cls"). system("cls"). break. sterge(&vector2). return 0."<<endl<<endl."<<endl. cout<<endl<<" Au tevoir!!!"<<endl<<endl. break. case '8': system("cls"). cout<<"La memoire a ete eliberee.point != NULL) { sterge(&vector). } system("pause"). } } while(toupper(option)!='8').

Programul va afisa: Meniul principal Crearea vectorului: Afisarea vectorului: Modificarea unui element al vectorului: Modificarea marimii vectorului: .

Suma a doi vectori: Modulul vectorului: Eliberarea memoriei: .