dotfiles/.config/Code/User/History/-3d2256b8/HmhR.cpp

82 lines
1.8 KiB
C++
Raw Normal View History

2024-06-16 18:53:25 +05:00
/*
Rafay Ahmad
23I-2526
*/
#include <iostream>
using namespace std;
class Vector{
int size;
int *arr;
public:
Vector(int size) : size(size){
arr = new int[size];
}
Vector operator+(Vector& other){
Vector *result = new Vector(size);
for(int i=0;i<this->size && i<other.size;i++){
result->arr[i] = this->arr[i] + other.arr[i];
}
if(this->size > other.size) for(int i=this->size-other.size;i<this->size;i++) result->arr[i] = this->arr[i];
else for(int i=other.size-this->size;i<other.size;i++) result->arr[i] = other.arr[i];
return *result;
}
Vector operator-(Vector& other){
Vector *result = new Vector(size);
for(int i=0;i<this->size && i<other.size;i++){
result->arr[i] = this->arr[i] - other.arr[i];
}
if(this->size > other.size) for(int i=this->size-other.size;i<this->size;i++) result->arr[i] = this->arr[i];
else for(int i=other.size-this->size;i<other.size;i++) result->arr[i] = other.arr[i];
return *result;
}
Vector operator*(int n){
for(int i=0;i<this->size;i++) this->arr[i] *= n;
return *this;
}
Vector operator/(int n){
if(n != 0) for(int i=0;i<this->size;i++) this->arr[i] /= n;
return *this;
}
Vector operator+=(Vector& other){
return *this + other;
}
Vector operator-=(Vector& other){
return *this - other;
}
bool operator==(Vector& other){
if(this->size != other.size) return false;
for(int i=0;i<this->size;i++) if(this->arr[i] != other.arr[i]) return false;
return true;
}
bool operator!=(Vector& other){
return !(*this == other);
}
~Vector(){
delete[] arr;
}
};
int main(){
return 0;
}