THIS IS A VERY IMPORTANT PROBLEM PLEASE MAKE SURE YOU UNDERSTAND IT COMPLETELY....
--------------------------------------------------------------------------------------------------------------------------
DETAILED EXPLAINATION : HERE
========================================================================
istream& operator>>(istream& in,vector& v)
{
in>>v.num;
int i;
for(i=0;i<v.num;i++)
{in>>v.ele[i];
}
return in;
}
ostream& operator<<(ostream& in,vector& v)
{
int i;
for(i=0;i<v.num;i++)
in<<v.ele[i]<<endl;
return in;
}
vector vector::operator+(vector& v)
{
vector temp;
if(num>v.num)
temp.num=num;
else
temp.num=v.num;
for(int i=0;i<num;i++)
{
temp.ele[i]=ele[i]+v.ele[i];
}
return temp;
}
vector vector::operator-(vector& v)
{
vector temp;
if(num>v.num)
temp.num=num;
else
temp.num=v.num;
for(int i=0;i<num;i++)
{
temp.ele[i]=ele[i]-v.ele[i];
}
return temp;
}
int vector::operator[](int i)
{
return ele[i-1];
}
--------------------------------------------------------------------------------------------------------------------------
DETAILED EXPLAINATION : HERE
========================================================================
istream& operator>>(istream& in,vector& v)
{
in>>v.num;
int i;
for(i=0;i<v.num;i++)
{in>>v.ele[i];
}
return in;
}
ostream& operator<<(ostream& in,vector& v)
{
int i;
for(i=0;i<v.num;i++)
in<<v.ele[i]<<endl;
return in;
}
vector vector::operator+(vector& v)
{
vector temp;
if(num>v.num)
temp.num=num;
else
temp.num=v.num;
for(int i=0;i<num;i++)
{
temp.ele[i]=ele[i]+v.ele[i];
}
return temp;
}
vector vector::operator-(vector& v)
{
vector temp;
if(num>v.num)
temp.num=num;
else
temp.num=v.num;
for(int i=0;i<num;i++)
{
temp.ele[i]=ele[i]-v.ele[i];
}
return temp;
}
int vector::operator[](int i)
{
return ele[i-1];
}
No comments:
Post a Comment