//#include "stdafx.h" #include #include #include #include template class Vector { TIP* pv; int dim; public: Vector() {pv=NULL;dim=0;} //constructori de clasa Vector(int); Vector(TIP,int); Vector(TIP*,int); Vector(Vector &); //constr.de copiere ~Vector() {delete[] pv;} //destructor Vector& operator=(Vector); int operator!() {if(dim) return 1; //test vector vid else return 0;} Vector operator+(Vector); //concatenare a 2 vectori Vector& operator+=(Vector); int operator==(Vector); //test de egalitate a 2 vectori operator TIP() {return pv[0];} //cast catre TIP TIP& operator[](int i) {return pv[i];} //referirea unui element bool cresc(TIP,TIP); bool desc(TIP,TIP); void comuta(TIP&a,TIP&b) {TIP aux;aux=a;a=b;b=aux;} void sortare(bool(*sens)(TIP,TIP)); //sortarea dupa o directie primita ca pointer de functie int regresie(Vector&,Vector&,double&,double&); //coeficientii dreptei de regresie friend ostream& operator<<(ostream&,Vector); friend istream& operator>>(istream&,Vector&); friend ifstream& operator>>(ifstream&,Vector&); }; templateVector::Vector(int n) { pv=new TIP[n]; dim=n; } templateVector::Vector(TIP in,int n) { pv=new TIP[n]; dim=n; for(int i=0;iVector::Vector(TIP*ini,int n) { pv=new TIP[n]; dim=n; for(int i=0;iVector::Vector(Vector &ve) { if(ve.pv) { dim=ve.dim; pv=new TIP[dim]; for(int i=0;iVector& Vector::operator=(Vector ve) {if((pv!=ve.pv)&&(ve.pv!=NULL)) {delete[] pv; dim=ve.dim; pv=new TIP[dim]; for(int i=0;iVector Vector::operator+(Vector ve) { Vector re(dim+ve.dim); re.dim=dim+ve.dim; re.pv=new TIP[re.dim]; if(pv==NULL) re=ve; else if(ve.pv==NULL) re=*this; else { for(int i=0;iVector& Vector::operator+=(Vector ve) { if(ve.dim==1) { Vector aux(dim); aux=*this; *this=*this+ve; return *this; } } templateint Vector::operator==(Vector v) {if(dim!=v.dim) return 0; else { int cont=0; for(int i=0;ibool cresc(TIP a,TIP b) { return abool desc(TIP a,TIP b) { return a>b?1:0; } templatevoid Vector::sortare(bool(*sens)(TIP,TIP)) { int i,j; for(i=0;iint Vector::regresie(Vector&v1,Vector&v2,double&a0,double&a1) { double mx,my; mx=my=0; for(int i=0;iostream& operator<<(ostream& ies,Vector v) { if((v.dim!=0)&&(v.pv!=NULL)) { ies<<"dim.vect: ";ies<istream& operator>>(istream& intr,Vector &v) { if(v.dim==0) {cout<<"dim.vect: ";intr>>v.dim; v.pv=new TIP[v.dim]; for(int i=0;i>v.pv[i]; return intr; } else { for(int i=0;i>v.pv[i]; return intr; } } templateifstream& operator>>(ifstream& intr,Vector& v) { //if((v.dim!=0)&&(v.pv!=NULL)) for(int i=0;i>v.pv[i]; return intr; } int main(int argc, char* argv[]) { Vectorvi(3,2),ve,vu,va; cout<>ve; cout<<"Deci vectorul citit este: "<vf(1),vh(2),vp,vl,vr(1,1),vg(v,3),vd,vk; cout<<"Introduceti vectorul cu variabila cauza:"<>vp; cout<<"Introduceti vectorul cu variabila efect:"<>vd; int er,ereg; double re0,re1; er=vp.regresie(vp,vd,re0,re1); if(er) cout<<"Dreapta de regresie este Y^="<vo; vk=vr+vo+vp; vp+=vr; cout<<"Op. += ptr.vect.cauza si un vect.de 1 elem ";cout<>vr; cout<>vg; cout<