//By Debashish Mahapatra
//LICA Sem II.
#include
#include
#include
#define size 10
class vector
{
int v[size];
int *list;
public:
int &operator[](int index)
{
if((index<0) || (index>9))
{
cout<<"Subscirpt out of range !";
}
else return v[index];
}
vector(int a)
{
list=new int [a];
size=a;
for(int i=0;i
list[i]=0;
}
}
~vector(){};
vector()
{
for(int i=0;i
v[i]=0;
}
}
friend ostream & operator<<(ostream &,vector &);
friend istream & operator>>(istream &,vector &);
vector operator*(int val1)
{
vector v2;
for(int i=0;i
v2.v[i]=v[i]*val1;
}
return v2;
}
vector operator+(vector v1)
{
vector v2;
for(int i=0;i
v2.v[i]=v[i]+v1.v[i];
}
return v2;
}
vector operator-(vector v1)
{
vector v2;
for(int i=0;i
v2.v[i]=v[i]-v1.v[i];
}
return v2;
}
vector operator/(vector v1)
{
vector v2;
for(int i=0;i
v2.v[i]=(v[i])/(v1.v[i]);
}
return v2;
}
void operator++()
{
for(int i=0;i
v[i]=++v[i];
}
}
void operator--()
{
for(int i=0;i
v[i]=--v[i];
}
}
};
ostream & operator<<(ostream &tempout, vector &tempvector)
{
for(int i=0;i
tempout<
}
return tempout;
}
istream & operator>>(istream & tempin,vector & tempvector)
{
for(int i=0;i
tempin>>tempvector.v[i];
}
return tempin;
}
void main()
{
vector v1,v2,v3;
int a,b,c,ch;
clrscr();
do
{
cout<<"\n1.<<\n2.>>\n3.+\n4.-\n5.*\n6./\n7.++\n8.--\n9.[]\n10.Exit\n";
cout<
cin>>ch;
switch(ch)
{
case 1: cout<<"\nEnter for first vertex==>\n";
cin>>v1;
cout<<"\nEnter for second vertex==>\n";
cin>>v2;
break;
case 2: cout<<"\nFirst vertex==>\n";
cout<
cout<
case 3: v3=v1+v2;
cout<
case 4: v3=v1-v2;
cout<
case 5: cout<<"\nEnter number to multiply==>\n";
cin>>a;
v3=v1*a;
cout<
cout<
case 6: v3=v2/v1;
cout<
case 7: ++v1;
++v2;
cout<
case 8: --v1;
--v2;
cout<
case 9: cout<<"\nEnter index number for v1==>\n";
cin>>a;
cout<
cin>>b;
cout<
}
}while(ch!=10);
getch();
}
------------------------
RAJ SOLUTION'S
www.rajsolution.com
www.sahinraj.blogspot.com
This comment has been removed by the author.
ReplyDelete