Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

i need a c++ program: Write a program containing the following functions: main -

ID: 3689566 • Letter: I

Question

i need a c++ program:

Write a program containing the following functions:

main - calls the other functions; otherwise does nothing

getSize - which asks the user how many strings they want

getSpace - which gets an array in the heap of the size requested by the user

inputData - which allows the user to input the strings and stores them

in the array

printData - which prints all the strings, one string per line

destroy - which returns all the space to the heap

All of these functions, except main, shall have a return type of void.

Put the main function first.

Use the function names specified above.

Arrange the functions in the order listed above.

Explanation / Answer

#include <iostream>
#include <string>

using namespace std;
void getSize(int&);
void getSpace(int, string*);
void inputData(int, string*);
void printData(string* , int);
void Destroy(string*);

int main()
{
int size;
string* ptrSpace;

getSize(size);
getSpace(size, ptrSpace);
inputData(size, &ptrSpace);
printData(&ptrSpace, size);
Destroy(&ptrSpace);

}

/*********** getSize ************
Ask user to input how many strings
they want.
*/

void getSize(int &size)
{
cout << "How many strings do you want? ";
cin >> size;
}

/*********** getSpace ************
gets an array in heap of the size
requested by the user
*/

void getSpace(int size, string*& str)
{
str = new string[size];
}

/*********** inputData ************
Allow users to input string values
and store them in the array
*/

void inputData(int size, string* space)
{
cout << "Type your string: ";
string data;
for (int i = 0; i < size; i++)
{
cin >> data;
cout << data << endl;
space[i] = data;
cout << space[i];
}
}

/*********** printData ************
Print out all the strings
One string per line
*/

void printData( string* space, int &size)
{
for (int i = 0; i < size; i ++)
{
cout << space[i] << endl;
}
}

/*********** Destroy ************
Retrun all the space to the heap
*/

void Destroy(string* space)
{
delete [] space;
}