inline void keep_window_open() { using std::cout; cout << "\nPress any key to exit:"; getchar(); }
std::string* deleteEntry(std::string *dynamicArray, int& size, std::string newEntry); // Precondition: size is the SIZE of dynamicArray[], a dynamically allocated array // Postcondition: newEntry, if can be found in dynamicArray, is deleted, // while all of the other elements are preserved in a new array
void display(std::string *array, const int size); // Postcondition: as its name implies
int main() { using namespace std; int size; cout<<"Input the size of the original string array:\t"; cin>>size; while(size <= 0) { cout<<"\nThe size must be a positive integer!\n"; cin>>size; } string *sArray=new string [size]; for(int i=0; i < size; ++i) { cout<<"The "<<i+1<<"th string:\t"; cin>>sArray[i]; } string *newArray; newArray=sArray; cout<<"\nThis is the array you gave:\n"; display(newArray,size);
char decision; cout<<"\nWould you like to delete some elements?\n"; cin>>decision; if(decision != 'n' && decision != 'N') { cout<<"\nDetermine which element you want to delete from it:\n"; string newEntry; while(cin>>newEntry) { newArray=deleteEntry(newArray,size,newEntry); cout<<"\nAfter the deletion, it becomes:\n"; display(newArray,size); cout<<endl; } cin.clear();