lil_SV

ZalupaKoncha

Oct 15th, 2022
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include<string>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. template <class T>
  9. class Array{
  10. public:
  11.     Array(){}
  12.     vector<T> copy(){
  13.         return a;
  14.     }
  15.  
  16.     void input(){
  17.         int n;
  18.         cin>>n;
  19.         a=vector<T>(n);
  20.         for(int i=0;i<a.size();i++){
  21.             cin>>a[i];
  22.         }
  23.     }
  24.  
  25.     void output(){
  26.         cout<<"[";
  27.         string str="";
  28.         for(int i=0;i<a.size();i++) {
  29.             cout<<str << a[i];
  30.             str=", ";
  31.         }
  32.         cout<<"]\n";
  33.     }
  34.  
  35.     void push_back(T k){
  36.         a.push_back(k);
  37.     }
  38.  
  39.     T sum(){
  40.         T f = 0.0;
  41.         for( int i=0; i<a.size(); i++){
  42.             f+=a[i];
  43.         }
  44.         return f;
  45.     }
  46.  
  47.     void concate(const vector<T> & b){
  48.         for(int i=0;i<b.size();i++){
  49.             a.push_back(b[i]);
  50.         }
  51.     }
  52. private:
  53.     vector<T> a;
  54. };
  55.  
  56. int main(){
  57.     Array<int>a;
  58.     cout<<"Введите массив\n";
  59.     a.input();
  60.     cout<<a.sum();
  61.     Array<double>b;
  62.     cout<<"\nВведите массив\n";
  63.     b.input();
  64.     cout<<b.sum();
  65. }
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
Advertisement
Add Comment
Please, Sign In to add comment