SlideShare a Scribd company logo
1 of 4
Download to read offline
The one that was previously posted on here does not compile or function as intended.
Change struct to class
Make all the members private
Add get_size , get_capacity and get_array methods
Add remove, index_of and operator+ methods
Add oprator< method, and together with other five ( > , >= , <= , == , != )
Complete and debug all the other methods in the sample code, such as insert
Write some testing code in the main function
Code template:
#include <iostream>
using namespace std;
struct Vec
{
int _size;
int _cap;
int* arr;
Vec()
{
_size = 0;
_cap = 4;
arr = new int[_cap];
}
void insert( int n, int x )
{
for ( int i = _size-1; i >= n; i-- )
{
arr[i+1] = arr[i];
}
arr[n] = x;
_size++;
}
void reserve( int new_cap )
{
if ( new_cap > _cap )
{
_cap = new_cap;
int *tmp = new int[_cap];
for ( int i = 0; i < _size; i++ )
{
tmp[i] = arr[i];
}
delete[] arr;
arr = tmp;
}
}
void push_back( int x )
{
if ( _size == _cap )
{
_cap *= 2;
reserve(_cap);
}
arr[_size++] = x;
}
void pop() {
if (_size > 0) _size--;
}
int& at( int idx )
{
if ( idx >= _size || idx < 0 )
{
throw "[Vector] Index out of bound!";
}
return arr[idx];
}
int& operator[]( int idx )
{
if ( idx >= _size || idx < 0 )
{
throw "[Vector] Index out of bound!";
}
return arr[idx];
}
~Vec()
{
delete[] arr;
}
};
ostream& operator<<(ostream& os, Vec& v)
{
os << "[ ";
for ( int i = 0; i < v._size-1; i++ )
{
os << v.arr[i] << ", ";
}
os << v.arr[v._size-1] << " ]";
return os;
}
int main()
{
Vec v;
v.push_back(3);
v.push_back(1);
v.push_back(4);
v.push_back(2);
v.push_back(8);
//v.insert(1, 7);
v[3] = 5;
cout << v[3] << endl;
//v.at(3) = 5;
cout << v << endl;
//cout << v._cap << endl;
//v.reserve(20);
//cout << v._cap << endl;
//cout << v << endl;
//cout << v._size << endl;
//cout << v._cap << endl;
return 0;
}
The one that was previously posted on here does not compile or functio.pdf

More Related Content

Similar to The one that was previously posted on here does not compile or functio.pdf

I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfshreeaadithyaacellso
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical fileMitul Patel
 
Lecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxLecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxarjurakibulhasanrrr7
 
Computer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsComputer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsVishvjeet Yadav
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...MaruMengesha
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for SpeedYung-Yu Chen
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical filePranav Ghildiyal
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfyamew16788
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2YOGESH SINGH
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings imtiazalijoono
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and PolynomialAroosa Rajput
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfChen-Hung Hu
 

Similar to The one that was previously posted on here does not compile or functio.pdf (20)

I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
 
Java arrays
Java    arraysJava    arrays
Java arrays
 
array2d.ppt
array2d.pptarray2d.ppt
array2d.ppt
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
 
Lecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxLecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptx
 
Computer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commandsComputer Science Practical Science C++ with SQL commands
Computer Science Practical Science C++ with SQL commands
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
Chp4(ref dynamic)
Chp4(ref dynamic)Chp4(ref dynamic)
Chp4(ref dynamic)
 
ParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdfParallelProgrammingBasics_v2.pdf
ParallelProgrammingBasics_v2.pdf
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
Arrays matrix 2020 ab
Arrays matrix 2020 abArrays matrix 2020 ab
Arrays matrix 2020 ab
 
C++ practical
C++ practicalC++ practical
C++ practical
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
 
Arrays
ArraysArrays
Arrays
 

More from astarmobiles

The role of the T helper lymphocytes is to- A- stimulate the natural k.pdf
The role of the T helper lymphocytes is to- A- stimulate the natural k.pdfThe role of the T helper lymphocytes is to- A- stimulate the natural k.pdf
The role of the T helper lymphocytes is to- A- stimulate the natural k.pdfastarmobiles
 
The rivige od the sarisle dax is (Beund to ore docinat plare wiveeded).pdf
The rivige od the sarisle dax is (Beund to ore docinat plare wiveeded).pdfThe rivige od the sarisle dax is (Beund to ore docinat plare wiveeded).pdf
The rivige od the sarisle dax is (Beund to ore docinat plare wiveeded).pdfastarmobiles
 
The rings of a Jovian planet are Question 34 options- a large numb.pdf
The rings of a Jovian planet are Question 34 options-     a large numb.pdfThe rings of a Jovian planet are Question 34 options-     a large numb.pdf
The rings of a Jovian planet are Question 34 options- a large numb.pdfastarmobiles
 
The Reverse transcriptase enzyme may use all the following as its subs.pdf
The Reverse transcriptase enzyme may use all the following as its subs.pdfThe Reverse transcriptase enzyme may use all the following as its subs.pdf
The Reverse transcriptase enzyme may use all the following as its subs.pdfastarmobiles
 
The researcher explored how pregnant women managed the process of deci.pdf
The researcher explored how pregnant women managed the process of deci.pdfThe researcher explored how pregnant women managed the process of deci.pdf
The researcher explored how pregnant women managed the process of deci.pdfastarmobiles
 
The remains of a human are found in an East Texas forest- Upon close e.pdf
The remains of a human are found in an East Texas forest- Upon close e.pdfThe remains of a human are found in an East Texas forest- Upon close e.pdf
The remains of a human are found in an East Texas forest- Upon close e.pdfastarmobiles
 
The relationship between ESG and CSR is- The relationship between ESG.pdf
The relationship between ESG and CSR is- The relationship between ESG.pdfThe relationship between ESG and CSR is- The relationship between ESG.pdf
The relationship between ESG and CSR is- The relationship between ESG.pdfastarmobiles
 
The recombination frequency between O and R is 23- and between R and W.pdf
The recombination frequency between O and R is 23- and between R and W.pdfThe recombination frequency between O and R is 23- and between R and W.pdf
The recombination frequency between O and R is 23- and between R and W.pdfastarmobiles
 
The rearrangement of the T-form of hemoglobin to the R-form (Select AL.pdf
The rearrangement of the T-form of hemoglobin to the R-form (Select AL.pdfThe rearrangement of the T-form of hemoglobin to the R-form (Select AL.pdf
The rearrangement of the T-form of hemoglobin to the R-form (Select AL.pdfastarmobiles
 
The purpose of the research model is to.pdf
The purpose of the research model is to.pdfThe purpose of the research model is to.pdf
The purpose of the research model is to.pdfastarmobiles
 
The proposed ownership percentage detailed in the cap table- A- must r.pdf
The proposed ownership percentage detailed in the cap table- A- must r.pdfThe proposed ownership percentage detailed in the cap table- A- must r.pdf
The proposed ownership percentage detailed in the cap table- A- must r.pdfastarmobiles
 
The probability of event A is P(A)-0-5- and the probability of event B.pdf
The probability of event A is P(A)-0-5- and the probability of event B.pdfThe probability of event A is P(A)-0-5- and the probability of event B.pdf
The probability of event A is P(A)-0-5- and the probability of event B.pdfastarmobiles
 
The program below needs some additional steps completed- The sample da.pdf
The program below needs some additional steps completed- The sample da.pdfThe program below needs some additional steps completed- The sample da.pdf
The program below needs some additional steps completed- The sample da.pdfastarmobiles
 
The process by which viral nucleic acids are encapsidated is called ge.pdf
The process by which viral nucleic acids are encapsidated is called ge.pdfThe process by which viral nucleic acids are encapsidated is called ge.pdf
The process by which viral nucleic acids are encapsidated is called ge.pdfastarmobiles
 
The probability pn that an infinite M-M-1 queue is in state n is given.pdf
The probability pn that an infinite M-M-1 queue is in state n is given.pdfThe probability pn that an infinite M-M-1 queue is in state n is given.pdf
The probability pn that an infinite M-M-1 queue is in state n is given.pdfastarmobiles
 
The probability of a randomly selected adult in one country being inte.pdf
The probability of a randomly selected adult in one country being inte.pdfThe probability of a randomly selected adult in one country being inte.pdf
The probability of a randomly selected adult in one country being inte.pdfastarmobiles
 
The primary cause of C- diff is A weakened immune system Normal flora.pdf
The primary cause of C- diff is A weakened immune system Normal flora.pdfThe primary cause of C- diff is A weakened immune system Normal flora.pdf
The primary cause of C- diff is A weakened immune system Normal flora.pdfastarmobiles
 
The point of cognitive cultural intelligence quotient (CQ) is- to asse.pdf
The point of cognitive cultural intelligence quotient (CQ) is- to asse.pdfThe point of cognitive cultural intelligence quotient (CQ) is- to asse.pdf
The point of cognitive cultural intelligence quotient (CQ) is- to asse.pdfastarmobiles
 
The pore waters of a wetland were sampled and the following were found.pdf
The pore waters of a wetland were sampled and the following were found.pdfThe pore waters of a wetland were sampled and the following were found.pdf
The pore waters of a wetland were sampled and the following were found.pdfastarmobiles
 
The poleward migration of the ITCZ directly causes- Seasonless for the.pdf
The poleward migration of the ITCZ directly causes- Seasonless for the.pdfThe poleward migration of the ITCZ directly causes- Seasonless for the.pdf
The poleward migration of the ITCZ directly causes- Seasonless for the.pdfastarmobiles
 

More from astarmobiles (20)

The role of the T helper lymphocytes is to- A- stimulate the natural k.pdf
The role of the T helper lymphocytes is to- A- stimulate the natural k.pdfThe role of the T helper lymphocytes is to- A- stimulate the natural k.pdf
The role of the T helper lymphocytes is to- A- stimulate the natural k.pdf
 
The rivige od the sarisle dax is (Beund to ore docinat plare wiveeded).pdf
The rivige od the sarisle dax is (Beund to ore docinat plare wiveeded).pdfThe rivige od the sarisle dax is (Beund to ore docinat plare wiveeded).pdf
The rivige od the sarisle dax is (Beund to ore docinat plare wiveeded).pdf
 
The rings of a Jovian planet are Question 34 options- a large numb.pdf
The rings of a Jovian planet are Question 34 options-     a large numb.pdfThe rings of a Jovian planet are Question 34 options-     a large numb.pdf
The rings of a Jovian planet are Question 34 options- a large numb.pdf
 
The Reverse transcriptase enzyme may use all the following as its subs.pdf
The Reverse transcriptase enzyme may use all the following as its subs.pdfThe Reverse transcriptase enzyme may use all the following as its subs.pdf
The Reverse transcriptase enzyme may use all the following as its subs.pdf
 
The researcher explored how pregnant women managed the process of deci.pdf
The researcher explored how pregnant women managed the process of deci.pdfThe researcher explored how pregnant women managed the process of deci.pdf
The researcher explored how pregnant women managed the process of deci.pdf
 
The remains of a human are found in an East Texas forest- Upon close e.pdf
The remains of a human are found in an East Texas forest- Upon close e.pdfThe remains of a human are found in an East Texas forest- Upon close e.pdf
The remains of a human are found in an East Texas forest- Upon close e.pdf
 
The relationship between ESG and CSR is- The relationship between ESG.pdf
The relationship between ESG and CSR is- The relationship between ESG.pdfThe relationship between ESG and CSR is- The relationship between ESG.pdf
The relationship between ESG and CSR is- The relationship between ESG.pdf
 
The recombination frequency between O and R is 23- and between R and W.pdf
The recombination frequency between O and R is 23- and between R and W.pdfThe recombination frequency between O and R is 23- and between R and W.pdf
The recombination frequency between O and R is 23- and between R and W.pdf
 
The rearrangement of the T-form of hemoglobin to the R-form (Select AL.pdf
The rearrangement of the T-form of hemoglobin to the R-form (Select AL.pdfThe rearrangement of the T-form of hemoglobin to the R-form (Select AL.pdf
The rearrangement of the T-form of hemoglobin to the R-form (Select AL.pdf
 
The purpose of the research model is to.pdf
The purpose of the research model is to.pdfThe purpose of the research model is to.pdf
The purpose of the research model is to.pdf
 
The proposed ownership percentage detailed in the cap table- A- must r.pdf
The proposed ownership percentage detailed in the cap table- A- must r.pdfThe proposed ownership percentage detailed in the cap table- A- must r.pdf
The proposed ownership percentage detailed in the cap table- A- must r.pdf
 
The probability of event A is P(A)-0-5- and the probability of event B.pdf
The probability of event A is P(A)-0-5- and the probability of event B.pdfThe probability of event A is P(A)-0-5- and the probability of event B.pdf
The probability of event A is P(A)-0-5- and the probability of event B.pdf
 
The program below needs some additional steps completed- The sample da.pdf
The program below needs some additional steps completed- The sample da.pdfThe program below needs some additional steps completed- The sample da.pdf
The program below needs some additional steps completed- The sample da.pdf
 
The process by which viral nucleic acids are encapsidated is called ge.pdf
The process by which viral nucleic acids are encapsidated is called ge.pdfThe process by which viral nucleic acids are encapsidated is called ge.pdf
The process by which viral nucleic acids are encapsidated is called ge.pdf
 
The probability pn that an infinite M-M-1 queue is in state n is given.pdf
The probability pn that an infinite M-M-1 queue is in state n is given.pdfThe probability pn that an infinite M-M-1 queue is in state n is given.pdf
The probability pn that an infinite M-M-1 queue is in state n is given.pdf
 
The probability of a randomly selected adult in one country being inte.pdf
The probability of a randomly selected adult in one country being inte.pdfThe probability of a randomly selected adult in one country being inte.pdf
The probability of a randomly selected adult in one country being inte.pdf
 
The primary cause of C- diff is A weakened immune system Normal flora.pdf
The primary cause of C- diff is A weakened immune system Normal flora.pdfThe primary cause of C- diff is A weakened immune system Normal flora.pdf
The primary cause of C- diff is A weakened immune system Normal flora.pdf
 
The point of cognitive cultural intelligence quotient (CQ) is- to asse.pdf
The point of cognitive cultural intelligence quotient (CQ) is- to asse.pdfThe point of cognitive cultural intelligence quotient (CQ) is- to asse.pdf
The point of cognitive cultural intelligence quotient (CQ) is- to asse.pdf
 
The pore waters of a wetland were sampled and the following were found.pdf
The pore waters of a wetland were sampled and the following were found.pdfThe pore waters of a wetland were sampled and the following were found.pdf
The pore waters of a wetland were sampled and the following were found.pdf
 
The poleward migration of the ITCZ directly causes- Seasonless for the.pdf
The poleward migration of the ITCZ directly causes- Seasonless for the.pdfThe poleward migration of the ITCZ directly causes- Seasonless for the.pdf
The poleward migration of the ITCZ directly causes- Seasonless for the.pdf
 

Recently uploaded

4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...Nguyen Thanh Tu Collection
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 

Recently uploaded (20)

4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - CẢ NĂ...
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 

The one that was previously posted on here does not compile or functio.pdf

  • 1. The one that was previously posted on here does not compile or function as intended. Change struct to class Make all the members private Add get_size , get_capacity and get_array methods Add remove, index_of and operator+ methods Add oprator< method, and together with other five ( > , >= , <= , == , != ) Complete and debug all the other methods in the sample code, such as insert Write some testing code in the main function Code template: #include <iostream> using namespace std; struct Vec { int _size; int _cap; int* arr; Vec() { _size = 0; _cap = 4; arr = new int[_cap]; } void insert( int n, int x ) { for ( int i = _size-1; i >= n; i-- ) { arr[i+1] = arr[i]; } arr[n] = x; _size++; } void reserve( int new_cap ) {
  • 2. if ( new_cap > _cap ) { _cap = new_cap; int *tmp = new int[_cap]; for ( int i = 0; i < _size; i++ ) { tmp[i] = arr[i]; } delete[] arr; arr = tmp; } } void push_back( int x ) { if ( _size == _cap ) { _cap *= 2; reserve(_cap); } arr[_size++] = x; } void pop() { if (_size > 0) _size--; } int& at( int idx ) { if ( idx >= _size || idx < 0 ) { throw "[Vector] Index out of bound!"; } return arr[idx]; } int& operator[]( int idx ) { if ( idx >= _size || idx < 0 ) { throw "[Vector] Index out of bound!"; } return arr[idx]; }
  • 3. ~Vec() { delete[] arr; } }; ostream& operator<<(ostream& os, Vec& v) { os << "[ "; for ( int i = 0; i < v._size-1; i++ ) { os << v.arr[i] << ", "; } os << v.arr[v._size-1] << " ]"; return os; } int main() { Vec v; v.push_back(3); v.push_back(1); v.push_back(4); v.push_back(2); v.push_back(8); //v.insert(1, 7); v[3] = 5; cout << v[3] << endl; //v.at(3) = 5; cout << v << endl; //cout << v._cap << endl; //v.reserve(20); //cout << v._cap << endl; //cout << v << endl; //cout << v._size << endl; //cout << v._cap << endl; return 0; }