Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <conio.h>
- #include <vector>
- using namespace std;
- template <class T> class Sequence : public vector<T>
- {
- public:
- Sequence<T>(int N):vector<T>(N){}
- void fill();
- void print();
- };
- template<class T> void Sequence<T>::fill()
- {
- for(unsigned int i=0;i<size();i++)
- {
- cout<<"a["<<i+1<<"]=";
- cin>>at(i);
- }
- cout<<endl;
- };
- template<class T> void Sequence<T>::print()
- {
- T tmp;
- cout<<"Sequence: "<<endl;
- cout<<at(0)<<" ";
- for(unsigned int i=0;i<size()-1;i++)
- {
- tmp=(pow(-1,(i+1)))*at(i)*at(i+1);
- cout<<tmp<<" ";
- }
- cout<<endl;
- };
- void main()
- {
- int size;
- cout<<"Input size=";
- cin>>size;
- cout<<endl<<"int:"<<endl;
- Sequence<int> intObj(size);
- intObj.fill();
- intObj.print();
- intObj.~Sequence();
- cout<<endl<<"double:"<<endl;
- Sequence<double> doubleObj(size);
- doubleObj.fill();
- doubleObj.print();
- doubleObj.~Sequence();
- cout<<endl<<"char:"<<endl;
- Sequence<char> charObj(size);
- charObj.fill();
- charObj.print();
- charObj.~Sequence();
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement