This commit is contained in:
RafayAhmad7548 2024-06-16 18:53:25 +05:00
parent 37776af5db
commit ab03d5f10c
4045 changed files with 286212 additions and 3 deletions

View file

@ -0,0 +1,129 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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(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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,123 @@
/*
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
// Test equality operator
bool isEqual = v1 == v2;
cout << "v1 == v2: " << (isEqual ? "true" : "false") << endl;
// Test inequality operator
bool isNotEqual = v1 != v2;
cout << "v1 != v2: " << (isNotEqual ? "true" : "false") << endl;
return 0;
}

View file

@ -0,0 +1,127 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,132 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) 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(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 if(this->size < other.size) 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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
for(int i=0;i<this->size && i<other.size;i++) this->arr[i] += other.arr[i];
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,128 @@
/*
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
// Test subtraction operator
Vector v4 = v1 - v2;
cout << "v1 - v2: " << v4 << endl;
// Test multiplication operator
Vector v5 = v1 * 2;
cout << "v1 * 2: " << v5 << endl;
// Test division operator
Vector v6 = v1 / 2;
cout << "v1 / 2: " << v6 << endl;
// Test addition assignment operator
v1 += v2;
cout << "v1 += v2: " << v1 << endl;
// Test subtraction assignment operator
v1 -= v2;
cout << "v1 -= v2: " << v1 << endl;
// Test equality operator
bool isEqual = v1 == v2;
cout << "v1 == v2: " << (isEqual ? "true" : "false") << endl;
// Test inequality operator
bool isNotEqual = v1 != v2;
cout << "v1 != v2: " << (isNotEqual ? "true" : "false") << endl;
return 0;
}

View file

@ -0,0 +1,128 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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(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){
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,132 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=this->size;i<other.size;i++) result.arr[i] = other.arr[i];
return result;
}
Vector operator-(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,132 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=this->size;i<other.size;i++) result.arr[i] = other.arr[i];
return result;
}
Vector operator-(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,133 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=this->size;i<other.size;i++) result.arr[i] = other.arr[i];
return result;
}
Vector operator-(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=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){
delete this;
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,134 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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 if(this->size < other.size) 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(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 if(this->size < other.size) 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){
for(int i=0;i<this->size && i<other.size;i++){
this->arr[i] += other.arr[i];
}
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,76 @@
/*
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,121 @@
/*
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,129 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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(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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,132 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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 if(this->size < other.size) 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(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 if(this->size < other.size) 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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
for(int i=0;i<this->size && i<other.size;i++) this->arr[i] += other.arr[i];
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,131 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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 if(this->size < other.size) 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(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 if(this->size < other.size) 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){
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,86 @@
/*
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
}
istream& operator>>(istream& output, Vector& other){
}
int main(){
return 0;
}

View file

@ -0,0 +1,82 @@
/*
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;
}

View file

@ -0,0 +1,132 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(size>other.size?size:other.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 if(this->size < other.size) 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(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 if(this->size < other.size) 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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
for(int i=0;i<this->size && i<other.size;i++) this->arr[i] += other.arr[i];
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,89 @@
/*
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
return 0;
}

View file

@ -0,0 +1,126 @@
/*
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout << "v1 * 2: " << v5 << endl;
// Test division operator
Vector v6 = v1 / 2;
cout << "v1 / 2: " << v6 << endl;
// Test addition assignment operator
v1 += v2;
cout << "v1 += v2: " << v1 << endl;
// Test subtraction assignment operator
v1 -= v2;
cout << "v1 -= v2: " << v1 << endl;
// Test equality operator
bool isEqual = v1 == v2;
cout << "v1 == v2: " << (isEqual ? "true" : "false") << endl;
// Test inequality operator
bool isNotEqual = v1 != v2;
cout << "v1 != v2: " << (isNotEqual ? "true" : "false") << endl;
return 0;
}

View file

@ -0,0 +1,132 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=this->size;i<other.size;i++) result.arr[i] = other.arr[i];
return result;
}
Vector operator-(Vector& other){
Vector result(size>other.size?size:other.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 if(this->size < other.size) 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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
for(int i=0;i<this->size && i<other.size;i++) this->arr[i] += other.arr[i];
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,132 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=this->size;i<other.size;i++) result.arr[i] = other.arr[i];
return result;
}
Vector operator-(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
for(int i=0;i<this->size && i<other.size;i++) this->arr[i] += other.arr[i];
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,131 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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 if(this->size < other.size) 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(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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,131 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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 if(this->size < other.size) 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(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 if(this->size < other.size) 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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,129 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,132 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=this->size;i<other.size;i++) result.arr[i] = other.arr[i];
return result;
}
Vector operator-(Vector& other){
Vector result(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 if(this->size < other.size) 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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
for(int i=0;i<this->size && i<other.size;i++) this->arr[i] += other.arr[i];
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,124 @@
/*
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
// Test subtraction assignment operator
v1 -= v2;
cout << "v1 -= v2: " << v1 << endl;
// Test equality operator
bool isEqual = v1 == v2;
cout << "v1 == v2: " << (isEqual ? "true" : "false") << endl;
// Test inequality operator
bool isNotEqual = v1 != v2;
cout << "v1 != v2: " << (isNotEqual ? "true" : "false") << endl;
return 0;
}

View file

@ -0,0 +1,133 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=this->size;i<other.size;i++) result.arr[i] = other.arr[i];
return result;
}
Vector operator-(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=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){
Vector temp = *this + other;
*this = temp;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,129 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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(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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,80 @@
/*
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){
}
~Vector(){
delete[] arr;
}
};
int main(){
return 0;
}

View file

@ -0,0 +1,131 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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(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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,135 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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 if(this->size < other.size) 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(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 if(this->size < other.size) 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){
for(int i=0;i<this->size && i<other.size;i++){
this->arr[i] += other.arr[i];
}
if(this->size < other.size) for(int i=other.size-this->size;i<other.size;i++) this->arr[i] = other.arr[i];
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,89 @@
/*
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++){
}
}
istream& operator>>(istream& output, Vector& other){
}
int main(){
return 0;
}

View file

@ -0,0 +1,129 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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(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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1 @@
{"version":1,"resource":"file:///home/rafayahmad/Stuff/lab12/lab12.cpp","entries":[{"id":"afrq.cpp","timestamp":1713759932455},{"id":"HmhR.cpp","timestamp":1713759949182},{"id":"ELU9.cpp","timestamp":1713760013557},{"id":"HFy4.cpp","timestamp":1713760041170},{"id":"cJ9E.cpp","timestamp":1713760080763},{"id":"vGYz.cpp","timestamp":1713760109219},{"id":"fIGj.cpp","timestamp":1713760149722},{"id":"Lq9G.cpp","timestamp":1713760179231},{"id":"n5bq.cpp","timestamp":1713760365802},{"id":"4IVn.cpp","timestamp":1713760390402},{"id":"Mga0.cpp","timestamp":1713760404018},{"id":"WRN7.cpp","timestamp":1713760427408},{"id":"1fiy.cpp","timestamp":1713760439144},{"id":"F00v.cpp","timestamp":1713760460220},{"id":"udbv.cpp","timestamp":1713760804195},{"id":"3fJd.cpp","timestamp":1713760828175},{"id":"pcP7.cpp","timestamp":1713760852361},{"id":"V0PS.cpp","timestamp":1713760868561},{"id":"uM5H.cpp","timestamp":1713760900370},{"id":"FfCQ.cpp","timestamp":1713760912457},{"id":"d707.cpp","timestamp":1713760930493},{"id":"5rlD.cpp","timestamp":1713761116767},{"id":"0nHQ.cpp","timestamp":1713761133340},{"id":"Zdbp.cpp","timestamp":1713761167243},{"id":"se5Y.cpp","timestamp":1713761201582},{"id":"b0sO.cpp","timestamp":1713761229362},{"id":"T9Fg.cpp","timestamp":1713761311091},{"id":"UGrv.cpp","timestamp":1713761323254},{"id":"qAaU.cpp","timestamp":1713761401653},{"id":"GzZf.cpp","timestamp":1713761927696},{"id":"lzHY.cpp","timestamp":1713761969538},{"id":"qmuE.cpp","timestamp":1713762099611},{"id":"wmtz.cpp","timestamp":1713762158670},{"id":"bmFh.cpp","timestamp":1713762175351},{"id":"BpRI.cpp","timestamp":1713762229266},{"id":"kqyl.cpp","timestamp":1713763977584},{"id":"g946.cpp","timestamp":1713764000374},{"id":"G1Jy.cpp","timestamp":1713780568274},{"id":"IbPO.cpp","timestamp":1713780895144},{"id":"47A4.cpp","timestamp":1713781005297},{"id":"VXgm.cpp","timestamp":1713781035174},{"id":"Pdc3.cpp","timestamp":1713781100588},{"id":"SQKD.cpp","timestamp":1713781122491},{"id":"jDAX.cpp","timestamp":1713781158508},{"id":"BCsW.cpp","timestamp":1713781185408},{"id":"yX0n.cpp","timestamp":1713781349672},{"id":"qsRo.cpp","timestamp":1713781377439},{"id":"7OtB.cpp","timestamp":1713781423052},{"id":"X2T5.cpp","timestamp":1713781474252},{"id":"A4KU.cpp","timestamp":1713781487832}]}

View file

@ -0,0 +1,90 @@
/*
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
}
int main(){
return 0;
}

View file

@ -0,0 +1,132 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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 if(this->size < other.size) 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(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 if(this->size < other.size) 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){
for(int i=0;i<this->size && i<other.size;i++) this->arr[i] += other.arr[i];
return *this;
}
Vector operator-=(Vector& other){
for(int i=0;i<this->size && i<other.size;i++) this->arr[i] += other.arr[i];
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,132 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=this->size;i<other.size;i++) result.arr[i] = other.arr[i];
return result;
}
Vector operator-(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,134 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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 if(this->size < other.size) 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(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 if(this->size < other.size) 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){
for(int i=0;i<this->size && i<other.size;i++){
this->arr[i] += other.arr[i];
}
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,131 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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 if(this->size < other.size) 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(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 if(this->size < other.size) 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){
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,130 @@
/*
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
// Test output operator
cout << "v1: " << v1 << endl;
cout << "v2: " << v2 << endl;
// Test addition operator
Vector v3 = v1 + v2;
cout << "v1 + v2: " << v3 << endl;
// Test subtraction operator
Vector v4 = v1 - v2;
cout << "v1 - v2: " << v4 << endl;
// Test multiplication operator
Vector v5 = v1 * 2;
cout << "v1 * 2: " << v5 << endl;
// Test division operator
Vector v6 = v1 / 2;
cout << "v1 / 2: " << v6 << endl;
// Test addition assignment operator
v1 += v2;
cout << "v1 += v2: " << v1 << endl;
// Test subtraction assignment operator
v1 -= v2;
cout << "v1 -= v2: " << v1 << endl;
// Test equality operator
bool isEqual = v1 == v2;
cout << "v1 == v2: " << (isEqual ? "true" : "false") << endl;
// Test inequality operator
bool isNotEqual = v1 != v2;
cout << "v1 != v2: " << (isNotEqual ? "true" : "false") << endl;
return 0;
}

View file

@ -0,0 +1,128 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,132 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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 if(this->size < other.size) 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(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 if(this->size < other.size) 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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,136 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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 if(this->size < other.size) 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(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 if(this->size < other.size) 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){
for(int i=0;i<this->size && i<other.size;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 if(this->size < other.size) for(int i=other.size-this->size;i<other.size;i++) result.arr[i] = other.arr[i];
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,132 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector* operator+(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=this->size;i<other.size;i++) result.arr[i] = other.arr[i];
return &result;
}
Vector operator-(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=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){
this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,130 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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(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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,129 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,127 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,88 @@
/*
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& output, Vector& other){
}
int main(){
return 0;
}

View file

@ -0,0 +1,136 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(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 if(this->size < other.size) 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(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 if(this->size < other.size) 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){
for(int i=0;i<this->size && i<other.size;i++){
this->arr[i] += other.arr[i];
}
if(this->size > other.size) for(int i=this->size-other.size;i<this->size;i++) this->arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=other.size-this->size;i<other.size;i++) this->arr[i] = other.arr[i];
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}

View file

@ -0,0 +1,132 @@
/*
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(const Vector& other) : size(other.size){
arr = new int[size];
for(int i=0;i<size;i++){
arr[i] = other.arr[i];
}
}
Vector operator+(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=this->size;i<other.size;i++) result.arr[i] = other.arr[i];
return result;
}
Vector operator-(Vector& other){
Vector result(size>other.size?size:other.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=other.size;i<this->size;i++) result.arr[i] = this->arr[i];
else if(this->size < other.size) for(int i=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){
*this = *this + other;
return *this;
}
Vector operator-=(Vector& other){
*this = *this - other;
return *this;
}
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);
}
friend ostream& operator<<(ostream& output, Vector& other);
friend istream& operator>>(istream& output, Vector& other);
~Vector(){
delete[] arr;
}
};
ostream& operator<<(ostream& output, Vector& other){
output<<"Size: "<<other.size<<endl;
for(int i=0;i<other.size;i++) output<<other.arr[i]<<" ";
return output;
}
istream& operator>>(istream& input, Vector& other){
cout<<"Enter Size: ";
input>>other.size;
delete[] other.arr;
other.arr = new int[other.size];
cout<<"Enter values\n";
for(int i=0;i<other.size;i++) input>>other.arr[i];
return input;
}
int main(){
Vector v1(5);
Vector v2(5);
cout<<"Enter values for v1: ";
cin>>v1;
cout<<"Enter values for v2: ";
cin>>v2;
cout<< "v1: "<<v1<< endl;
cout<<"v2: "<<v2<< endl;
Vector v3 = v1 + v2;
cout<<"v1 + v2: "<<v3<<endl;
Vector v4 = v1 - v2;
cout<<"v1 - v2: "<<v4<<endl;
Vector v5 = v1 * 2;
cout<<"v1 * 2: "<<v5<<endl;
Vector v6 = v1 / 2;
cout<<"v1 / 2: "<<v6<<endl;
v1 += v2;
cout<<"v1 += v2: "<<v1<<endl;
v1 -= v2;
cout<<"v1 -= v2: "<<v1<<endl;
bool isEqual = v1 == v2;
cout<< "v1 == v2: "<<(isEqual ? "true" : "false")<<endl;
bool isNotEqual = v1 != v2;
cout<<"v1 != v2: "<<(isNotEqual ? "true" : "false")<<endl;
return 0;
}