SlideShare a Scribd company logo
check the modifed code now you will get all operations done.
terminal will display add, subtract, multiply and div operation and dounday condition too.
#include
using namespace std;
class Array
{
private:
int start;
int end;
int *array;
public:
Array(int n);
Array(int n, int m);
int &operator[](int index);
Array &operator=(Array a);
bool operator==(Array &a);
bool operator!=(Array &a);
friend ostream &operator<<(ostream &out, Array &a);
friend Array &operator+(Array &a, Array&b);
friend Array &operator-(Array &a, Array&b);
friend Array &operator*(Array &a, Array&b);
friend Array &operator/(Array &a, Array&b);
};
Array::Array(int n)
{
start = 0;
end = n-1;
array = new int[n];
for (int i = 0; i < n; i++)
array[i] = i+1;
}
Array::Array(int n, int m)
{
start = n;
end = m-1;
array = new int[m-n];
for (int i = 0; i < m-n; i++)
array[i] = start + i;
}
int &Array::operator[](int index)
{
if (index >= start && index <= end)
{
return (array[index-start]);
}
cout << "Error: Index out of bounds." << endl;
int temp = 0;
return temp;
//return *array;
}
Array &Array::operator=(Array a)
{
start = a.start;
end = a.end;
for(int i = 0; i < end - start; ++i)
{
array[i] = a.array[i];
}
return *this;
}
bool Array::operator==(Array &a)
{
for(int i = 0; i < end - start; ++i)
{
if(array[i] != a.array[i])
return false;
}
return true;
}
bool Array::operator!=(Array &a){
return *this == a;
}
ostream &operator<<(ostream &out, Array &b)
{
for(int i = 0; i < b.end - b.start; ++i)
{
out << "(" << i + b.start << ")" << b.array[i] << " ";
}
return out;
}
Array &operator+(Array &a, Array&b)
{
Array arr(a.end - a.start);
for(int i = 0; i < a.end - a.start; ++i)
{
arr.array[i] = a.array[i] + b.array[i];
}
return arr;
}
Array &operator-(Array &a, Array&b)
{
Array arr(a.end - a.start);
for(int i = 0; i < a.end - a.start; ++i)
{
arr.array[i] = a.array[i] - b.array[i];
}
return arr;
}
Array &operator*(Array &a, Array&b)
{
Array arr(a.end - a.start);
for(int i = 0; i < a.end - a.start; ++i)
{
arr.array[i] = a.array[i] * b.array[i];
}
return arr;
}
Array &operator/(Array &a, Array&b)
{
Array arr(a.end - a.start);
for(int i = 0; i < a.end - a.start; ++i)
{
if (a.array[i]!=0)
arr.array[i] = b.array[i] / a.array[i];
}
return arr;
}
int main()
{
Array test(10);
Array Ary1(10,25);
Array Ary2(-5,10);
Array Ary3(15,30);
int i;
int j;
for (i = 0; i < 10; i++)
test[i] = i+1;
cout << "Test array output" << endl;
for (i = 0; i < 10; i++)
cout << test[i] << " ";
cout << endl;
i = -5;
while (i < 10)
{
Ary2[i] = i*2;
i++;
}
cout << " ";
cout << "Ary2 array otuput" << endl;
for (i = -5; i < 10; i++)
cout << Ary2[i] << " ";
cout << endl;
i = 10; j = -5;
while ( i < 25 )
{ Ary1[ i ] = i*100;
Ary2[j] = j * 200;
i++; j++;
};
cout << "Ary1 array output" << endl;
cout << Ary1 << endl;
cout << endl;
cout << " ";
cout << "Ary2 array output" << endl;
cout << Ary2 << endl;
cout << endl;
cout << " ";
for (i=0;i<14;i++)
Ary3[i+15] = Ary1[i+10] + Ary2[i+-5];
cout << "Ary3 array Addition output" << endl;
cout << Ary3 << endl;
cout << " ";
for (i=0;i<14;i++)
Ary3[i+15] = Ary1[i+10] - Ary2[i+-5];
cout << "Ary3 array Subtraction output" << endl;
cout << Ary3 << endl;
cout << " ";
for (i=0;i<14;i++)
Ary3[i+15] = Ary1[i+10] * Ary2[i+-5];
cout << "Ary3 array Multiply output" << endl;
cout << Ary3 << endl;
cout << " ";
for (i=0;i<14;i++)
Ary3[i+15] = Ary2[i+-5]/Ary1[i+10];
cout << "Ary3 array Division output" << endl;
cout << Ary3 << endl;
cout << " ";
cout << "Test boundary conditions" << endl;
Ary1[8] = 100;
Ary1[16] = 200;
i = 100;
cout << Ary1[i] << endl;
return 0;
}
Solution
check the modifed code now you will get all operations done.
terminal will display add, subtract, multiply and div operation and dounday condition too.
#include
using namespace std;
class Array
{
private:
int start;
int end;
int *array;
public:
Array(int n);
Array(int n, int m);
int &operator[](int index);
Array &operator=(Array a);
bool operator==(Array &a);
bool operator!=(Array &a);
friend ostream &operator<<(ostream &out, Array &a);
friend Array &operator+(Array &a, Array&b);
friend Array &operator-(Array &a, Array&b);
friend Array &operator*(Array &a, Array&b);
friend Array &operator/(Array &a, Array&b);
};
Array::Array(int n)
{
start = 0;
end = n-1;
array = new int[n];
for (int i = 0; i < n; i++)
array[i] = i+1;
}
Array::Array(int n, int m)
{
start = n;
end = m-1;
array = new int[m-n];
for (int i = 0; i < m-n; i++)
array[i] = start + i;
}
int &Array::operator[](int index)
{
if (index >= start && index <= end)
{
return (array[index-start]);
}
cout << "Error: Index out of bounds." << endl;
int temp = 0;
return temp;
//return *array;
}
Array &Array::operator=(Array a)
{
start = a.start;
end = a.end;
for(int i = 0; i < end - start; ++i)
{
array[i] = a.array[i];
}
return *this;
}
bool Array::operator==(Array &a)
{
for(int i = 0; i < end - start; ++i)
{
if(array[i] != a.array[i])
return false;
}
return true;
}
bool Array::operator!=(Array &a){
return *this == a;
}
ostream &operator<<(ostream &out, Array &b)
{
for(int i = 0; i < b.end - b.start; ++i)
{
out << "(" << i + b.start << ")" << b.array[i] << " ";
}
return out;
}
Array &operator+(Array &a, Array&b)
{
Array arr(a.end - a.start);
for(int i = 0; i < a.end - a.start; ++i)
{
arr.array[i] = a.array[i] + b.array[i];
}
return arr;
}
Array &operator-(Array &a, Array&b)
{
Array arr(a.end - a.start);
for(int i = 0; i < a.end - a.start; ++i)
{
arr.array[i] = a.array[i] - b.array[i];
}
return arr;
}
Array &operator*(Array &a, Array&b)
{
Array arr(a.end - a.start);
for(int i = 0; i < a.end - a.start; ++i)
{
arr.array[i] = a.array[i] * b.array[i];
}
return arr;
}
Array &operator/(Array &a, Array&b)
{
Array arr(a.end - a.start);
for(int i = 0; i < a.end - a.start; ++i)
{
if (a.array[i]!=0)
arr.array[i] = b.array[i] / a.array[i];
}
return arr;
}
int main()
{
Array test(10);
Array Ary1(10,25);
Array Ary2(-5,10);
Array Ary3(15,30);
int i;
int j;
for (i = 0; i < 10; i++)
test[i] = i+1;
cout << "Test array output" << endl;
for (i = 0; i < 10; i++)
cout << test[i] << " ";
cout << endl;
i = -5;
while (i < 10)
{
Ary2[i] = i*2;
i++;
}
cout << " ";
cout << "Ary2 array otuput" << endl;
for (i = -5; i < 10; i++)
cout << Ary2[i] << " ";
cout << endl;
i = 10; j = -5;
while ( i < 25 )
{ Ary1[ i ] = i*100;
Ary2[j] = j * 200;
i++; j++;
};
cout << "Ary1 array output" << endl;
cout << Ary1 << endl;
cout << endl;
cout << " ";
cout << "Ary2 array output" << endl;
cout << Ary2 << endl;
cout << endl;
cout << " ";
for (i=0;i<14;i++)
Ary3[i+15] = Ary1[i+10] + Ary2[i+-5];
cout << "Ary3 array Addition output" << endl;
cout << Ary3 << endl;
cout << " ";
for (i=0;i<14;i++)
Ary3[i+15] = Ary1[i+10] - Ary2[i+-5];
cout << "Ary3 array Subtraction output" << endl;
cout << Ary3 << endl;
cout << " ";
for (i=0;i<14;i++)
Ary3[i+15] = Ary1[i+10] * Ary2[i+-5];
cout << "Ary3 array Multiply output" << endl;
cout << Ary3 << endl;
cout << " ";
for (i=0;i<14;i++)
Ary3[i+15] = Ary2[i+-5]/Ary1[i+10];
cout << "Ary3 array Division output" << endl;
cout << Ary3 << endl;
cout << " ";
cout << "Test boundary conditions" << endl;
Ary1[8] = 100;
Ary1[16] = 200;
i = 100;
cout << Ary1[i] << endl;
return 0;
}

More Related Content

Similar to check the modifed code now you will get all operations done.termin.pdf

Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
rohassanie
 
lecture12.ppt
lecture12.pptlecture12.ppt
lecture12.ppt
UmairMughal74
 
Operator overloading in c++ is the most required.
Operator overloading in c++ is the most required.Operator overloading in c++ is the most required.
Operator overloading in c++ is the most required.
iammukesh1075
 
Array and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptxArray and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptx
JumanneChiyanda
 
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
arihantelehyb
 
Synapse india dotnet development overloading operater part 3
Synapse india dotnet development overloading operater part 3Synapse india dotnet development overloading operater part 3
Synapse india dotnet development overloading operater part 3
Synapseindiappsdevelopment
 
Arrays matrix 2020 ab
Arrays matrix 2020 abArrays matrix 2020 ab
Arrays matrix 2020 ab
Dr .Ahmed Tawwab
 
Groovy
GroovyGroovy
Groovy
Zen Urban
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
arri2009av
 
Chapter12 array-single-dimension
Chapter12 array-single-dimensionChapter12 array-single-dimension
Chapter12 array-single-dimension
Deepak Singh
 
Arrays
ArraysArrays
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
vrgokila
 
Array
ArrayArray
Object oriented programming; operator overloading array
Object oriented programming; operator overloading arrayObject oriented programming; operator overloading array
Object oriented programming; operator overloading array
Syed Zaid Irshad
 
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
apleather
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
Er Ritu Aggarwal
 
COA_remaining_lab_works_077BCT033.pdf
COA_remaining_lab_works_077BCT033.pdfCOA_remaining_lab_works_077BCT033.pdf
COA_remaining_lab_works_077BCT033.pdf
JavedAnsari236392
 
pointers 1
pointers 1pointers 1
pointers 1
gaurav koriya
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression Calculator
Neeraj Kaushik
 
2DArrays.ppt
2DArrays.ppt2DArrays.ppt
2DArrays.ppt
Nooryaseen9
 

Similar to check the modifed code now you will get all operations done.termin.pdf (20)

Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
lecture12.ppt
lecture12.pptlecture12.ppt
lecture12.ppt
 
Operator overloading in c++ is the most required.
Operator overloading in c++ is the most required.Operator overloading in c++ is the most required.
Operator overloading in c++ is the most required.
 
Array and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptxArray and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptx
 
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
 
Synapse india dotnet development overloading operater part 3
Synapse india dotnet development overloading operater part 3Synapse india dotnet development overloading operater part 3
Synapse india dotnet development overloading operater part 3
 
Arrays matrix 2020 ab
Arrays matrix 2020 abArrays matrix 2020 ab
Arrays matrix 2020 ab
 
Groovy
GroovyGroovy
Groovy
 
Write a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdfWrite a program that obtains the execution time of selection sort, bu.pdf
Write a program that obtains the execution time of selection sort, bu.pdf
 
Chapter12 array-single-dimension
Chapter12 array-single-dimensionChapter12 array-single-dimension
Chapter12 array-single-dimension
 
Arrays
ArraysArrays
Arrays
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Array
ArrayArray
Array
 
Object oriented programming; operator overloading array
Object oriented programming; operator overloading arrayObject oriented programming; operator overloading array
Object oriented programming; operator overloading array
 
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf#include stdio.h#include stdlib.h#include string.h#inclu.pdf
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
 
Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02Daapracticals 111105084852-phpapp02
Daapracticals 111105084852-phpapp02
 
COA_remaining_lab_works_077BCT033.pdf
COA_remaining_lab_works_077BCT033.pdfCOA_remaining_lab_works_077BCT033.pdf
COA_remaining_lab_works_077BCT033.pdf
 
pointers 1
pointers 1pointers 1
pointers 1
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression Calculator
 
2DArrays.ppt
2DArrays.ppt2DArrays.ppt
2DArrays.ppt
 

More from angelfragranc

C ) common in nature, but commonly used psychological measures rare.pdf
 C ) common in nature, but commonly used psychological measures rare.pdf C ) common in nature, but commonly used psychological measures rare.pdf
C ) common in nature, but commonly used psychological measures rare.pdf
angelfragranc
 
Question evidence 1. Comparison of DNA sequences among single-ce.pdf
    Question evidence   1. Comparison of DNA sequences among single-ce.pdf    Question evidence   1. Comparison of DNA sequences among single-ce.pdf
Question evidence 1. Comparison of DNA sequences among single-ce.pdf
angelfragranc
 
The purpose of alchol (ethanol) is to dissolve io.pdf
                     The purpose of alchol (ethanol) is to dissolve io.pdf                     The purpose of alchol (ethanol) is to dissolve io.pdf
The purpose of alchol (ethanol) is to dissolve io.pdf
angelfragranc
 
The components may not separate properly, because.pdf
                     The components may not separate properly, because.pdf                     The components may not separate properly, because.pdf
The components may not separate properly, because.pdf
angelfragranc
 
The answer would be 5 because Dehydration in a .pdf
                     The answer would be 5 because  Dehydration in a .pdf                     The answer would be 5 because  Dehydration in a .pdf
The answer would be 5 because Dehydration in a .pdf
angelfragranc
 
SO3 Sol.pdf
                     SO3                                       Sol.pdf                     SO3                                       Sol.pdf
SO3 Sol.pdf
angelfragranc
 
Nucleophile is any negative ion or any neutral mo.pdf
                     Nucleophile is any negative ion or any neutral mo.pdf                     Nucleophile is any negative ion or any neutral mo.pdf
Nucleophile is any negative ion or any neutral mo.pdf
angelfragranc
 
Moles of acid (HNO2) = Vol conc = 0.52 = 1 mol.pdf
                     Moles of acid (HNO2) = Vol  conc = 0.52 = 1 mol.pdf                     Moles of acid (HNO2) = Vol  conc = 0.52 = 1 mol.pdf
Moles of acid (HNO2) = Vol conc = 0.52 = 1 mol.pdf
angelfragranc
 
it is a salt formed by KOH and HCl it is a neutra.pdf
                     it is a salt formed by KOH and HCl it is a neutra.pdf                     it is a salt formed by KOH and HCl it is a neutra.pdf
it is a salt formed by KOH and HCl it is a neutra.pdf
angelfragranc
 
Cultural competence refers to an ability to inter.pdf
                     Cultural competence refers to an ability to inter.pdf                     Cultural competence refers to an ability to inter.pdf
Cultural competence refers to an ability to inter.pdf
angelfragranc
 
Conformers can also be named as conformational is.pdf
                     Conformers can also be named as conformational is.pdf                     Conformers can also be named as conformational is.pdf
Conformers can also be named as conformational is.pdf
angelfragranc
 
Cl S Se Solution Cl .pdf
                     Cl  S  Se  Solution                     Cl .pdf                     Cl  S  Se  Solution                     Cl .pdf
Cl S Se Solution Cl .pdf
angelfragranc
 
benzene sulphonic acid - SO3H on benzene ring .pdf
                     benzene sulphonic acid  - SO3H on benzene ring   .pdf                     benzene sulphonic acid  - SO3H on benzene ring   .pdf
benzene sulphonic acid - SO3H on benzene ring .pdf
angelfragranc
 
The HTML was developed by Tim Berners Lee, to create electronic docu.pdf
The HTML was developed by Tim Berners Lee, to create electronic docu.pdfThe HTML was developed by Tim Berners Lee, to create electronic docu.pdf
The HTML was developed by Tim Berners Lee, to create electronic docu.pdf
angelfragranc
 
The genotype of happy skipping smurf 2 – Hs hSSolutionThe ge.pdf
The genotype of happy skipping smurf 2 – Hs  hSSolutionThe ge.pdfThe genotype of happy skipping smurf 2 – Hs  hSSolutionThe ge.pdf
The genotype of happy skipping smurf 2 – Hs hSSolutionThe ge.pdf
angelfragranc
 
ans D because NO2 has higher priority and should.pdf
                     ans D because NO2 has higher priority and should.pdf                     ans D because NO2 has higher priority and should.pdf
ans D because NO2 has higher priority and should.pdf
angelfragranc
 
The objective of the above code is to define a phonebook entry in ja.pdf
The objective of the above code is to define a phonebook entry in ja.pdfThe objective of the above code is to define a phonebook entry in ja.pdf
The objective of the above code is to define a phonebook entry in ja.pdf
angelfragranc
 
A. He has a smaller radius than H because He has .pdf
                     A. He has a smaller radius than H because He has .pdf                     A. He has a smaller radius than H because He has .pdf
A. He has a smaller radius than H because He has .pdf
angelfragranc
 
standard deviation = 0Solutionstandard deviation = 0.pdf
standard deviation = 0Solutionstandard deviation = 0.pdfstandard deviation = 0Solutionstandard deviation = 0.pdf
standard deviation = 0Solutionstandard deviation = 0.pdf
angelfragranc
 
A transducer is a device, usually electrical, ele.pdf
                     A transducer is a device, usually electrical, ele.pdf                     A transducer is a device, usually electrical, ele.pdf
A transducer is a device, usually electrical, ele.pdf
angelfragranc
 

More from angelfragranc (20)

C ) common in nature, but commonly used psychological measures rare.pdf
 C ) common in nature, but commonly used psychological measures rare.pdf C ) common in nature, but commonly used psychological measures rare.pdf
C ) common in nature, but commonly used psychological measures rare.pdf
 
Question evidence 1. Comparison of DNA sequences among single-ce.pdf
    Question evidence   1. Comparison of DNA sequences among single-ce.pdf    Question evidence   1. Comparison of DNA sequences among single-ce.pdf
Question evidence 1. Comparison of DNA sequences among single-ce.pdf
 
The purpose of alchol (ethanol) is to dissolve io.pdf
                     The purpose of alchol (ethanol) is to dissolve io.pdf                     The purpose of alchol (ethanol) is to dissolve io.pdf
The purpose of alchol (ethanol) is to dissolve io.pdf
 
The components may not separate properly, because.pdf
                     The components may not separate properly, because.pdf                     The components may not separate properly, because.pdf
The components may not separate properly, because.pdf
 
The answer would be 5 because Dehydration in a .pdf
                     The answer would be 5 because  Dehydration in a .pdf                     The answer would be 5 because  Dehydration in a .pdf
The answer would be 5 because Dehydration in a .pdf
 
SO3 Sol.pdf
                     SO3                                       Sol.pdf                     SO3                                       Sol.pdf
SO3 Sol.pdf
 
Nucleophile is any negative ion or any neutral mo.pdf
                     Nucleophile is any negative ion or any neutral mo.pdf                     Nucleophile is any negative ion or any neutral mo.pdf
Nucleophile is any negative ion or any neutral mo.pdf
 
Moles of acid (HNO2) = Vol conc = 0.52 = 1 mol.pdf
                     Moles of acid (HNO2) = Vol  conc = 0.52 = 1 mol.pdf                     Moles of acid (HNO2) = Vol  conc = 0.52 = 1 mol.pdf
Moles of acid (HNO2) = Vol conc = 0.52 = 1 mol.pdf
 
it is a salt formed by KOH and HCl it is a neutra.pdf
                     it is a salt formed by KOH and HCl it is a neutra.pdf                     it is a salt formed by KOH and HCl it is a neutra.pdf
it is a salt formed by KOH and HCl it is a neutra.pdf
 
Cultural competence refers to an ability to inter.pdf
                     Cultural competence refers to an ability to inter.pdf                     Cultural competence refers to an ability to inter.pdf
Cultural competence refers to an ability to inter.pdf
 
Conformers can also be named as conformational is.pdf
                     Conformers can also be named as conformational is.pdf                     Conformers can also be named as conformational is.pdf
Conformers can also be named as conformational is.pdf
 
Cl S Se Solution Cl .pdf
                     Cl  S  Se  Solution                     Cl .pdf                     Cl  S  Se  Solution                     Cl .pdf
Cl S Se Solution Cl .pdf
 
benzene sulphonic acid - SO3H on benzene ring .pdf
                     benzene sulphonic acid  - SO3H on benzene ring   .pdf                     benzene sulphonic acid  - SO3H on benzene ring   .pdf
benzene sulphonic acid - SO3H on benzene ring .pdf
 
The HTML was developed by Tim Berners Lee, to create electronic docu.pdf
The HTML was developed by Tim Berners Lee, to create electronic docu.pdfThe HTML was developed by Tim Berners Lee, to create electronic docu.pdf
The HTML was developed by Tim Berners Lee, to create electronic docu.pdf
 
The genotype of happy skipping smurf 2 – Hs hSSolutionThe ge.pdf
The genotype of happy skipping smurf 2 – Hs  hSSolutionThe ge.pdfThe genotype of happy skipping smurf 2 – Hs  hSSolutionThe ge.pdf
The genotype of happy skipping smurf 2 – Hs hSSolutionThe ge.pdf
 
ans D because NO2 has higher priority and should.pdf
                     ans D because NO2 has higher priority and should.pdf                     ans D because NO2 has higher priority and should.pdf
ans D because NO2 has higher priority and should.pdf
 
The objective of the above code is to define a phonebook entry in ja.pdf
The objective of the above code is to define a phonebook entry in ja.pdfThe objective of the above code is to define a phonebook entry in ja.pdf
The objective of the above code is to define a phonebook entry in ja.pdf
 
A. He has a smaller radius than H because He has .pdf
                     A. He has a smaller radius than H because He has .pdf                     A. He has a smaller radius than H because He has .pdf
A. He has a smaller radius than H because He has .pdf
 
standard deviation = 0Solutionstandard deviation = 0.pdf
standard deviation = 0Solutionstandard deviation = 0.pdfstandard deviation = 0Solutionstandard deviation = 0.pdf
standard deviation = 0Solutionstandard deviation = 0.pdf
 
A transducer is a device, usually electrical, ele.pdf
                     A transducer is a device, usually electrical, ele.pdf                     A transducer is a device, usually electrical, ele.pdf
A transducer is a device, usually electrical, ele.pdf
 

Recently uploaded

writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
MysoreMuleSoftMeetup
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
HajraNaeem15
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
สมใจ จันสุกสี
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Leena Ghag-Sakpal
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
Himanshu Rai
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
spdendr
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 

Recently uploaded (20)

writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47Mule event processing models | MuleSoft Mysore Meetup #47
Mule event processing models | MuleSoft Mysore Meetup #47
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
How to deliver Powerpoint Presentations.pptx
How to deliver Powerpoint  Presentations.pptxHow to deliver Powerpoint  Presentations.pptx
How to deliver Powerpoint Presentations.pptx
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
คำศัพท์ คำพื้นฐานการอ่าน ภาษาอังกฤษ ระดับชั้น ม.1
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem studentsRHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
RHEOLOGY Physical pharmaceutics-II notes for B.pharm 4th sem students
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 

check the modifed code now you will get all operations done.termin.pdf

  • 1. check the modifed code now you will get all operations done. terminal will display add, subtract, multiply and div operation and dounday condition too. #include using namespace std; class Array { private: int start; int end; int *array; public: Array(int n); Array(int n, int m); int &operator[](int index); Array &operator=(Array a); bool operator==(Array &a); bool operator!=(Array &a); friend ostream &operator<<(ostream &out, Array &a); friend Array &operator+(Array &a, Array&b); friend Array &operator-(Array &a, Array&b); friend Array &operator*(Array &a, Array&b); friend Array &operator/(Array &a, Array&b); }; Array::Array(int n) { start = 0; end = n-1; array = new int[n]; for (int i = 0; i < n; i++) array[i] = i+1; } Array::Array(int n, int m) { start = n; end = m-1;
  • 2. array = new int[m-n]; for (int i = 0; i < m-n; i++) array[i] = start + i; } int &Array::operator[](int index) { if (index >= start && index <= end) { return (array[index-start]); } cout << "Error: Index out of bounds." << endl; int temp = 0; return temp; //return *array; } Array &Array::operator=(Array a) { start = a.start; end = a.end; for(int i = 0; i < end - start; ++i) { array[i] = a.array[i]; } return *this; } bool Array::operator==(Array &a) { for(int i = 0; i < end - start; ++i) { if(array[i] != a.array[i]) return false; } return true; } bool Array::operator!=(Array &a){ return *this == a;
  • 3. } ostream &operator<<(ostream &out, Array &b) { for(int i = 0; i < b.end - b.start; ++i) { out << "(" << i + b.start << ")" << b.array[i] << " "; } return out; } Array &operator+(Array &a, Array&b) { Array arr(a.end - a.start); for(int i = 0; i < a.end - a.start; ++i) { arr.array[i] = a.array[i] + b.array[i]; } return arr; } Array &operator-(Array &a, Array&b) { Array arr(a.end - a.start); for(int i = 0; i < a.end - a.start; ++i) { arr.array[i] = a.array[i] - b.array[i]; } return arr; } Array &operator*(Array &a, Array&b) { Array arr(a.end - a.start); for(int i = 0; i < a.end - a.start; ++i) { arr.array[i] = a.array[i] * b.array[i]; }
  • 4. return arr; } Array &operator/(Array &a, Array&b) { Array arr(a.end - a.start); for(int i = 0; i < a.end - a.start; ++i) { if (a.array[i]!=0) arr.array[i] = b.array[i] / a.array[i]; } return arr; } int main() { Array test(10); Array Ary1(10,25); Array Ary2(-5,10); Array Ary3(15,30); int i; int j; for (i = 0; i < 10; i++) test[i] = i+1; cout << "Test array output" << endl; for (i = 0; i < 10; i++) cout << test[i] << " "; cout << endl; i = -5; while (i < 10) { Ary2[i] = i*2;
  • 5. i++; } cout << " "; cout << "Ary2 array otuput" << endl; for (i = -5; i < 10; i++) cout << Ary2[i] << " "; cout << endl; i = 10; j = -5; while ( i < 25 ) { Ary1[ i ] = i*100; Ary2[j] = j * 200; i++; j++; }; cout << "Ary1 array output" << endl; cout << Ary1 << endl; cout << endl; cout << " "; cout << "Ary2 array output" << endl; cout << Ary2 << endl; cout << endl; cout << " "; for (i=0;i<14;i++) Ary3[i+15] = Ary1[i+10] + Ary2[i+-5]; cout << "Ary3 array Addition output" << endl; cout << Ary3 << endl; cout << " "; for (i=0;i<14;i++) Ary3[i+15] = Ary1[i+10] - Ary2[i+-5]; cout << "Ary3 array Subtraction output" << endl;
  • 6. cout << Ary3 << endl; cout << " "; for (i=0;i<14;i++) Ary3[i+15] = Ary1[i+10] * Ary2[i+-5]; cout << "Ary3 array Multiply output" << endl; cout << Ary3 << endl; cout << " "; for (i=0;i<14;i++) Ary3[i+15] = Ary2[i+-5]/Ary1[i+10]; cout << "Ary3 array Division output" << endl; cout << Ary3 << endl; cout << " "; cout << "Test boundary conditions" << endl; Ary1[8] = 100; Ary1[16] = 200; i = 100; cout << Ary1[i] << endl; return 0; } Solution check the modifed code now you will get all operations done. terminal will display add, subtract, multiply and div operation and dounday condition too. #include using namespace std; class Array { private: int start; int end; int *array; public: Array(int n);
  • 7. Array(int n, int m); int &operator[](int index); Array &operator=(Array a); bool operator==(Array &a); bool operator!=(Array &a); friend ostream &operator<<(ostream &out, Array &a); friend Array &operator+(Array &a, Array&b); friend Array &operator-(Array &a, Array&b); friend Array &operator*(Array &a, Array&b); friend Array &operator/(Array &a, Array&b); }; Array::Array(int n) { start = 0; end = n-1; array = new int[n]; for (int i = 0; i < n; i++) array[i] = i+1; } Array::Array(int n, int m) { start = n; end = m-1; array = new int[m-n]; for (int i = 0; i < m-n; i++) array[i] = start + i; } int &Array::operator[](int index) { if (index >= start && index <= end) { return (array[index-start]); } cout << "Error: Index out of bounds." << endl; int temp = 0; return temp;
  • 8. //return *array; } Array &Array::operator=(Array a) { start = a.start; end = a.end; for(int i = 0; i < end - start; ++i) { array[i] = a.array[i]; } return *this; } bool Array::operator==(Array &a) { for(int i = 0; i < end - start; ++i) { if(array[i] != a.array[i]) return false; } return true; } bool Array::operator!=(Array &a){ return *this == a; } ostream &operator<<(ostream &out, Array &b) { for(int i = 0; i < b.end - b.start; ++i) { out << "(" << i + b.start << ")" << b.array[i] << " "; } return out; } Array &operator+(Array &a, Array&b) { Array arr(a.end - a.start); for(int i = 0; i < a.end - a.start; ++i)
  • 9. { arr.array[i] = a.array[i] + b.array[i]; } return arr; } Array &operator-(Array &a, Array&b) { Array arr(a.end - a.start); for(int i = 0; i < a.end - a.start; ++i) { arr.array[i] = a.array[i] - b.array[i]; } return arr; } Array &operator*(Array &a, Array&b) { Array arr(a.end - a.start); for(int i = 0; i < a.end - a.start; ++i) { arr.array[i] = a.array[i] * b.array[i]; } return arr; } Array &operator/(Array &a, Array&b) { Array arr(a.end - a.start); for(int i = 0; i < a.end - a.start; ++i) { if (a.array[i]!=0) arr.array[i] = b.array[i] / a.array[i]; } return arr; }
  • 10. int main() { Array test(10); Array Ary1(10,25); Array Ary2(-5,10); Array Ary3(15,30); int i; int j; for (i = 0; i < 10; i++) test[i] = i+1; cout << "Test array output" << endl; for (i = 0; i < 10; i++) cout << test[i] << " "; cout << endl; i = -5; while (i < 10) { Ary2[i] = i*2; i++; } cout << " "; cout << "Ary2 array otuput" << endl; for (i = -5; i < 10; i++) cout << Ary2[i] << " "; cout << endl; i = 10; j = -5; while ( i < 25 ) { Ary1[ i ] = i*100;
  • 11. Ary2[j] = j * 200; i++; j++; }; cout << "Ary1 array output" << endl; cout << Ary1 << endl; cout << endl; cout << " "; cout << "Ary2 array output" << endl; cout << Ary2 << endl; cout << endl; cout << " "; for (i=0;i<14;i++) Ary3[i+15] = Ary1[i+10] + Ary2[i+-5]; cout << "Ary3 array Addition output" << endl; cout << Ary3 << endl; cout << " "; for (i=0;i<14;i++) Ary3[i+15] = Ary1[i+10] - Ary2[i+-5]; cout << "Ary3 array Subtraction output" << endl; cout << Ary3 << endl; cout << " "; for (i=0;i<14;i++) Ary3[i+15] = Ary1[i+10] * Ary2[i+-5]; cout << "Ary3 array Multiply output" << endl; cout << Ary3 << endl; cout << " "; for (i=0;i<14;i++) Ary3[i+15] = Ary2[i+-5]/Ary1[i+10]; cout << "Ary3 array Division output" << endl; cout << Ary3 << endl; cout << " ";
  • 12. cout << "Test boundary conditions" << endl; Ary1[8] = 100; Ary1[16] = 200; i = 100; cout << Ary1[i] << endl; return 0; }