Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

why am i getting this wrong can anybody correct this? ---------------------- instructions my source codew --------- my code ----------- h37.h // do not make any

why am i getting this wrong can anybody correct this?

----------------------

instructions

image text in transcribed

image text in transcribed

my source codew

---------

image text in transcribed

my code

-----------

h37.h // do not make any changes

-------------------------------------------------------

#ifndef H37_H_ #define H37_H_ #include

const size_t INITIAL_CAPACITY = 2;

class FlexArray { public: // You will write these FlexArray& readData(std::istream& in); std::string toString() const; ~FlexArray();

// These prohibit certain operations FlexArray() = default; FlexArray(const FlexArray&) = delete; FlexArray& operator=(const FlexArray&) = delete; private: size_t size_ = 0; int * data_ = nullptr; };

inline std::ostream& operator

inline std::istream& operator>>(std::istream& in, FlexArray& a) { a.readData(in); return in; } #endif

h37.cpp // what i got so far

-----------------

#include #include using namespace std;

string STUDENT = " "; // Add your Canvas/occ-email ID

#include "h37.h"

// Implement the three member functions here

FlexArray& FlexArray::readData(istream& in) { size_t capacity = INITIAL_CAPACITY; data_ = new int[INITIAL_CAPACITY](); int * buffer = new int[INITIAL_CAPACITY](); int read; size_t count = 0;

while(in >> read && capacity > count && isdigit(read)) { buffer[count] = read; count++;

size_ = count;

if(count >= capacity) { capacity *= 2; data_ = new int [capacity]();

for(size_t i = 0; i

} }

}

delete []buffer, buffer = nullptr; return *this;

}

string FlexArray::toString() const { string result = "{"; result += to_string(data_[0]); for(size_t i = 1; i

}

FlexArray::~FlexArray() { size_ = 0; data_ = nullptr; }

Upload the workspace for H37 where you'll find the definition of the FlexArray class in h37.h. Do not make any changes to h37.h at all. As you can see in the header, you are going to write three member functions. Here are the descriptions: The readData Member Function The readData() member function will read integer data from an input stream (such as cin) until the user terminates input by either running out of data or by entering an in- valid value such as Q. The function sets the size data member to the number of numeric in- puts. The mernber data-is a pointer to a heap allocated array At the end of the function, the array should have exactly size-ele- ments. The function will return *this (a reference to the current FleArray object). elements the user will enter. Start with a ca- You won't know at the outset how many pacity of INITIAL CAPACITY (defined inside h37.h). Do not change this from its cur- rent value of 2. Managing Memory in readData Inside readData(), whenever your array fills up, create a new array of double the cur- rent capacity, copy the original elements to the new storage, free the original array and assign the new array to the member data_. At the end of your function, you'll follow a similar pattern to shrink the allocated memory so that it is exactly the same size as the number of elements. Be sure to delete any intermediate arrays. If you have any memory leaks displayed, fix them before submitting your assignment. This algorithm is similar to that used for fiLLArray) in In-Class Exercise 9B. The only difference is that reallocation and copying that occurs when the array is filled up The tostring Member Function For toString), the result should be delimited with braces "" and ")". The individ- ual elements in the array should be separated with a comma, followed by a space. There should be no space before the first element or after the last. (You'll recognize this as the fencepost algorithm we covered in In-Class Exercise 9B.) You can convert the integer elements in the array by using the to string() function in the header Upload the workspace for H37 where you'll find the definition of the FlexArray class in h37.h. Do not make any changes to h37.h at all. As you can see in the header, you are going to write three member functions. Here are the descriptions: The readData Member Function The readData() member function will read integer data from an input stream (such as cin) until the user terminates input by either running out of data or by entering an in- valid value such as Q. The function sets the size data member to the number of numeric in- puts. The mernber data-is a pointer to a heap allocated array At the end of the function, the array should have exactly size-ele- ments. The function will return *this (a reference to the current FleArray object). elements the user will enter. Start with a ca- You won't know at the outset how many pacity of INITIAL CAPACITY (defined inside h37.h). Do not change this from its cur- rent value of 2. Managing Memory in readData Inside readData(), whenever your array fills up, create a new array of double the cur- rent capacity, copy the original elements to the new storage, free the original array and assign the new array to the member data_. At the end of your function, you'll follow a similar pattern to shrink the allocated memory so that it is exactly the same size as the number of elements. Be sure to delete any intermediate arrays. If you have any memory leaks displayed, fix them before submitting your assignment. This algorithm is similar to that used for fiLLArray) in In-Class Exercise 9B. The only difference is that reallocation and copying that occurs when the array is filled up The tostring Member Function For toString), the result should be delimited with braces "" and ")". The individ- ual elements in the array should be separated with a comma, followed by a space. There should be no space before the first element or after the last. (You'll recognize this as the fencepost algorithm we covered in In-Class Exercise 9B.) You can convert the integer elements in the array by using the to string() function in the header

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Technology And Management Computers And Information Processing Systems For Business

Authors: Robert C. Goldstein

1st Edition

0471887374, 978-0471887379

More Books

Students also viewed these Databases questions

Question

6. Explain how to train managers to coach employees.

Answered: 1 week ago

Question

5. Tell how job experiences can be used for skill development.

Answered: 1 week ago