SlideShare a Scribd company logo
1 of 4
Download to read offline
These are the things I have to do to the code please help me out.
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
#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;
}
These are the things I have to do to the code please help me out- Chan.pdf

More Related Content

Similar to These are the things I have to do to the code please help me out- Chan.pdf

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
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for SpeedYung-Yu Chen
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorNeeraj Kaushik
 
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
 
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
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and PolynomialAroosa Rajput
 
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
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings imtiazalijoono
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical fileMitul Patel
 
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
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTsKevlin Henney
 
ماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارامماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارامAram Jamal
 

Similar to These are the things I have to do to the code please help me out- Chan.pdf (20)

Java arrays
Java    arraysJava    arrays
Java arrays
 
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
 
Write Python for Speed
Write Python for SpeedWrite Python for Speed
Write Python for Speed
 
C-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression CalculatorC-Sharp Arithmatic Expression Calculator
C-Sharp Arithmatic Expression Calculator
 
array2d.ppt
array2d.pptarray2d.ppt
array2d.ppt
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
 
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
 
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-...
 
Sparse Matrix and Polynomial
Sparse Matrix and PolynomialSparse Matrix and Polynomial
Sparse Matrix and Polynomial
 
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
 
Arrays matrix 2020 ab
Arrays matrix 2020 abArrays matrix 2020 ab
Arrays matrix 2020 ab
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Cs pritical file
Cs pritical fileCs pritical file
Cs pritical file
 
Arrays
ArraysArrays
Arrays
 
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
 
2DArrays.ppt
2DArrays.ppt2DArrays.ppt
2DArrays.ppt
 
DSC program.pdf
DSC program.pdfDSC program.pdf
DSC program.pdf
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
 
ماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارامماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارام
 

More from DylanTZEAverys

tusd tee ieguiments-cmodot exarpie Get mote belp -Rest the iegulendets.pdf
tusd tee ieguiments-cmodot exarpie Get mote belp -Rest the iegulendets.pdftusd tee ieguiments-cmodot exarpie Get mote belp -Rest the iegulendets.pdf
tusd tee ieguiments-cmodot exarpie Get mote belp -Rest the iegulendets.pdfDylanTZEAverys
 
Use the data below to compute GDP by the expenditure approach- All fig.pdf
Use the data below to compute GDP by the expenditure approach- All fig.pdfUse the data below to compute GDP by the expenditure approach- All fig.pdf
Use the data below to compute GDP by the expenditure approach- All fig.pdfDylanTZEAverys
 
urgent The deadweight logs of the tax ls shownt by anded 7- A+B+F th-.pdf
urgent The deadweight logs of the tax ls shownt by anded 7- A+B+F th-.pdfurgent The deadweight logs of the tax ls shownt by anded 7- A+B+F th-.pdf
urgent The deadweight logs of the tax ls shownt by anded 7- A+B+F th-.pdfDylanTZEAverys
 
Use MV-P(1+RT) to find the maturity value (in $ -$ of the loan-.pdf
Use MV-P(1+RT) to find the maturity value (in $ -$ of the loan-.pdfUse MV-P(1+RT) to find the maturity value (in $ -$ of the loan-.pdf
Use MV-P(1+RT) to find the maturity value (in $ -$ of the loan-.pdfDylanTZEAverys
 
Understand how atmospheric nitrogen (N2) is converted to ammonia and s.pdf
Understand how atmospheric nitrogen (N2) is converted to ammonia and s.pdfUnderstand how atmospheric nitrogen (N2) is converted to ammonia and s.pdf
Understand how atmospheric nitrogen (N2) is converted to ammonia and s.pdfDylanTZEAverys
 
Understand what makes up an ecosystem- microbiome- guild and populatio.pdf
Understand what makes up an ecosystem- microbiome- guild and populatio.pdfUnderstand what makes up an ecosystem- microbiome- guild and populatio.pdf
Understand what makes up an ecosystem- microbiome- guild and populatio.pdfDylanTZEAverys
 
Understanding how the gum disease pathogen- Porphyromonas gingivalis-.pdf
Understanding how the gum disease pathogen- Porphyromonas gingivalis-.pdfUnderstanding how the gum disease pathogen- Porphyromonas gingivalis-.pdf
Understanding how the gum disease pathogen- Porphyromonas gingivalis-.pdfDylanTZEAverys
 
Understanding how the gum disease pathogen- Porphyromonas gingivalis- (1).pdf
Understanding how the gum disease pathogen- Porphyromonas gingivalis- (1).pdfUnderstanding how the gum disease pathogen- Porphyromonas gingivalis- (1).pdf
Understanding how the gum disease pathogen- Porphyromonas gingivalis- (1).pdfDylanTZEAverys
 
Unknown D fizzes when dilute hydrochloric acid is applied- What type o.pdf
Unknown D fizzes when dilute hydrochloric acid is applied- What type o.pdfUnknown D fizzes when dilute hydrochloric acid is applied- What type o.pdf
Unknown D fizzes when dilute hydrochloric acid is applied- What type o.pdfDylanTZEAverys
 
Type A hemophilia in dogs is sex linked recessive disorder- There is a.pdf
Type A hemophilia in dogs is sex linked recessive disorder- There is a.pdfType A hemophilia in dogs is sex linked recessive disorder- There is a.pdf
Type A hemophilia in dogs is sex linked recessive disorder- There is a.pdfDylanTZEAverys
 
Two different models have been developed to describe the pace of evolu.pdf
Two different models have been developed to describe the pace of evolu.pdfTwo different models have been developed to describe the pace of evolu.pdf
Two different models have been developed to describe the pace of evolu.pdfDylanTZEAverys
 
True or False- We can overcome a component auditor's lack of independe.pdf
True or False- We can overcome a component auditor's lack of independe.pdfTrue or False- We can overcome a component auditor's lack of independe.pdf
True or False- We can overcome a component auditor's lack of independe.pdfDylanTZEAverys
 
True or False- If Mendel had compared traits controlled by genes on th.pdf
True or False- If Mendel had compared traits controlled by genes on th.pdfTrue or False- If Mendel had compared traits controlled by genes on th.pdf
True or False- If Mendel had compared traits controlled by genes on th.pdfDylanTZEAverys
 
Tristan Walker has also started a foundation called Code2040- Code2040.pdf
Tristan Walker has also started a foundation called Code2040- Code2040.pdfTristan Walker has also started a foundation called Code2040- Code2040.pdf
Tristan Walker has also started a foundation called Code2040- Code2040.pdfDylanTZEAverys
 
Trypanosomes are parasites which cause dsease in humans and animals In.pdf
Trypanosomes are parasites which cause dsease in humans and animals In.pdfTrypanosomes are parasites which cause dsease in humans and animals In.pdf
Trypanosomes are parasites which cause dsease in humans and animals In.pdfDylanTZEAverys
 
True or False- -home-etaylor-Documents-foo-txt is an absolute file pat.pdf
True or False- -home-etaylor-Documents-foo-txt is an absolute file pat.pdfTrue or False- -home-etaylor-Documents-foo-txt is an absolute file pat.pdf
True or False- -home-etaylor-Documents-foo-txt is an absolute file pat.pdfDylanTZEAverys
 
Total cholesterol in children aged 10-15 is assumed to follow a normal.pdf
Total cholesterol in children aged 10-15 is assumed to follow a normal.pdfTotal cholesterol in children aged 10-15 is assumed to follow a normal.pdf
Total cholesterol in children aged 10-15 is assumed to follow a normal.pdfDylanTZEAverys
 
Tool-Technique Bioinformatics Nanotechnology Clinical Modeling-trials.pdf
Tool-Technique Bioinformatics Nanotechnology Clinical Modeling-trials.pdfTool-Technique Bioinformatics Nanotechnology Clinical Modeling-trials.pdf
Tool-Technique Bioinformatics Nanotechnology Clinical Modeling-trials.pdfDylanTZEAverys
 
Topic - Process Improvement- College admission process improvement for.pdf
Topic - Process Improvement- College admission process improvement for.pdfTopic - Process Improvement- College admission process improvement for.pdf
Topic - Process Improvement- College admission process improvement for.pdfDylanTZEAverys
 
Today- you have learned about Sexual reproduction- which is performed.pdf
Today- you have learned about Sexual reproduction- which is performed.pdfToday- you have learned about Sexual reproduction- which is performed.pdf
Today- you have learned about Sexual reproduction- which is performed.pdfDylanTZEAverys
 

More from DylanTZEAverys (20)

tusd tee ieguiments-cmodot exarpie Get mote belp -Rest the iegulendets.pdf
tusd tee ieguiments-cmodot exarpie Get mote belp -Rest the iegulendets.pdftusd tee ieguiments-cmodot exarpie Get mote belp -Rest the iegulendets.pdf
tusd tee ieguiments-cmodot exarpie Get mote belp -Rest the iegulendets.pdf
 
Use the data below to compute GDP by the expenditure approach- All fig.pdf
Use the data below to compute GDP by the expenditure approach- All fig.pdfUse the data below to compute GDP by the expenditure approach- All fig.pdf
Use the data below to compute GDP by the expenditure approach- All fig.pdf
 
urgent The deadweight logs of the tax ls shownt by anded 7- A+B+F th-.pdf
urgent The deadweight logs of the tax ls shownt by anded 7- A+B+F th-.pdfurgent The deadweight logs of the tax ls shownt by anded 7- A+B+F th-.pdf
urgent The deadweight logs of the tax ls shownt by anded 7- A+B+F th-.pdf
 
Use MV-P(1+RT) to find the maturity value (in $ -$ of the loan-.pdf
Use MV-P(1+RT) to find the maturity value (in $ -$ of the loan-.pdfUse MV-P(1+RT) to find the maturity value (in $ -$ of the loan-.pdf
Use MV-P(1+RT) to find the maturity value (in $ -$ of the loan-.pdf
 
Understand how atmospheric nitrogen (N2) is converted to ammonia and s.pdf
Understand how atmospheric nitrogen (N2) is converted to ammonia and s.pdfUnderstand how atmospheric nitrogen (N2) is converted to ammonia and s.pdf
Understand how atmospheric nitrogen (N2) is converted to ammonia and s.pdf
 
Understand what makes up an ecosystem- microbiome- guild and populatio.pdf
Understand what makes up an ecosystem- microbiome- guild and populatio.pdfUnderstand what makes up an ecosystem- microbiome- guild and populatio.pdf
Understand what makes up an ecosystem- microbiome- guild and populatio.pdf
 
Understanding how the gum disease pathogen- Porphyromonas gingivalis-.pdf
Understanding how the gum disease pathogen- Porphyromonas gingivalis-.pdfUnderstanding how the gum disease pathogen- Porphyromonas gingivalis-.pdf
Understanding how the gum disease pathogen- Porphyromonas gingivalis-.pdf
 
Understanding how the gum disease pathogen- Porphyromonas gingivalis- (1).pdf
Understanding how the gum disease pathogen- Porphyromonas gingivalis- (1).pdfUnderstanding how the gum disease pathogen- Porphyromonas gingivalis- (1).pdf
Understanding how the gum disease pathogen- Porphyromonas gingivalis- (1).pdf
 
Unknown D fizzes when dilute hydrochloric acid is applied- What type o.pdf
Unknown D fizzes when dilute hydrochloric acid is applied- What type o.pdfUnknown D fizzes when dilute hydrochloric acid is applied- What type o.pdf
Unknown D fizzes when dilute hydrochloric acid is applied- What type o.pdf
 
Type A hemophilia in dogs is sex linked recessive disorder- There is a.pdf
Type A hemophilia in dogs is sex linked recessive disorder- There is a.pdfType A hemophilia in dogs is sex linked recessive disorder- There is a.pdf
Type A hemophilia in dogs is sex linked recessive disorder- There is a.pdf
 
Two different models have been developed to describe the pace of evolu.pdf
Two different models have been developed to describe the pace of evolu.pdfTwo different models have been developed to describe the pace of evolu.pdf
Two different models have been developed to describe the pace of evolu.pdf
 
True or False- We can overcome a component auditor's lack of independe.pdf
True or False- We can overcome a component auditor's lack of independe.pdfTrue or False- We can overcome a component auditor's lack of independe.pdf
True or False- We can overcome a component auditor's lack of independe.pdf
 
True or False- If Mendel had compared traits controlled by genes on th.pdf
True or False- If Mendel had compared traits controlled by genes on th.pdfTrue or False- If Mendel had compared traits controlled by genes on th.pdf
True or False- If Mendel had compared traits controlled by genes on th.pdf
 
Tristan Walker has also started a foundation called Code2040- Code2040.pdf
Tristan Walker has also started a foundation called Code2040- Code2040.pdfTristan Walker has also started a foundation called Code2040- Code2040.pdf
Tristan Walker has also started a foundation called Code2040- Code2040.pdf
 
Trypanosomes are parasites which cause dsease in humans and animals In.pdf
Trypanosomes are parasites which cause dsease in humans and animals In.pdfTrypanosomes are parasites which cause dsease in humans and animals In.pdf
Trypanosomes are parasites which cause dsease in humans and animals In.pdf
 
True or False- -home-etaylor-Documents-foo-txt is an absolute file pat.pdf
True or False- -home-etaylor-Documents-foo-txt is an absolute file pat.pdfTrue or False- -home-etaylor-Documents-foo-txt is an absolute file pat.pdf
True or False- -home-etaylor-Documents-foo-txt is an absolute file pat.pdf
 
Total cholesterol in children aged 10-15 is assumed to follow a normal.pdf
Total cholesterol in children aged 10-15 is assumed to follow a normal.pdfTotal cholesterol in children aged 10-15 is assumed to follow a normal.pdf
Total cholesterol in children aged 10-15 is assumed to follow a normal.pdf
 
Tool-Technique Bioinformatics Nanotechnology Clinical Modeling-trials.pdf
Tool-Technique Bioinformatics Nanotechnology Clinical Modeling-trials.pdfTool-Technique Bioinformatics Nanotechnology Clinical Modeling-trials.pdf
Tool-Technique Bioinformatics Nanotechnology Clinical Modeling-trials.pdf
 
Topic - Process Improvement- College admission process improvement for.pdf
Topic - Process Improvement- College admission process improvement for.pdfTopic - Process Improvement- College admission process improvement for.pdf
Topic - Process Improvement- College admission process improvement for.pdf
 
Today- you have learned about Sexual reproduction- which is performed.pdf
Today- you have learned about Sexual reproduction- which is performed.pdfToday- you have learned about Sexual reproduction- which is performed.pdf
Today- you have learned about Sexual reproduction- which is performed.pdf
 

Recently uploaded

FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
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
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactisticshameyhk98
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
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
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfstareducators107
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSAnaAcapella
 

Recently uploaded (20)

FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
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.
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
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
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
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
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Simple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdfSimple, Complex, and Compound Sentences Exercises.pdf
Simple, Complex, and Compound Sentences Exercises.pdf
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 

These are the things I have to do to the code please help me out- Chan.pdf

  • 1. These are the things I have to do to the code please help me out. 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 #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 ) {
  • 2. _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() {
  • 3. 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; }