SlideShare a Scribd company logo
#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)
{
int element;
if (index >= start && index <= end)
{
element=array[index-start];
}
else
{
cout << "Error: Index out of bounds." << endl;
element=-1;
}
int &p=element;
return p;
}
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];
}
Array &p=arr;
return p;
}
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];
}
Array &p=arr;
return p;
}
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];
}
Array &p=arr;
return p;
}
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] = b.array[i] / a.array[i];
}
Array &p=arr;
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 << " ";
Ary3 = Ary1 + Ary2;
cout << "Ary2 array Addition output" << endl;
cout << Ary3 << endl;
cout << " ";
Ary3 = Ary1 - Ary2;
cout << "Ary3 array Subtraction output" << endl;
cout << Ary3 << endl;
cout << " ";
Ary3 = Ary1 * Ary2;
cout << "Ary3 array Multiply output" << endl;
cout << Ary3 << endl;
cout << " ";
Ary3 = Ary1 / Ary2;
cout << "Ary3 array Division output" << endl;
cout << Ary3 << endl;
cout << " ";
cout << "Test boundary conditions" << endl;
Ary1[8] = 100;
Ary1[16] = 200;
i = 100;
cout <
Solution
#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)
{
int element;
if (index >= start && index <= end)
{
element=array[index-start];
}
else
{
cout << "Error: Index out of bounds." << endl;
element=-1;
}
int &p=element;
return p;
}
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];
}
Array &p=arr;
return p;
}
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];
}
Array &p=arr;
return p;
}
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];
}
Array &p=arr;
return p;
}
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] = b.array[i] / a.array[i];
}
Array &p=arr;
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 << " ";
Ary3 = Ary1 + Ary2;
cout << "Ary2 array Addition output" << endl;
cout << Ary3 << endl;
cout << " ";
Ary3 = Ary1 - Ary2;
cout << "Ary3 array Subtraction output" << endl;
cout << Ary3 << endl;
cout << " ";
Ary3 = Ary1 * Ary2;
cout << "Ary3 array Multiply output" << endl;
cout << Ary3 << endl;
cout << " ";
Ary3 = Ary1 / Ary2;
cout << "Ary3 array Division output" << endl;
cout << Ary3 << endl;
cout << " ";
cout << "Test boundary conditions" << endl;
Ary1[8] = 100;
Ary1[16] = 200;
i = 100;
cout <

More Related Content

Similar to #include iostream using namespace std; class Array { priva.pdf

Arrays matrix 2020 ab
Arrays matrix 2020 abArrays matrix 2020 ab
Arrays matrix 2020 ab
Dr .Ahmed Tawwab
 
Pointers and arrays
Pointers and arraysPointers and arrays
Pointers and arrays
Bhuvana Gowtham
 
Arrays
ArraysArrays
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.ppt
FareedIhsas
 
programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdf
sowmya koneru
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
piyush Kumar Sharma
 
#include stdio.h #include stdlib.h #include time.hdouble.pdf
#include stdio.h #include stdlib.h #include time.hdouble.pdf#include stdio.h #include stdlib.h #include time.hdouble.pdf
#include stdio.h #include stdlib.h #include time.hdouble.pdf
arjunchetri1
 
#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
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
Rahul Chugh
 
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
 
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
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
rohassanie
 
Sorting Technique
Sorting TechniqueSorting Technique
Sorting Technique
Salman Vadsarya
 
10. array & pointer
10. array & pointer10. array & pointer
10. array & pointer
웅식 전
 
Ada file
Ada fileAda file
Ada file
Kumar Gaurav
 
#include String.hpp#include ..Functionsfunctions.hpp.docx
#include String.hpp#include ..Functionsfunctions.hpp.docx#include String.hpp#include ..Functionsfunctions.hpp.docx
#include String.hpp#include ..Functionsfunctions.hpp.docx
gertrudebellgrove
 
Session 7 En
Session 7 EnSession 7 En
Session 7 En
guest91d2b3
 
Session 7 En
Session 7 EnSession 7 En
Session 7 En
SamQuiDaiBo
 
Array
ArrayArray
unit-2-dsa.pptx
unit-2-dsa.pptxunit-2-dsa.pptx
unit-2-dsa.pptx
sayalishivarkar1
 

Similar to #include iostream using namespace std; class Array { priva.pdf (20)

Arrays matrix 2020 ab
Arrays matrix 2020 abArrays matrix 2020 ab
Arrays matrix 2020 ab
 
Pointers and arrays
Pointers and arraysPointers and arrays
Pointers and arrays
 
Arrays
ArraysArrays
Arrays
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.ppt
 
programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdf
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
#include stdio.h #include stdlib.h #include time.hdouble.pdf
#include stdio.h #include stdlib.h #include time.hdouble.pdf#include stdio.h #include stdlib.h #include time.hdouble.pdf
#include stdio.h #include stdlib.h #include time.hdouble.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
#include stdio.h#include stdlib.h#include string.h#inclu.pdf
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
Object oriented programming; operator overloading array
Object oriented programming; operator overloading arrayObject oriented programming; operator overloading array
Object oriented programming; operator overloading array
 
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
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
Sorting Technique
Sorting TechniqueSorting Technique
Sorting Technique
 
10. array & pointer
10. array & pointer10. array & pointer
10. array & pointer
 
Ada file
Ada fileAda file
Ada file
 
#include String.hpp#include ..Functionsfunctions.hpp.docx
#include String.hpp#include ..Functionsfunctions.hpp.docx#include String.hpp#include ..Functionsfunctions.hpp.docx
#include String.hpp#include ..Functionsfunctions.hpp.docx
 
Session 7 En
Session 7 EnSession 7 En
Session 7 En
 
Session 7 En
Session 7 EnSession 7 En
Session 7 En
 
Array
ArrayArray
Array
 
unit-2-dsa.pptx
unit-2-dsa.pptxunit-2-dsa.pptx
unit-2-dsa.pptx
 

More from ANSAPPARELS

yes, roasting essentially means heating the ore, .pdf
                     yes, roasting essentially means heating the ore, .pdf                     yes, roasting essentially means heating the ore, .pdf
yes, roasting essentially means heating the ore, .pdf
ANSAPPARELS
 
There is no figure,Please upload it .pdf
                     There is no figure,Please upload it              .pdf                     There is no figure,Please upload it              .pdf
There is no figure,Please upload it .pdf
ANSAPPARELS
 
The adition is slow because the benzyne formed is.pdf
                     The adition is slow because the benzyne formed is.pdf                     The adition is slow because the benzyne formed is.pdf
The adition is slow because the benzyne formed is.pdf
ANSAPPARELS
 
only 1(I) .pdf
                     only 1(I)                                      .pdf                     only 1(I)                                      .pdf
only 1(I) .pdf
ANSAPPARELS
 
Yes, I do agree, that some eukaryotic cells survive only on the reso.pdf
Yes, I do agree, that some eukaryotic cells survive only on the reso.pdfYes, I do agree, that some eukaryotic cells survive only on the reso.pdf
Yes, I do agree, that some eukaryotic cells survive only on the reso.pdf
ANSAPPARELS
 
What are the key components of an internal audit What are the impli.pdf
What are the key components of an internal audit What are the impli.pdfWhat are the key components of an internal audit What are the impli.pdf
What are the key components of an internal audit What are the impli.pdf
ANSAPPARELS
 
IV I II III Solution .pdf
                     IV  I  II  III   Solution                 .pdf                     IV  I  II  III   Solution                 .pdf
IV I II III Solution .pdf
ANSAPPARELS
 
To differentiate between the mutated and normal genes, the DNA of th.pdf
To differentiate between the mutated and normal genes, the DNA of th.pdfTo differentiate between the mutated and normal genes, the DNA of th.pdf
To differentiate between the mutated and normal genes, the DNA of th.pdf
ANSAPPARELS
 
The most critical shortcomings of these assumptions are1.The flow .pdf
The most critical shortcomings of these assumptions are1.The flow .pdfThe most critical shortcomings of these assumptions are1.The flow .pdf
The most critical shortcomings of these assumptions are1.The flow .pdf
ANSAPPARELS
 
The following statements are true1. The tendency of water to mini.pdf
The following statements are true1. The tendency of water to mini.pdfThe following statements are true1. The tendency of water to mini.pdf
The following statements are true1. The tendency of water to mini.pdf
ANSAPPARELS
 
The data is Quantitative as there are numbers , and its an observati.pdf
The data is Quantitative as there are numbers , and its an observati.pdfThe data is Quantitative as there are numbers , and its an observati.pdf
The data is Quantitative as there are numbers , and its an observati.pdf
ANSAPPARELS
 
Thank you everyone! The answer was O(n!)SolutionThank you ever.pdf
Thank you everyone! The answer was O(n!)SolutionThank you ever.pdfThank you everyone! The answer was O(n!)SolutionThank you ever.pdf
Thank you everyone! The answer was O(n!)SolutionThank you ever.pdf
ANSAPPARELS
 
Solution1 ) The purpose of criminal law is to help maintain social.pdf
Solution1 ) The purpose of criminal law is to help maintain social.pdfSolution1 ) The purpose of criminal law is to help maintain social.pdf
Solution1 ) The purpose of criminal law is to help maintain social.pdf
ANSAPPARELS
 
question not visibleSolutionquestion not visible.pdf
question not visibleSolutionquestion not visible.pdfquestion not visibleSolutionquestion not visible.pdf
question not visibleSolutionquestion not visible.pdf
ANSAPPARELS
 
num.txt(Save this file under D Drive.Then the path of the file is D.pdf
num.txt(Save this file under D Drive.Then the path of the file is D.pdfnum.txt(Save this file under D Drive.Then the path of the file is D.pdf
num.txt(Save this file under D Drive.Then the path of the file is D.pdf
ANSAPPARELS
 
n = 7 which is odd so median is the middle value of te data after ar.pdf
n = 7 which is odd so median is the middle value of te data after ar.pdfn = 7 which is odd so median is the middle value of te data after ar.pdf
n = 7 which is odd so median is the middle value of te data after ar.pdf
ANSAPPARELS
 
Molybdenum is the elementSolutionMolybdenum is the element.pdf
Molybdenum is the elementSolutionMolybdenum is the element.pdfMolybdenum is the elementSolutionMolybdenum is the element.pdf
Molybdenum is the elementSolutionMolybdenum is the element.pdf
ANSAPPARELS
 
Mean absolute deviationSolutionMean absolute deviation.pdf
Mean absolute deviationSolutionMean absolute deviation.pdfMean absolute deviationSolutionMean absolute deviation.pdf
Mean absolute deviationSolutionMean absolute deviation.pdf
ANSAPPARELS
 
elements involved are C and N .pdf
                     elements involved are C and N                    .pdf                     elements involved are C and N                    .pdf
elements involved are C and N .pdf
ANSAPPARELS
 
Information security means protecting information (data) and informa.pdf
Information security means protecting information (data) and informa.pdfInformation security means protecting information (data) and informa.pdf
Information security means protecting information (data) and informa.pdf
ANSAPPARELS
 

More from ANSAPPARELS (20)

yes, roasting essentially means heating the ore, .pdf
                     yes, roasting essentially means heating the ore, .pdf                     yes, roasting essentially means heating the ore, .pdf
yes, roasting essentially means heating the ore, .pdf
 
There is no figure,Please upload it .pdf
                     There is no figure,Please upload it              .pdf                     There is no figure,Please upload it              .pdf
There is no figure,Please upload it .pdf
 
The adition is slow because the benzyne formed is.pdf
                     The adition is slow because the benzyne formed is.pdf                     The adition is slow because the benzyne formed is.pdf
The adition is slow because the benzyne formed is.pdf
 
only 1(I) .pdf
                     only 1(I)                                      .pdf                     only 1(I)                                      .pdf
only 1(I) .pdf
 
Yes, I do agree, that some eukaryotic cells survive only on the reso.pdf
Yes, I do agree, that some eukaryotic cells survive only on the reso.pdfYes, I do agree, that some eukaryotic cells survive only on the reso.pdf
Yes, I do agree, that some eukaryotic cells survive only on the reso.pdf
 
What are the key components of an internal audit What are the impli.pdf
What are the key components of an internal audit What are the impli.pdfWhat are the key components of an internal audit What are the impli.pdf
What are the key components of an internal audit What are the impli.pdf
 
IV I II III Solution .pdf
                     IV  I  II  III   Solution                 .pdf                     IV  I  II  III   Solution                 .pdf
IV I II III Solution .pdf
 
To differentiate between the mutated and normal genes, the DNA of th.pdf
To differentiate between the mutated and normal genes, the DNA of th.pdfTo differentiate between the mutated and normal genes, the DNA of th.pdf
To differentiate between the mutated and normal genes, the DNA of th.pdf
 
The most critical shortcomings of these assumptions are1.The flow .pdf
The most critical shortcomings of these assumptions are1.The flow .pdfThe most critical shortcomings of these assumptions are1.The flow .pdf
The most critical shortcomings of these assumptions are1.The flow .pdf
 
The following statements are true1. The tendency of water to mini.pdf
The following statements are true1. The tendency of water to mini.pdfThe following statements are true1. The tendency of water to mini.pdf
The following statements are true1. The tendency of water to mini.pdf
 
The data is Quantitative as there are numbers , and its an observati.pdf
The data is Quantitative as there are numbers , and its an observati.pdfThe data is Quantitative as there are numbers , and its an observati.pdf
The data is Quantitative as there are numbers , and its an observati.pdf
 
Thank you everyone! The answer was O(n!)SolutionThank you ever.pdf
Thank you everyone! The answer was O(n!)SolutionThank you ever.pdfThank you everyone! The answer was O(n!)SolutionThank you ever.pdf
Thank you everyone! The answer was O(n!)SolutionThank you ever.pdf
 
Solution1 ) The purpose of criminal law is to help maintain social.pdf
Solution1 ) The purpose of criminal law is to help maintain social.pdfSolution1 ) The purpose of criminal law is to help maintain social.pdf
Solution1 ) The purpose of criminal law is to help maintain social.pdf
 
question not visibleSolutionquestion not visible.pdf
question not visibleSolutionquestion not visible.pdfquestion not visibleSolutionquestion not visible.pdf
question not visibleSolutionquestion not visible.pdf
 
num.txt(Save this file under D Drive.Then the path of the file is D.pdf
num.txt(Save this file under D Drive.Then the path of the file is D.pdfnum.txt(Save this file under D Drive.Then the path of the file is D.pdf
num.txt(Save this file under D Drive.Then the path of the file is D.pdf
 
n = 7 which is odd so median is the middle value of te data after ar.pdf
n = 7 which is odd so median is the middle value of te data after ar.pdfn = 7 which is odd so median is the middle value of te data after ar.pdf
n = 7 which is odd so median is the middle value of te data after ar.pdf
 
Molybdenum is the elementSolutionMolybdenum is the element.pdf
Molybdenum is the elementSolutionMolybdenum is the element.pdfMolybdenum is the elementSolutionMolybdenum is the element.pdf
Molybdenum is the elementSolutionMolybdenum is the element.pdf
 
Mean absolute deviationSolutionMean absolute deviation.pdf
Mean absolute deviationSolutionMean absolute deviation.pdfMean absolute deviationSolutionMean absolute deviation.pdf
Mean absolute deviationSolutionMean absolute deviation.pdf
 
elements involved are C and N .pdf
                     elements involved are C and N                    .pdf                     elements involved are C and N                    .pdf
elements involved are C and N .pdf
 
Information security means protecting information (data) and informa.pdf
Information security means protecting information (data) and informa.pdfInformation security means protecting information (data) and informa.pdf
Information security means protecting information (data) and informa.pdf
 

Recently uploaded

Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
 
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
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
National Information Standards Organization (NISO)
 
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
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
melliereed
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
 
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
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
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)

Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
 
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...
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
 
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
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
 
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
 
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
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
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
 

#include iostream using namespace std; class Array { priva.pdf

  • 1. #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++)
  • 2. array[i] = start + i; } int &Array::operator[](int index) { int element; if (index >= start && index <= end) { element=array[index-start]; } else { cout << "Error: Index out of bounds." << endl; element=-1; } int &p=element; return p; } 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; }
  • 3. 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]; } Array &p=arr; return p; } 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]; } Array &p=arr; return p; } Array &operator*(Array &a, Array&b) { Array arr(a.end - a.start); for(int i = 0; i < a.end - a.start; ++i) {
  • 4. arr.array[i] = a.array[i] * b.array[i]; } Array &p=arr; return p; } 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] = b.array[i] / a.array[i]; } Array &p=arr; 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)
  • 5. { 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 << " "; Ary3 = Ary1 + Ary2; cout << "Ary2 array Addition output" << endl; cout << Ary3 << endl; cout << " "; Ary3 = Ary1 - Ary2; cout << "Ary3 array Subtraction output" << endl; cout << Ary3 << endl; cout << " ";
  • 6. Ary3 = Ary1 * Ary2; cout << "Ary3 array Multiply output" << endl; cout << Ary3 << endl; cout << " "; Ary3 = Ary1 / Ary2; cout << "Ary3 array Division output" << endl; cout << Ary3 << endl; cout << " "; cout << "Test boundary conditions" << endl; Ary1[8] = 100; Ary1[16] = 200; i = 100; cout < Solution #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);
  • 7. 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) { int element; if (index >= start && index <= end) { element=array[index-start]; } else { cout << "Error: Index out of bounds." << endl; element=-1; } int &p=element; return p; } Array &Array::operator=(Array a) { start = a.start;
  • 8. 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]; } Array &p=arr; return p;
  • 9. } 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]; } Array &p=arr; return p; } 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]; } Array &p=arr; return p; } 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] = b.array[i] / a.array[i]; } Array &p=arr; return arr; } int main() { Array test(10); Array Ary1(10,25); Array Ary2(-5,10);
  • 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++; };
  • 11. cout << "Ary1 array output" << endl; cout << Ary1 << endl; cout << endl; cout << " "; Ary3 = Ary1 + Ary2; cout << "Ary2 array Addition output" << endl; cout << Ary3 << endl; cout << " "; Ary3 = Ary1 - Ary2; cout << "Ary3 array Subtraction output" << endl; cout << Ary3 << endl; cout << " "; Ary3 = Ary1 * Ary2; cout << "Ary3 array Multiply output" << endl; cout << Ary3 << endl; cout << " "; Ary3 = Ary1 / Ary2; cout << "Ary3 array Division output" << endl; cout << Ary3 << endl; cout << " "; cout << "Test boundary conditions" << endl; Ary1[8] = 100; Ary1[16] = 200; i = 100; cout <