Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include<string>
- #include <vector>
- using namespace std;
- template <class T>
- class Array{
- public:
- Array(){}
- vector<T> copy(){
- return a;
- }
- void input(){
- int n;
- cin>>n;
- a=vector<T>(n);
- for(int i=0;i<a.size();i++){
- cin>>a[i];
- }
- }
- void output(){
- cout<<"[";
- string str="";
- for(int i=0;i<a.size();i++) {
- cout<<str << a[i];
- str=", ";
- }
- cout<<"]\n";
- }
- void push_back(T k){
- a.push_back(k);
- }
- T sum(){
- T f = 0.0;
- for( int i=0; i<a.size(); i++){
- f+=a[i];
- }
- return f;
- }
- void concate(const vector<T> & b){
- for(int i=0;i<b.size();i++){
- a.push_back(b[i]);
- }
- }
- private:
- vector<T> a;
- };
- int main(){
- Array<int>a;
- cout<<"Введите массив\n";
- a.input();
- cout<<a.sum();
- Array<double>b;
- cout<<"\nВведите массив\n";
- b.input();
- cout<<b.sum();
- }
Advertisement
Add Comment
Please, Sign In to add comment