Here is the code provided. I'm confused on the premise of these questions. Main(). #include #include "flexArray.h" using namespace std; int main() {     flexArray f;     f.SetLength(5);     f.SetElement("Hello", 0);     f.SetElement("World", 1);     f.SetElement("THIS SHOULD FAIL", 6);     for (int i = 0; i < f.GetLength(); i++) {         cout << "Element " << i << " = " << f.GetElement(i) << endl;     }     f.SetLength(10);     f.SetElement("THIS SHOULD NOT FAIL", 6);     for (int i = 0; i < f.GetLength(); i++) {         cout << "Element " << i << " = " << f.GetElement(i) << endl;     }     return 0;   header file.  #ifndef __FLEXARRAY_H__ #define __FLEXARRAY_H__ #include // This is an array of strings class flexArray { public:     flexArray(); // Default constructor     flexArray(unsigned int arrayLen); // Constructor with a length param     ~flexArray(); // Destructor: cleans up dynamically-allocated memory     unsigned int GetLength();     void SetLength(unsigned int updatedLength);     std::string GetElement(unsigned int position);     void SetElement(std::string update, unsigned int position); private:     unsigned int _length; // this is the current length of the array     std::string* _array;  // this is where we put the actual values }; #endif /* __FLEXARRAY_H__ */  flexArray.cpp #include "flexArray.h" flexArray::flexArray() { // Default constructor     // _length and _array     _length = 100; // Setting the length to the default 100     _array = new std::string[_length]; // Dynamically allocate the array } flexArray::flexArray(unsigned int arrayLen) { // Constructor with a length param     // _length and _array     _length = arrayLen; // Setting the length to the parameter     _array = new std::string[_length]; // Dynamically allocate the array } flexArray::~flexArray() { // Destructor: cleans up dynamically-allocated memory     delete [] _array; // Deallocating the array before closing } unsigned int flexArray::GetLength() {     return _length; } void flexArray::SetLength(unsigned int updatedLength) {     // Step 1: Allocate space          // Step 2: Copy over elements     // Step 3: Delete old array     // Step 4: Update with new array      } std::string flexArray::GetElement(unsigned int position) { } void flexArray::SetElement(std::string update, unsigned int position) { }

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

Here is the code provided. I'm confused on the premise of these questions.

Main().

#include <iostream>
#include "flexArray.h"

using namespace std;

int main() {

    flexArray f;

    f.SetLength(5);
    f.SetElement("Hello", 0);
    f.SetElement("World", 1);
    f.SetElement("THIS SHOULD FAIL", 6);

    for (int i = 0; i < f.GetLength(); i++) {
        cout << "Element " << i << " = " << f.GetElement(i) << endl;
    }

    f.SetLength(10);
    f.SetElement("THIS SHOULD NOT FAIL", 6);

    for (int i = 0; i < f.GetLength(); i++) {
        cout << "Element " << i << " = " << f.GetElement(i) << endl;
    }

    return 0;

 

header file. 

#ifndef __FLEXARRAY_H__
#define __FLEXARRAY_H__

#include <string>

// This is an array of strings
class flexArray {
public:
    flexArray(); // Default constructor
    flexArray(unsigned int arrayLen); // Constructor with a length param
    ~flexArray(); // Destructor: cleans up dynamically-allocated memory

    unsigned int GetLength();
    void SetLength(unsigned int updatedLength);

    std::string GetElement(unsigned int position);
    void SetElement(std::string update, unsigned int position);

private:
    unsigned int _length; // this is the current length of the array
    std::string* _array;  // this is where we put the actual values
};

#endif /* __FLEXARRAY_H__ */ 

flexArray.cpp

#include "flexArray.h"

flexArray::flexArray() { // Default constructor
    // _length and _array
    _length = 100; // Setting the length to the default 100
    _array = new std::string[_length]; // Dynamically allocate the array
}

flexArray::flexArray(unsigned int arrayLen) { // Constructor with a length param
    // _length and _array
    _length = arrayLen; // Setting the length to the parameter
    _array = new std::string[_length]; // Dynamically allocate the array
}

flexArray::~flexArray() { // Destructor: cleans up dynamically-allocated memory
    delete [] _array; // Deallocating the array before closing
}

unsigned int flexArray::GetLength() {
    return _length;
}

void flexArray::SetLength(unsigned int updatedLength) {
    // Step 1: Allocate space
    

    // Step 2: Copy over elements


    // Step 3: Delete old array


    // Step 4: Update with new array
    
}

std::string flexArray::GetElement(unsigned int position) {

}

void flexArray::SetElement(std::string update, unsigned int position) {

}

1. Build the setLength function. If the new length is shorter than the current array,
copy only enough items from the previous array to fill the new array. If it's longer,
copy all of the old items into the new array and initialize the remaining elements
to the empty string
11 T
2. Build the setElement function. This is a fairly simple mutator that changes the
string at the specified location to the new value.
3. Build the getElement function. This is a fairly simple accessor that returns the
string at the specified location.
Transcribed Image Text:1. Build the setLength function. If the new length is shorter than the current array, copy only enough items from the previous array to fill the new array. If it's longer, copy all of the old items into the new array and initialize the remaining elements to the empty string 11 T 2. Build the setElement function. This is a fairly simple mutator that changes the string at the specified location to the new value. 3. Build the getElement function. This is a fairly simple accessor that returns the string at the specified location.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 4 images

Blurred answer
Knowledge Booster
Reference Types in Function
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