C++ FORMAT PLEASE: THIS IS THE ASSIGNMENT: Write a program containing the follow
ID: 3689497 • Letter: C
Question
C++ FORMAT PLEASE:
THIS IS THE ASSIGNMENT:
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.
THIS IS WHAT I HAVE SO FAR AND I DONT KNOW HOW TO FIX IT IF YOU CAN PLEASE HELP ME!
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
void getSize (int *size);
void getSpace (string *& pStrArr, int size);
void inputData (string &pStrArr, int size);
void printData (string *&pStrArr, int size);
void destroy (string *pStrArr);
int main ()
{
string *pStrArr;
int size;
getSize (&size);
getSpace (pStrArr, size);
inputData (*pStrArr, size);
printData (pStrArr, size);
destroy (pStrArr);
return 0;
}
void getSize (int *size)
{
cout << "Enter in how many strings you would like" << endl;
cin >> *size;
cin.ignore();
}
/************getSpace************
*/
void getSpace (string *& pStrArr, int size)
{
if (num <= )
}
/**********inputData*************
*/
void inputData (string &pStrArr, int size)
{
}
/***********printData*************
*/
void printData (string *&pStrArr, int size)
{
for (int i = 0; i < size; i++)
cout << "string number" << i + 1 << " : " << pStrArr[i] <<
}
/************Destroy**************
returns all the space to the heap.
function accepts a pointer to string array
*/
void destroy (string *pStrArr)
{
delete [] pStrArr;
pStrArr = 0;
}
Explanation / Answer
There is lot of bugs in your code so here is the remodified version and queries please comment
#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 sizeOfString;
string* ptrSpace;
getSize(sizeOfString);
getSpace(sizeOfString, ptrSpace);
inputData(sizeOfString, &ptrSpace);
printData(&ptrSpace, sizeOfString);
Destroy(&ptrSpace);
}
void getSize(int &sizeOfString)
{
cout << "how many strings do you want? ";
cin >> sizeOfString;
}
void getSpace(int sizeOfString, string*& str)
{
str = new string[sizeOfString];
}
void inputData(int sizeOfString, string *space)
{
cout << "now put string you want : ";
string data;
for (int i = 0; i < sizeOfString; i++)
{
cin >> data;
cout << data << endl;
space[i] = data;
cout << space[i];
}
}
void printData( string *space, int sizeOfString)
{
for (int i = 0; i < sizeOfString; i ++)
{
cout << space[i] << endl;
}
}
void Destroy(string *space)
{
delete [] space;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.