Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, Is there a way you can make the output into a double because It doesn't make it into a double. #include ; #include ;

Hello, Is there a way you can make the output into a double because It doesn't make it into a double.

#include ; #include ; #include ; using namespace std; double* read_data(double& size) { double capacity = 10.0; double* data = new double[capacity]; string input; size = 0.0; cout << "Please enter the integers: "; while (cin >> input && input != "Q") { if (size == capacity) { double* new_data = new double[capacity * 2.0]; memcpy(new_data, data, sizeof(double) * capacity); delete[] data; data = new_data; capacity *= 2.0; } size++; data[size] = atof(input.c_str()); } cout << endl; cout << "The original array is: {"; for (int i = 0; i < size; i++) { cout << data[i]; if (i < size - 1.0) cout << ", "; } cout << "}" << endl << endl; cout << "Please enter new integers: "; while (cin >> input && input != "Q") { if (size == capacity) { double* new_data = new double[capacity * 2.0]; memcpy(new_data, data, sizeof(double) * capacity); delete[] data; data = new_data; capacity *= 2.0; } size++; data[size] = atof(input.c_str()); } cout << endl; cout << "New array is: {"; for (int i = 0; i < size; i++) { cout << data[i]; if (i < size - 1) cout << ", "; } cout << "}" << endl; return data; } int main() { double size; double* data = read_data(size); delete[] data; return 0; }

ex: Please enter the integers: 1.3 4 5.2 16.3 9.99 7.21 4.5 7.43 11.21 12.5 q

// shows 10 arrays output: the original array is: {1.3, 4, 5.2, 16.3, ...., 11.21, 12.5 }

//making the second new array and add with the old array

Please enter new integers: 1.5 4.5 9.5 16.5 7.5 11.5 Q

//shows the new array 16 New array is: {1.3, 4, 5.2, 16.3, ...., 11.21, 12.5, 1.5, 4.5, 9.5, 16.5, 7.5, 11.5}

I'm not sure if it makes sense or not.

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_2

Step: 3

blur-text-image_3

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

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

a. Describe the encounter. What made it intercultural?

Answered: 1 week ago