Hello, I am having trouble with this homework question for my c++ course. **It is saying to use the int main provided - I have included it in the snip along with the correct output snip. 1. Implement a class IntArr using dynamic memory. a. data members:     capacity: maximum number of elements in the array     size: current number of elements in the array     array: a pointer to a dynamic array of integers b. constructors:      default constructor: capacity and size are 0, array pointer is nullptr      user constructor: create a dynamic array of the specified size c. overloaded operators: subscript operator: return an element or exits if illegal index d. “the big three”:     copy constructor: construct an IntArr object using deep copy     assignment overload operator: deep copy from one object to another     destructor: destroys an object without creating a memory leak e. grow function: “grow” the array to twice its capacity f. push_back function: add a new integer to the end of the array g. pop_back function: remove the last element in the array h. getSize function: return the current size of the array (not capacity) i. Use the provided main function (next page) and output example Notes  a. grow function replaces the existing array with a new array  b. subscript operator should be a const member function  c. ensure that deep copy is used where applicable  d. push_back and pop_back functions require the grow function  e. push_back and pop_back functions should update array size (not capacity)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Hello, I am having trouble with this homework question for my c++ course.

**It is saying to use the int main provided - I have included it in the snip along with the correct output snip.

1. Implement a class IntArr using dynamic memory.
a. data members:
    capacity: maximum number of elements in the array
    size: current number of elements in the array
    array: a pointer to a dynamic array of integers
b. constructors:
     default constructor: capacity and size are 0, array pointer is nullptr
     user constructor: create a dynamic array of the specified size
c. overloaded operators:
subscript operator: return an element or exits if illegal index
d. “the big three”:
    copy constructor: construct an IntArr object using deep copy
    assignment overload operator: deep copy from one object to another
    destructor: destroys an object without creating a memory leak
e. grow function: “grow” the array to twice its capacity
f. push_back function: add a new integer to the end of the array
g. pop_back function: remove the last element in the array
h. getSize function: return the current size of the array (not capacity)
i. Use the provided main function (next page) and output example
Notes
 a. grow function replaces the existing array with a new array
 b. subscript operator should be a const member function
 c. ensure that deep copy is used where applicable
 d. push_back and pop_back functions require the grow function
 e. push_back and pop_back functions should update array size (not capacity)

 

Array size: 5
Array A: 5 10 15 20 25
Array size: 7
Array A: 5 10 15 20 25 30 35
PArray B: 5 10 15 20 25 30 35
Array size: 6
Array A: 5 10 15 20 25 30
Array B: 5 10 15 20 25 30
Transcribed Image Text:Array size: 5 Array A: 5 10 15 20 25 Array size: 7 Array A: 5 10 15 20 25 30 35 PArray B: 5 10 15 20 25 30 35 Array size: 6 Array A: 5 10 15 20 25 30 Array B: 5 10 15 20 25 30
int main() {
cout << endl;
IntArr a{5};
for(int i=0; i<5; i++) { a.push_back((1+1)*5); }
cout « "Array size: " « a.getSize() « endl;
cout « "Array A: ";
for(int i=0; i<a.getSize(); i++) { cout << a[i] << " "; }
cout << endl « endl;
a. push_back(30);
a.push_back(35);
cout « "Array size: " « a.getSize() « endl;
<<
IntArr b = a;
cout <« "Array A: ";
for(int i=0; i<a.getSize(); i++) { cout <« a[i] << " "; }
cout << "\nPArray B: ";
for(int i=0; i<b.getSize(); i++) { cout « b[i] « " "; }
cout <« endl « endl;
a. pop_back();
cout <« "Array size: " <« a.getSize() <« endl;
b = a;
cout « "Array A: ";
for(int i=0; i<a.getSize(); i++)
cout <« ali] «" "; }
cout <« "\nArray B: ";
for(int i=0; i<b.getSize(); i++){ cout « b[i] « " "; }
cout « endl « endl;
cout << endl;
return 8;
Transcribed Image Text:int main() { cout << endl; IntArr a{5}; for(int i=0; i<5; i++) { a.push_back((1+1)*5); } cout « "Array size: " « a.getSize() « endl; cout « "Array A: "; for(int i=0; i<a.getSize(); i++) { cout << a[i] << " "; } cout << endl « endl; a. push_back(30); a.push_back(35); cout « "Array size: " « a.getSize() « endl; << IntArr b = a; cout <« "Array A: "; for(int i=0; i<a.getSize(); i++) { cout <« a[i] << " "; } cout << "\nPArray B: "; for(int i=0; i<b.getSize(); i++) { cout « b[i] « " "; } cout <« endl « endl; a. pop_back(); cout <« "Array size: " <« a.getSize() <« endl; b = a; cout « "Array A: "; for(int i=0; i<a.getSize(); i++) cout <« ali] «" "; } cout <« "\nArray B: "; for(int i=0; i<b.getSize(); i++){ cout « b[i] « " "; } cout « endl « endl; cout << endl; return 8;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY