Lab3_vector

Клас Вектор до лаб 3
 avatar
mysliutchka
plain_text
3 years ago
1.2 kB
6
Indexable
#include <iostream>
using namespace std;
class Vector {
private:
    int vector_size;
    double* p_vector;
public:
    Vector() {
        this->vector_size = 0;
        this->p_vector = 0;
    }
    Vector(int& cols) {
        this->vector_size = cols;
        this->p_vector = new double[this->vector_size];
        for (int i = 0; i < this->vector_size; i++) {
            cin >> i;
            this->p_vector[i] = i;
        }
    }
    void Print() {
        for (int i = 0; i < this->vector_size; i++) {
            cout << this->p_vector[i] << "\t";
        }
    }

    double Sum_of_elements() {
        double sum = 0;
        for (int i = 0; i < this->vector_size; i++) {
            sum = +this->p_vector[i];
        }
        cout << sum;
        return sum;
    }
    ~Vector() {
        delete[] this->p_vector;
    }
};
int main() {

    int rows, cols;
    cout << "Enter number of rows in the table: " << endl;
    cin >> rows;
    cout << "Enter number of columns in the table: " << endl;
    cin >> cols;

    Vector vector1(cols);
    vector1.Print();
    vector1.Sum_of_elements();
    /*Table table_1(rows,cols);
    table_1.PrintTable();*/
    return 0;
}
Editor is loading...