One problem with dynamic arrays is that they don't carry around their size. Create a structure, DynArray which uses a unique pointer for a dynamic array (data), and an int for the size and capacity.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section: Chapter Questions
Problem 8PP: (Data processing) A bank’s customer records are to be stored in a file and read into a set of arrays...
icon
Related questions
Question
One problem with dynamic arrays is that they don't carry around their size. Create a structure,
DynArray which uses a unique pointer for a dynamic array (data), and an int for the
size and capacity.
dynarray.h
#ifndef DYNARRAY_H
#define DYNARRAY_H
1
2
3
4
#include <iostream>
#include <memory>
7
// Define the DynArray structure here
8
std::ostream& operator<<(std::ostream& out, const DynArray& a);
std::istream& operator>>(std::istream& in, DynArray& a);
DynArray makeDA (int capacity);
10
11
12
13
#endif
memory.cpp
1
#include <iostream>
#include <string>
#include "dynarray.h"
using namespace std;
2
3
4
int main()
{
cout « "Array capacity: ";
int capacity;
cin >> capacity;
7
8
9
10
11
auto a = makeDA (capacity);
cout « "Enter up to " <« capacity « " numbers: ";
cin >> a;
12
13
14
15
16
cout « "a->" « a « endl;
17
}
Transcribed Image Text:One problem with dynamic arrays is that they don't carry around their size. Create a structure, DynArray which uses a unique pointer for a dynamic array (data), and an int for the size and capacity. dynarray.h #ifndef DYNARRAY_H #define DYNARRAY_H 1 2 3 4 #include <iostream> #include <memory> 7 // Define the DynArray structure here 8 std::ostream& operator<<(std::ostream& out, const DynArray& a); std::istream& operator>>(std::istream& in, DynArray& a); DynArray makeDA (int capacity); 10 11 12 13 #endif memory.cpp 1 #include <iostream> #include <string> #include "dynarray.h" using namespace std; 2 3 4 int main() { cout « "Array capacity: "; int capacity; cin >> capacity; 7 8 9 10 11 auto a = makeDA (capacity); cout « "Enter up to " <« capacity « " numbers: "; cin >> a; 12 13 14 15 16 cout « "a->" « a « endl; 17 }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Randomized Select Algorithm
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT