SlideShare a Scribd company logo
1 of 11
Download to read offline
#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

SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.pptFareedIhsas
 
programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdfsowmya koneru
 
#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.pdfarjunchetri1
 
#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.pdfapleather
 
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 arraySyed 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.pptxJumanneChiyanda
 
10. array & pointer
10. array & pointer10. array & pointer
10. array & pointer웅식 전
 
#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.docxgertrudebellgrove
 

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, .pdfANSAPPARELS
 
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 .pdfANSAPPARELS
 
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.pdfANSAPPARELS
 
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.pdfANSAPPARELS
 
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.pdfANSAPPARELS
 
IV I II III Solution .pdf
                     IV  I  II  III   Solution                 .pdf                     IV  I  II  III   Solution                 .pdf
IV I II III Solution .pdfANSAPPARELS
 
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.pdfANSAPPARELS
 
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 .pdfANSAPPARELS
 
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.pdfANSAPPARELS
 
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.pdfANSAPPARELS
 
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.pdfANSAPPARELS
 
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.pdfANSAPPARELS
 
question not visibleSolutionquestion not visible.pdf
question not visibleSolutionquestion not visible.pdfquestion not visibleSolutionquestion not visible.pdf
question not visibleSolutionquestion not visible.pdfANSAPPARELS
 
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.pdfANSAPPARELS
 
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.pdfANSAPPARELS
 
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.pdfANSAPPARELS
 
Mean absolute deviationSolutionMean absolute deviation.pdf
Mean absolute deviationSolutionMean absolute deviation.pdfMean absolute deviationSolutionMean absolute deviation.pdf
Mean absolute deviationSolutionMean absolute deviation.pdfANSAPPARELS
 
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 .pdfANSAPPARELS
 
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.pdfANSAPPARELS
 

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

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdfssuserdda66b
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 

Recently uploaded (20)

UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

#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 <