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) . Use the provided main function (next page) and output example Notes a. grow function replaces the existing array with a new array . 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) main: int main() { cout << endl; IntArr a{5}; for(int i=0; i<5; i++) { a.push_back((i+1)*5); } cout << "Array size: " << a.getSize() << endl; cout << "Array A: "; for(int i=0; i

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

C++ Programming Question 1:
Hi, need help with review question 1 if possible. Thanks.

Main Function:

int main() {
cout << endl;

IntArr a{5};
for(int i=0; i<5; i++) { a.push_back((i+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 << a[i] << " "; }
cout << "\nArray B: ";
for(int i=0; i<b.getSize(); i++) { cout << b[i] << " "; }
cout << endl << endl;

cout << endl;
return 0;
}

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)
main:
int main() {
cout << endl;
}
IntArr a{5};
for(int i=0; i<5; i++)
{ a.push_back((i+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 << "\nPArray B: ";
for(int i=0; i<b.getSize(); i++) {
cout << endl << endl;
cout << "Array A: ";
for(int i=0; i<a.getSize(); i++) {
cout << "\nArray B: ";
for(int i=0; i<b.getSize(); i++) {
cout << endl << endl;
a.pop_back();
cout << "Array size: " << a.getSize() << endl;
b = a;
cout << endl;
return 0;
cout << a[i] << " "; }
Output:
cout << b[i] << " "; }
cout << a[i] << " "; }
cout << b[i] << " "; }
Array ze:
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: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) main: int main() { cout << endl; } IntArr a{5}; for(int i=0; i<5; i++) { a.push_back((i+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 << "\nPArray B: "; for(int i=0; i<b.getSize(); i++) { cout << endl << endl; cout << "Array A: "; for(int i=0; i<a.getSize(); i++) { cout << "\nArray B: "; for(int i=0; i<b.getSize(); i++) { cout << endl << endl; a.pop_back(); cout << "Array size: " << a.getSize() << endl; b = a; cout << endl; return 0; cout << a[i] << " "; } Output: cout << b[i] << " "; } cout << a[i] << " "; } cout << b[i] << " "; } Array ze: 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
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education