Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- class Vector{
- private:
- int len;
- double* first;
- public:
- Vector(int len,double value = 0){ // ПУНКТ А
- this->len = len;
- first = new double [len];
- for(int i = 0;i < len;i++){
- first[i] = value;
- }
- }
- Vector(const Vector &other){ // ПУНКТ Б
- this->len = other.len;
- first = new double [this->len];
- for (int i = 0;i < len;i++){
- first[i] = other.first[i];
- }
- }
- ~Vector(){ // ПУНКТ В
- delete [] first;
- }
- Vector& operator= (const Vector &other){ // ПУНКТ Г
- this->len = other.len;
- delete [] first;
- first = new double [this->len];
- for (int i = 0;i < len;i++){
- this->first[i] = other.first[i];
- }
- return *this;
- }
- Vector& operator+= (const Vector &other){
- for (int i = 0;i < len;i++){
- this->first[i] += other.first[i];
- }
- return *this;
- }
- Vector& operator-= (const Vector &other){
- for (int i = 0;i < len;i++){
- this->first[i] -= other.first[i];
- }
- return *this;
- }
- Vector& operator+ (const Vector &other){
- Vector res(*this);
- for (int i = 0;i < len;i++){
- res.first[i] += other.first[i];
- }
- return res;
- }
- Vector& operator- (const Vector &other){
- Vector res(*this);
- for (int i = 0;i < len;i++){
- res.first[i] -= other.first[i];
- }
- return res;
- }
- Vector& operator* (int a){
- Vector res(*this);
- for (int i = 0;i < len;i++){
- res.first[i] *= a;
- }
- return res;
- }
- double operator[] (int index) const {
- return this->first[index];
- }
- double& operator[] (int index) {
- return first[index];
- }
- operator double () const{ // Оператор привидения типа к double доделать
- return ;
- }
- double operator* (const Vector &other){ //скалярное произведение
- double res = 0;
- for (int i = 0;i < len;i++){
- res += this->first[i] * other.first[i];
- }
- return res;
- }
- double lengthV() const{ //ПУНКТ Д
- double res = 0;
- for(int i = 0;i<this->len;i++){
- res += this->first[i] * this->first[i];
- }
- res = sqrt(res);
- return res;
- }
- int sizeV() const { // ПУНКТ Е
- return this->len;
- }
- };
- istream& operator >> (istream &in,Vector &other){
- for (int i = 0; i < other.lengthV(); i++) {
- in >> other[i];
- }
- return in;
- }
- ostream& operator << (ostream &out, const Vector &other) {
- for (int i = 0; i < other.lengthV(); i++){
- out << other[i] << " ";
- }
- return out;
- }
- Vector& operator* (int a, Vector &other){ // Возможный вариант перегрузки умножения числа на вектор
- Vector res(other);
- for (int i = 0;i < other.lengthV();i++){
- res[i] *= a;
- }
- return res;
- }
- int main(){
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement