SlideShare a Scribd company logo
1 of 2
Download to read offline
Program must be written in C++
Define a class named CheckedArray. The objects of this class are like regular arrays but have
range checking. If a is an object of the class CheckedArray and i is an illegal index, then use of
a[i] will cause your program to throw an exception (an object) of the class
ArrayOutOfRangeError. Defining the class ArrayOutOfRangeError is part of this project. Note
that, among other things, your CheckedArray class must have a suitable overloading of the
[]operators, as discussed in Appendix 6. Appendix 6: You can overload the square brackets, [],
for a class so that they can be used with objects of the class. If you want to use [] in an
expression on the left-hand side of an assignment operator, then the operator must be defined to
return a reference, which is indicated by adding & to the returned type. (This has some similarity
to what we discussed for overloading the I/O operators << and >>.) When overloading [], the
operator [] must be a member function; the overloaded [] cannot be a friend operator. (in this
regard, [] is overloaded in a way similar to the way in which the assignment operator = is
overloaded; overloading = is discussed in the section of Chapter 11 entitled “Overloading the
Assignment Operator.―) For example, the following defines a class called Pair whose objects
behave like arrays of characters with the two indexes 1 and 2 (not 0 and 1): Class Pair { public:
Pair(); Pair(char first_value, char second_value); char& operator[] (int index); private: char first;
char second; }; The definition of the member function [] can be as follows: char &
Pair::operator[] (int index) { if (index == 1) return first; else if (index == 2) return second; else {
cout << “Illegal index value. ―; exit(1); } } Objects are declared and used as follows: Pair
a; a[1] = ‘A’ ; a[2] = ‘B’ ; cout << a[i] << a[2] << endl; Note that in a[1], a is is the
calling object and 1 is the argument to the member function [].
Solution
class ArrayOutOfRangeError{
};
template<class elemType>
class CheckedArray
{
public:
explicit CheckedArray(int size = DefaultArraySize);
CheckedArray(elemType *array,int array_size);
CheckedArray(const CheckedArray &rhs);
~CheckedArray(){ delete [] ia; }
elemType operator[](int index);
private:
static const int DefaultArraySize = 10;
int _size;
elemType *ia;
};

More Related Content

Similar to Program must be written in C++ Define a class named CheckedArray- The.docx

Functional Objects & Function and Closures
Functional Objects  & Function and ClosuresFunctional Objects  & Function and Closures
Functional Objects & Function and ClosuresSandip Kumar
 
ScalaLanguage_ch_4_5.pptx
ScalaLanguage_ch_4_5.pptxScalaLanguage_ch_4_5.pptx
ScalaLanguage_ch_4_5.pptxjkapardhi
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)SURBHI SAROHA
 
Lec 28 - operator overloading
Lec 28 - operator overloadingLec 28 - operator overloading
Lec 28 - operator overloadingPrincess Sam
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfajajkhan16
 
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxAssg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxfestockton
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notesGOKULKANNANMMECLECTC
 
Operator overloading
Operator overloadingOperator overloading
Operator overloadingBurhan Ahmed
 
Operator oveerloading
Operator oveerloadingOperator oveerloading
Operator oveerloadingyatinnarula
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in Carshpreetkaur07
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxdunhamadell
 
operator overloading
operator overloadingoperator overloading
operator overloadingNishant Joshi
 
Synapse india complain sharing info on chapter 8 operator overloading
Synapse india complain sharing info on chapter 8   operator overloadingSynapse india complain sharing info on chapter 8   operator overloading
Synapse india complain sharing info on chapter 8 operator overloadingSynapseindiaComplaints
 

Similar to Program must be written in C++ Define a class named CheckedArray- The.docx (20)

Functions1
Functions1Functions1
Functions1
 
Scala oo (1)
Scala oo (1)Scala oo (1)
Scala oo (1)
 
Functional Objects & Function and Closures
Functional Objects  & Function and ClosuresFunctional Objects  & Function and Closures
Functional Objects & Function and Closures
 
Functions
FunctionsFunctions
Functions
 
ScalaLanguage_ch_4_5.pptx
ScalaLanguage_ch_4_5.pptxScalaLanguage_ch_4_5.pptx
ScalaLanguage_ch_4_5.pptx
 
MA3696 Lecture 9
MA3696 Lecture 9MA3696 Lecture 9
MA3696 Lecture 9
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
Lec 28 - operator overloading
Lec 28 - operator overloadingLec 28 - operator overloading
Lec 28 - operator overloading
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
 
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docxAssg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
Assg 07 Templates and Operator OverloadingCOSC 2336 Sprin.docx
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Arrays
ArraysArrays
Arrays
 
Operator oveerloading
Operator oveerloadingOperator oveerloading
Operator oveerloading
 
25-functions.ppt
25-functions.ppt25-functions.ppt
25-functions.ppt
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
 
Objectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docxObjectives Assignment 09 Applications of Stacks COS.docx
Objectives Assignment 09 Applications of Stacks COS.docx
 
operator overloading
operator overloadingoperator overloading
operator overloading
 
Chap 5 c++
Chap 5 c++Chap 5 c++
Chap 5 c++
 
Synapse india complain sharing info on chapter 8 operator overloading
Synapse india complain sharing info on chapter 8   operator overloadingSynapse india complain sharing info on chapter 8   operator overloading
Synapse india complain sharing info on chapter 8 operator overloading
 

More from todd921

Question 1 2 points Save Team building is designed to gather.docx
Question 1  2  points    Save    Team  building is designed to gather.docxQuestion 1  2  points    Save    Team  building is designed to gather.docx
Question 1 2 points Save Team building is designed to gather.docxtodd921
 
Question 21 2 points Save How do training and development with.docx
Question  21  2 points   Save    How do training and development with.docxQuestion  21  2 points   Save    How do training and development with.docx
Question 21 2 points Save How do training and development with.docxtodd921
 
QS# 2- 9-17 What is the difference between a note payable and an accou.docx
QS# 2- 9-17 What is the difference between a note payable and an accou.docxQS# 2- 9-17 What is the difference between a note payable and an accou.docx
QS# 2- 9-17 What is the difference between a note payable and an accou.docxtodd921
 
Q1) Prepare the year end closing entries for eagles corp- Q2) what is.docx
Q1) Prepare the year end closing entries for eagles corp- Q2) what is.docxQ1) Prepare the year end closing entries for eagles corp- Q2) what is.docx
Q1) Prepare the year end closing entries for eagles corp- Q2) what is.docxtodd921
 
Q- Lord Rutherford found that most of an atom consists of empty space-.docx
Q- Lord Rutherford found that most of an atom consists of empty space-.docxQ- Lord Rutherford found that most of an atom consists of empty space-.docx
Q- Lord Rutherford found that most of an atom consists of empty space-.docxtodd921
 
PYTHON Programming Language Design a class named Account that contains.docx
PYTHON Programming Language Design a class named Account that contains.docxPYTHON Programming Language Design a class named Account that contains.docx
PYTHON Programming Language Design a class named Account that contains.docxtodd921
 
Purchases Date Units Unit Cost Sales Units Average cost for each unit.docx
Purchases Date Units Unit Cost Sales Units Average cost for each unit.docxPurchases Date Units Unit Cost Sales Units Average cost for each unit.docx
Purchases Date Units Unit Cost Sales Units Average cost for each unit.docxtodd921
 
Provide examples of applications that typically access files according.docx
Provide examples of applications that typically access files according.docxProvide examples of applications that typically access files according.docx
Provide examples of applications that typically access files according.docxtodd921
 
Provide copy constructor- destructor- and assignment operator for the.docx
Provide copy constructor- destructor- and assignment operator for the.docxProvide copy constructor- destructor- and assignment operator for the.docx
Provide copy constructor- destructor- and assignment operator for the.docxtodd921
 
Provide a summary of the basic ideals and significant individuals behi.docx
Provide a summary of the basic ideals and significant individuals behi.docxProvide a summary of the basic ideals and significant individuals behi.docx
Provide a summary of the basic ideals and significant individuals behi.docxtodd921
 
proposed solution to resource sharing and security against unauthorize.docx
proposed solution to resource sharing and security against unauthorize.docxproposed solution to resource sharing and security against unauthorize.docx
proposed solution to resource sharing and security against unauthorize.docxtodd921
 
Programming Language- C++ or Java Write to program to generate a pair.docx
Programming Language- C++ or Java Write to program to generate a pair.docxProgramming Language- C++ or Java Write to program to generate a pair.docx
Programming Language- C++ or Java Write to program to generate a pair.docxtodd921
 
Question 30 As people become more powerful they tend to become less go.docx
Question 30 As people become more powerful they tend to become less go.docxQuestion 30 As people become more powerful they tend to become less go.docx
Question 30 As people become more powerful they tend to become less go.docxtodd921
 
Question 34 People with high Machiavellian values tend to- place a lot.docx
Question 34 People with high Machiavellian values tend to- place a lot.docxQuestion 34 People with high Machiavellian values tend to- place a lot.docx
Question 34 People with high Machiavellian values tend to- place a lot.docxtodd921
 
Question 21 Resource scarcity is a likely cause of conflict in organiz.docx
Question 21 Resource scarcity is a likely cause of conflict in organiz.docxQuestion 21 Resource scarcity is a likely cause of conflict in organiz.docx
Question 21 Resource scarcity is a likely cause of conflict in organiz.docxtodd921
 
Question 2 Compare the eye to a camera by listing four of the basic co.docx
Question 2 Compare the eye to a camera by listing four of the basic co.docxQuestion 2 Compare the eye to a camera by listing four of the basic co.docx
Question 2 Compare the eye to a camera by listing four of the basic co.docxtodd921
 
Question 1- The alien species has decided that they will use a special.docx
Question 1- The alien species has decided that they will use a special.docxQuestion 1- The alien species has decided that they will use a special.docx
Question 1- The alien species has decided that they will use a special.docxtodd921
 
Question 13 Which of the following is the first stage of an experienti.docx
Question 13 Which of the following is the first stage of an experienti.docxQuestion 13 Which of the following is the first stage of an experienti.docx
Question 13 Which of the following is the first stage of an experienti.docxtodd921
 
Question 11 Active communication occurs by facial expressions- body po.docx
Question 11 Active communication occurs by facial expressions- body po.docxQuestion 11 Active communication occurs by facial expressions- body po.docx
Question 11 Active communication occurs by facial expressions- body po.docxtodd921
 
QUESTION 1 Interaction Design is designing interactive products to sup.docx
QUESTION 1 Interaction Design is designing interactive products to sup.docxQUESTION 1 Interaction Design is designing interactive products to sup.docx
QUESTION 1 Interaction Design is designing interactive products to sup.docxtodd921
 

More from todd921 (20)

Question 1 2 points Save Team building is designed to gather.docx
Question 1  2  points    Save    Team  building is designed to gather.docxQuestion 1  2  points    Save    Team  building is designed to gather.docx
Question 1 2 points Save Team building is designed to gather.docx
 
Question 21 2 points Save How do training and development with.docx
Question  21  2 points   Save    How do training and development with.docxQuestion  21  2 points   Save    How do training and development with.docx
Question 21 2 points Save How do training and development with.docx
 
QS# 2- 9-17 What is the difference between a note payable and an accou.docx
QS# 2- 9-17 What is the difference between a note payable and an accou.docxQS# 2- 9-17 What is the difference between a note payable and an accou.docx
QS# 2- 9-17 What is the difference between a note payable and an accou.docx
 
Q1) Prepare the year end closing entries for eagles corp- Q2) what is.docx
Q1) Prepare the year end closing entries for eagles corp- Q2) what is.docxQ1) Prepare the year end closing entries for eagles corp- Q2) what is.docx
Q1) Prepare the year end closing entries for eagles corp- Q2) what is.docx
 
Q- Lord Rutherford found that most of an atom consists of empty space-.docx
Q- Lord Rutherford found that most of an atom consists of empty space-.docxQ- Lord Rutherford found that most of an atom consists of empty space-.docx
Q- Lord Rutherford found that most of an atom consists of empty space-.docx
 
PYTHON Programming Language Design a class named Account that contains.docx
PYTHON Programming Language Design a class named Account that contains.docxPYTHON Programming Language Design a class named Account that contains.docx
PYTHON Programming Language Design a class named Account that contains.docx
 
Purchases Date Units Unit Cost Sales Units Average cost for each unit.docx
Purchases Date Units Unit Cost Sales Units Average cost for each unit.docxPurchases Date Units Unit Cost Sales Units Average cost for each unit.docx
Purchases Date Units Unit Cost Sales Units Average cost for each unit.docx
 
Provide examples of applications that typically access files according.docx
Provide examples of applications that typically access files according.docxProvide examples of applications that typically access files according.docx
Provide examples of applications that typically access files according.docx
 
Provide copy constructor- destructor- and assignment operator for the.docx
Provide copy constructor- destructor- and assignment operator for the.docxProvide copy constructor- destructor- and assignment operator for the.docx
Provide copy constructor- destructor- and assignment operator for the.docx
 
Provide a summary of the basic ideals and significant individuals behi.docx
Provide a summary of the basic ideals and significant individuals behi.docxProvide a summary of the basic ideals and significant individuals behi.docx
Provide a summary of the basic ideals and significant individuals behi.docx
 
proposed solution to resource sharing and security against unauthorize.docx
proposed solution to resource sharing and security against unauthorize.docxproposed solution to resource sharing and security against unauthorize.docx
proposed solution to resource sharing and security against unauthorize.docx
 
Programming Language- C++ or Java Write to program to generate a pair.docx
Programming Language- C++ or Java Write to program to generate a pair.docxProgramming Language- C++ or Java Write to program to generate a pair.docx
Programming Language- C++ or Java Write to program to generate a pair.docx
 
Question 30 As people become more powerful they tend to become less go.docx
Question 30 As people become more powerful they tend to become less go.docxQuestion 30 As people become more powerful they tend to become less go.docx
Question 30 As people become more powerful they tend to become less go.docx
 
Question 34 People with high Machiavellian values tend to- place a lot.docx
Question 34 People with high Machiavellian values tend to- place a lot.docxQuestion 34 People with high Machiavellian values tend to- place a lot.docx
Question 34 People with high Machiavellian values tend to- place a lot.docx
 
Question 21 Resource scarcity is a likely cause of conflict in organiz.docx
Question 21 Resource scarcity is a likely cause of conflict in organiz.docxQuestion 21 Resource scarcity is a likely cause of conflict in organiz.docx
Question 21 Resource scarcity is a likely cause of conflict in organiz.docx
 
Question 2 Compare the eye to a camera by listing four of the basic co.docx
Question 2 Compare the eye to a camera by listing four of the basic co.docxQuestion 2 Compare the eye to a camera by listing four of the basic co.docx
Question 2 Compare the eye to a camera by listing four of the basic co.docx
 
Question 1- The alien species has decided that they will use a special.docx
Question 1- The alien species has decided that they will use a special.docxQuestion 1- The alien species has decided that they will use a special.docx
Question 1- The alien species has decided that they will use a special.docx
 
Question 13 Which of the following is the first stage of an experienti.docx
Question 13 Which of the following is the first stage of an experienti.docxQuestion 13 Which of the following is the first stage of an experienti.docx
Question 13 Which of the following is the first stage of an experienti.docx
 
Question 11 Active communication occurs by facial expressions- body po.docx
Question 11 Active communication occurs by facial expressions- body po.docxQuestion 11 Active communication occurs by facial expressions- body po.docx
Question 11 Active communication occurs by facial expressions- body po.docx
 
QUESTION 1 Interaction Design is designing interactive products to sup.docx
QUESTION 1 Interaction Design is designing interactive products to sup.docxQUESTION 1 Interaction Design is designing interactive products to sup.docx
QUESTION 1 Interaction Design is designing interactive products to sup.docx
 

Recently uploaded

CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxAnupam32727
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
Employablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxEmployablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxryandux83rd
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEPART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEMISSRITIMABIOLOGYEXP
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
Shark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristicsShark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristicsArubSultan
 
How to Uninstall a Module in Odoo 17 Using Command Line
How to Uninstall a Module in Odoo 17 Using Command LineHow to Uninstall a Module in Odoo 17 Using Command Line
How to Uninstall a Module in Odoo 17 Using Command LineCeline George
 
6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroomSamsung Business USA
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQuiz Club NITW
 
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...Osopher
 
Objectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptxObjectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptxMadhavi Dharankar
 

Recently uploaded (20)

CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptxCLASSIFICATION OF ANTI - CANCER DRUGS.pptx
CLASSIFICATION OF ANTI - CANCER DRUGS.pptx
 
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
Plagiarism,forms,understand about plagiarism,avoid plagiarism,key significanc...
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
Employablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptxEmployablity presentation and Future Career Plan.pptx
Employablity presentation and Future Career Plan.pptx
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
Spearman's correlation,Formula,Advantages,
Spearman's correlation,Formula,Advantages,Spearman's correlation,Formula,Advantages,
Spearman's correlation,Formula,Advantages,
 
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFEPART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
PART 1 - CHAPTER 1 - CELL THE FUNDAMENTAL UNIT OF LIFE
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
Shark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristicsShark introduction Morphology and its behaviour characteristics
Shark introduction Morphology and its behaviour characteristics
 
How to Uninstall a Module in Odoo 17 Using Command Line
How to Uninstall a Module in Odoo 17 Using Command LineHow to Uninstall a Module in Odoo 17 Using Command Line
How to Uninstall a Module in Odoo 17 Using Command Line
 
prashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Professionprashanth updated resume 2024 for Teaching Profession
prashanth updated resume 2024 for Teaching Profession
 
6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom6 ways Samsung’s Interactive Display powered by Android changes the classroom
6 ways Samsung’s Interactive Display powered by Android changes the classroom
 
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITWQ-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
Q-Factor HISPOL Quiz-6th April 2024, Quiz Club NITW
 
CARNAVAL COM MAGIA E EUFORIA _
CARNAVAL COM MAGIA E EUFORIA            _CARNAVAL COM MAGIA E EUFORIA            _
CARNAVAL COM MAGIA E EUFORIA _
 
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
Healthy Minds, Flourishing Lives: A Philosophical Approach to Mental Health a...
 
Objectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptxObjectives n learning outcoms - MD 20240404.pptx
Objectives n learning outcoms - MD 20240404.pptx
 
Chi-Square Test Non Parametric Test Categorical Variable
Chi-Square Test Non Parametric Test Categorical VariableChi-Square Test Non Parametric Test Categorical Variable
Chi-Square Test Non Parametric Test Categorical Variable
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 

Program must be written in C++ Define a class named CheckedArray- The.docx

  • 1. Program must be written in C++ Define a class named CheckedArray. The objects of this class are like regular arrays but have range checking. If a is an object of the class CheckedArray and i is an illegal index, then use of a[i] will cause your program to throw an exception (an object) of the class ArrayOutOfRangeError. Defining the class ArrayOutOfRangeError is part of this project. Note that, among other things, your CheckedArray class must have a suitable overloading of the []operators, as discussed in Appendix 6. Appendix 6: You can overload the square brackets, [], for a class so that they can be used with objects of the class. If you want to use [] in an expression on the left-hand side of an assignment operator, then the operator must be defined to return a reference, which is indicated by adding & to the returned type. (This has some similarity to what we discussed for overloading the I/O operators << and >>.) When overloading [], the operator [] must be a member function; the overloaded [] cannot be a friend operator. (in this regard, [] is overloaded in a way similar to the way in which the assignment operator = is overloaded; overloading = is discussed in the section of Chapter 11 entitled “Overloading the Assignment Operator.―) For example, the following defines a class called Pair whose objects behave like arrays of characters with the two indexes 1 and 2 (not 0 and 1): Class Pair { public: Pair(); Pair(char first_value, char second_value); char& operator[] (int index); private: char first; char second; }; The definition of the member function [] can be as follows: char & Pair::operator[] (int index) { if (index == 1) return first; else if (index == 2) return second; else { cout << “Illegal index value. ―; exit(1); } } Objects are declared and used as follows: Pair a; a[1] = ‘A’ ; a[2] = ‘B’ ; cout << a[i] << a[2] << endl; Note that in a[1], a is is the calling object and 1 is the argument to the member function []. Solution class ArrayOutOfRangeError{ }; template<class elemType> class CheckedArray { public: explicit CheckedArray(int size = DefaultArraySize); CheckedArray(elemType *array,int array_size);
  • 2. CheckedArray(const CheckedArray &rhs); ~CheckedArray(){ delete [] ia; } elemType operator[](int index); private: static const int DefaultArraySize = 10; int _size; elemType *ia; };