#include
#include
#include
const int No=5;
class List
{
private:
int n;
int *array;
public:
List(int i)
{
array=new int[i];
n=i;
}
~List()
{
delete array;
}
void Init(int al,...);
void Show();
void Add(List &v1,List &v2);
int Inner(List &v2);
void Scale(int x);
};
void List::Init(int al,...)
{
va_list argp;
va_start(argp,al);
array[0]=al;
for(int i=1;i array[i]=va_arg(argp,int);
va_end(argp);
}
void List::Show()
{
cout<<"(";
for(int i=0;i cout< cout<<")"< }
void List:: Add(List &v1,List &v2)
{
for(int i=0;i array[i]=v1.array[i]+v2.array[i];
}
int List::Inner(List &v2)
{
int result=0;
for(int i=0;i result+=array[i]*v2.array[i];
return(result);
}
void List::Scale(int x)
{
for(int i=0;i array[i]*=x;
}
main()
{
List vect1(No),vect2(No),vect3(No);
int InnerProduct;
vect1.Init(2,4,6,8,10);
vect2.Init(1,3,5,7,9);
int m=4;
cout<<"vect1=";
vect1.Show();
cout<<"vect2=";
vect2.Show();
vect3.Add(vect1,vect2);
cout<<"vect3=vect1+vect2=";
vect3.Show();
InnerProduct=vect1.Inner(vect2);
cout<<"Inner product of vect1&vect2 is:"< vect3.Scale(m);
cout<<"vect3*"< vect3.Show();
return 0;
}
vect1=(2,4,6,8,10,)
vect2=(1,3,5,7,9,)
vect3=vect1+vect2=(3,7,11,15,19,)
Inner product of vect1&vect2 is:190
vect3*4=(12,28,44,60,76,)