//CSE9B Assignment 3 //Programming Project 3, Chapter 9 //CSE 9 B Winter 1997 UCSD //Assignment 3 //This program tests the function delete_repeats. //You put your name(s), email address, file name, and date last changed. #include const int MAX = 20; void input_data(char a[], int& size); //Postcondition: a has been filled with MAX or fewer characters //read from the keyboard. size is equal to the number of characters read. void new_line(istream& in_stream); //Discards all the input remaining on the current input line. void output_data(const char a[], int size); //Precondition: a contains size or more elements. //Postcondition: a[0] through a[size-1] have been written to the screen. //on one line with no spaces and output has been advanced to the //next line. void delete_repeats(char a[], int& size); //Precondition: a has values for a[0] to a[size - 1]. //Postcondition: All repeated values in a have been removed. //The remaining values have been moved down so they fill //an initials segment of the array. size has been changed //to the number of values left. int main() { char a[MAX]; int size; char ans; cout << "This program tests the function delete_repeats.\n" << "Be sure to test an array with zero elements,\n" << "one with only one element, a long array with\n" << "all the same letter, and lots of other cases." << endl << endl; do { input_data(a, size); cout << "Before deletes array contains:\n"; output_data(a, size); cout << "size = " << size << endl; delete_repeats(a, size); cout << "After deletes array contains:\n"; output_data(a, size); cout << "size = " << size << endl; cout << "Test again?(y/n)"; cin >> ans; new_line(cin); }while ((ans != 'n') && (ans != 'N')); } //Uses iostream.h: void new_line(istream& in_stream) { char symbol; do { in_stream.get(symbol); } while (symbol != '\n'); }