Question 2.

Posted: August 29, 2012 in Lab 5
#include<iostream.h>
class vector
{
int a[25],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<<"\nVector is=\n";
cout<<"(";
for(int i=0;i<n;i++)
{
cout<<a[i];
if(i!=n-1)
cout<<",";
}
cout<<")";
}
void modify()
{
int num;
cout<<"\nWhich element you want to modify ?\n";
cin>>num;
cout<<"Enter Element=";
cin>>a[num-1];
cout<<"\nSuccessfull \n";
}
void scaler()
{
int sc;
cout<<"\nEnter Scaler Element=";
cin>>sc;
for(int i=0;i<n;i++)
{
a[i]=sc*a[i];
}
}
};

int main()
{
vector v;
cout<<"Create a Vector\n";
v.getdata();

cout<<"Modify Value of Given Element\n";
v.modify();

cout<<"Multiply Vector by a Scaler\n";
v.scaler();

cout<<"Displaying 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