16. Create a class vector that contains series of n numbers.Perform the Pre-Increment and Post- Decrement operations on a vector object using operator overloading.(Use friend Function).


#include<iostream.h>
#include<conio.h>
const n=5;
class vector
{
public:int v[n];
public:
void get();
public: friend void operator++(vector&);
friend void operator–(vector&,int);
void disp();
};
void vector::get()
{
for(int i=0;i<n;i++)
{
cin>>v[i];
}
}
void operator++(vector &t)
{
for(int i=0;i<n;i++)
{
++t.v[i];
}
}
void operator–(vector &t,int)
{
for(int i=0;i<n;i++)
{
t.v[i]–;
}
}
void vector::disp()
{
cout<<“\n\nVector Series: “;
for(int i=0;i<n;i++)
{
cout<<v[i]<<“\t”;
}
cout<<“\n”;
}
void main()
{
int j;
vector vect;
clrscr();
cout<<“\nEnter the Vector Element: \n”;
vect.get();
vect.disp();
++vect;
cout<<“\n\tAfter Pre-Increment \n”;
vect.disp();
vect–;
cout<<“\n\tAfter Post-Decrement \n”;
vect.disp();
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s