Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template<class T>
- class vector
- {
- T *v;
- int size;
- public:
- void input()
- {
- cout<<"enter the size of array"<<endl;
- cin>>size;
- v=new int[size];
- }
- void create();
- void display();
- void modify();
- void scalar_mul();
- };
- template<class T>
- void vector<T>::create()
- {
- for (int i=0;i<size;i++)
- v[i]=0;
- }
- template<class T>
- void vector<T>::display(){
- cout<<"(";
- for (int i=0;i<size;i++){
- cout<<v[i]<<",";
- }
- cout<<")";
- }
- template<class T>
- void vector<T>::modify()
- {
- int pos,newval;
- cout<<"enter the position you want to modify";
- cin>>pos;
- cout<<"enter new value ";
- cin>>newval;
- v[pos-1]=newval;
- }
- template<class T>
- void vector<T>::scalar_mul()
- {
- int sca;
- cout<<"enter the scalar value";
- cin>>sca;
- for(int i=0;i<size;i++)
- {
- v[i]=v[i]*sca;
- }
- }
- int main()
- {
- vector<int>v1;
- v1.input();
- v1.create();
- v1.display();
- v1.modify();
- v1.display();
- v1.scalar_mul();
- v1.display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement