Advertisement
Jgug

l6_v4

Dec 21st, 2012
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <conio.h>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. template <class T> class Sequence : public vector<T>
  9. {
  10. public:
  11.     Sequence<T>(int N):vector<T>(N){}
  12.     void fill();
  13.     void print();
  14. };
  15.  
  16. template<class T> void Sequence<T>::fill()
  17. {
  18.     for(unsigned int i=0;i<size();i++)
  19.     {
  20.         cout<<"a["<<i+1<<"]=";
  21.         cin>>at(i);
  22.     }
  23.     cout<<endl;
  24. };
  25.  
  26. template<class T> void Sequence<T>::print()
  27. {
  28.     T tmp;
  29.     cout<<"Sequence: "<<endl;
  30.     cout<<at(0)<<"  ";
  31.     for(unsigned int i=0;i<size()-1;i++)
  32.     {
  33.         tmp=(pow(-1,(i+1)))*at(i)*at(i+1);
  34.         cout<<tmp<<"  ";
  35.     }
  36.     cout<<endl;
  37. };
  38.  
  39. void main()
  40. {
  41.     int size;
  42.     cout<<"Input size=";
  43.     cin>>size;
  44.  
  45.     cout<<endl<<"int:"<<endl;
  46.     Sequence<int> intObj(size);
  47.     intObj.fill();
  48.     intObj.print();
  49.     intObj.~Sequence();
  50.  
  51.     cout<<endl<<"double:"<<endl;
  52.     Sequence<double> doubleObj(size);
  53.     doubleObj.fill();
  54.     doubleObj.print();
  55.     doubleObj.~Sequence();
  56.  
  57.     cout<<endl<<"char:"<<endl;
  58.     Sequence<char> charObj(size);
  59.     charObj.fill();
  60.     charObj.print();
  61.     charObj.~Sequence();
  62.  
  63.     _getch();
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement