Question: hello, my code is attatched and i need help filling in the functions that i have commented out in the program, please write comments explaining
hello, my code is attatched and i need help filling in the functions that i have commented out in the program,
please write comments explaining what, why so i can use this as a learning experience and learn from it. thank you
i need help filling in the
void pushback, void popback, int front(), it back(), size_t size(), bool empty, void check overflow.
instructions and code attahced below
#include
#include
#include
class int_vector {
public :
int_vector() : capacity_(minCapacity_), size_(0), data_(new int[size_]) {
std:: cout
}
int_vector(const std::initializer_list& li): int_vector(){
for(int i : li){
*(data_ + size_) = i;
++size_;
}
}
int_vector(const int_vector& other) : data_(nullptr){
std::cout
copy(other);
} //copy c'tor
int_vector& operator = (const int_vector& other){
if(this == &other) {copy(other);}
copy(other);
return *this;
}
void copy(const int_vector& other){
if(data_ != nullptr) {delete[] data_;}
capacity_ = other.capacity_;
size_ = other.size_;
data_ = new int[size_];
memcpy(data_, other.data_, size_* sizeof(int));
}
~int_vector(){
std::cout
delete[] data_;
}
int operator[](size_t idx) const{ return *(data_ + idx);} //read-only
int& operator[](size_t idx) { return *(data_ + idx);} //rewrite
//size_t count() const;
//bool empty() const;
//int front() const;
//int back() const;
//void push_back(int value){
//check_overflow();
// data_[size_++] = value;
// }
// void pop_back();
//void check_overflow() const{
// if(size_ == capacity_){
// throw new std::invalid_argument("overflow");
// }
// }
//void check_empty() const;
friend std::ostream& operator
if (iv.size_ == 0) {
return os
}
os
for (size_t i = 0; i
os
}
return os
}
private :
const size_t minCapacity_ = 10;
size_t capacity_;
size_t size_;
int* data_;
};
int main() {
int_vector ivdefault;
int_vector iv2({3,1,4,1,5,9,2,6,5});
int_vector ivcopycted= iv2;
ivdefault= iv2;
iv2[0]=2;
iv2[1]=7;
iv2[2]=1;
//int_vector iv2 = iv;
// int_vector iv3;
// iv3 = iv;
// std::cout
//std::cout
// std::cout
//iv[0] = 999;
// std::cout
std::cout
return 0;
}


LAB: int_vector class (prelude to vector
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
