Sie sind auf Seite 1von 3

c++ program #include<iostream.h> #include<conio.h> #include<stdlib.

h> class vector { private: int *array; public: void *operator new(size_t size) { vector *v; cout<<"\nNew operator is invoked"; v=::new vector; v->array=new int[size]; if(!v) { cout<<"\nMemory cannot be allocate"; exit(0); } return v; } void operator delete(void *v) { cout<<"\nopertor delete has been invoked"; vector *vp; vp=(vector *)v; delete (int *)vp->array; ::delete v; } void read(int); int max(int); int sum(int); }; void vector::read(int a) { int i; Page 1

c++ program for(i=0;i<a;i++) { cout<<"\nEnter the element"<<i+1<<"\n"; cin>>array[i]; } } int vector::max(int a) { int max=0,i; for(i=0;i<a;i++) if(array[i]>max) max=array[i]; return max; } int vector::sum(int a) { int total=0,i; for(i=0;i<a;i++) total=total+array[i]; return total; } void main() { int a; clrscr(); cout<<"\nEnter the size of the vector"; cin>>a; vector *vec=new vector; cout<<"\nEnter the vector element:"; vec->read(a); cout<<"\nThe max value is:"; cout<<vec->max(a); cout<<"\nThe total value is:"; cout<<vec->sum(a); delete vec; getch(); Page 2

c++ program }

Page 3

Das könnte Ihnen auch gefallen