Question 3.

Posted: August 29, 2012 in Lab 5
#include<iostream.h>
class vector
{
int a[50],n;
public:
vector(){}

void getdata()
{
cout<<"Enter n=";
cin>>n;
cout<<"\nEnter Vector=\n";
for(int i=0;i<n;i++)
{
cin>>a[i];
}
}
void show()
{
cout<<"n="<<n;

cout<<"\nVector is=\n";
cout<<"(";
for(int i=0;i<n;i++)
{
cout<<a[i];
if(i!=n-1)
cout<<",";
}
cout<<")";
}

add(vector v1,vector v2)
{
vector v;
for(int i=0;i<v1.n;i++)
{
a[i]=v1.a[i]+v2.a[i];
}
n=v1.n;
}
};
int main()
{
vector v1,v2,v;
cout<<"Create 2 Vectors \n";
v1.getdata();
v2.getdata();

cout<<"Adding 2 vectors \n";
v.add(v1,v2);

cout<<"\nDisplaying Vector \n";
v.show();
return 0;
}
Advertisements

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