Program:
#include<iostream>
using namespace std;
class vector
{
int a[20],i,j,k,n,s,p;
public:
void creat();
void modify();
void mult();
void display();
};
void vector::creat()
{
cout<<"\nEnter number of elements:";
cin>>n;
cout<<"\nEnter elements:";
for(i=1;i<=n;++i)
cin>>a[i];
}
void vector::display()
{
cout<<"\nVector is:";
for(i=1;i<=n;++i)
cout<<a[i]<<"\t";
}
void vector::mult()
{
cout<<"\nEnter the scalar to be multiplied:";
cin>>s;
for(i=1;i<=n;++i)
a[i]=a[i]*s;
cout<<"\nVector after multiplication";
display();
}
void vector::modify()
{
cout<<"\nEnter no. to be inserted:";
cin>>j;
cout<<"\n Enter position to insert:";
cin>>p;
for(i=n;i>=p;--i)
a[i+1]=a[i];
a[i+1]=j;
n++;
}
int main()
{
vector ob1;
int ch,k=1;
while(k==1)
{
cout<<"\nMENU\n\n1.TO CREATE VECTOR\n2.TO DISPLAY\n3.TO MULTIPLY BY A SCALAR\n4.TO INSERT TO A POSITION\n5.EXIT\nENTER YOUR CHOICE";
cin>>ch;
switch(ch)
{
case 1:ob1.creat();
break;
case 2:ob1.display();
break;
case 3: ob1.mult();
break;
case 4:ob1.modify();
break;
case 5:k=0;
break;
}
}
return 0;
}
#include<iostream>
using namespace std;
class vector
{
int a[20],i,j,k,n,s,p;
public:
void creat();
void modify();
void mult();
void display();
};
void vector::creat()
{
cout<<"\nEnter number of elements:";
cin>>n;
cout<<"\nEnter elements:";
for(i=1;i<=n;++i)
cin>>a[i];
}
void vector::display()
{
cout<<"\nVector is:";
for(i=1;i<=n;++i)
cout<<a[i]<<"\t";
}
void vector::mult()
{
cout<<"\nEnter the scalar to be multiplied:";
cin>>s;
for(i=1;i<=n;++i)
a[i]=a[i]*s;
cout<<"\nVector after multiplication";
display();
}
void vector::modify()
{
cout<<"\nEnter no. to be inserted:";
cin>>j;
cout<<"\n Enter position to insert:";
cin>>p;
for(i=n;i>=p;--i)
a[i+1]=a[i];
a[i+1]=j;
n++;
}
int main()
{
vector ob1;
int ch,k=1;
while(k==1)
{
cout<<"\nMENU\n\n1.TO CREATE VECTOR\n2.TO DISPLAY\n3.TO MULTIPLY BY A SCALAR\n4.TO INSERT TO A POSITION\n5.EXIT\nENTER YOUR CHOICE";
cin>>ch;
switch(ch)
{
case 1:ob1.creat();
break;
case 2:ob1.display();
break;
case 3: ob1.mult();
break;
case 4:ob1.modify();
break;
case 5:k=0;
break;
}
}
return 0;
}
0 comments:
Post a Comment