#include <iostream>
void introduction();
//Explains what the program does
void fill_array(char a[], int size, int& number_used);
//Array a[] is filled with character data from the keyboard
void delete_repeats(char a[], int& number_used);
//Function will remove all repeated characters and move the rest of the characters
//foward to fill in the gap.
void output(char a[], int& number_used);
//Outputs the contents of the array and outs the new size of the array
int main()
{
usingnamespace std;
char array[100];
int number_used;
introduction();
fill_array(array, 100, number_used);
output(array, number_used);
}
//uses iostream
void introduction()
{
usingnamespace std;
cout << "Enter a text string to test:\n";
}
//uses iostream
void fill_array(char a[], int size, int& number_used)
{
usingnamespace std;
char c;
int index = 0;
cout << "Please type in a sentence and then press enter.\n";
cin.get(c);
while (c != '\n' && index < size) {
a[index] = c;
cin.get(c);
index++;
}
number_used = index;
for (int i = 0; i < number_used; i++) {
for (int j = i + 1; j < number_used; j++) {
if (a[i] == a[j]) {
cout << a[i] << " duplicates found at "
<< i << " and " << j <<std::endl;
number_used=number_used-1;
for (int k = j; k < number_used; k++)
a[k] = a[k + 1];
a[number_used] = '\0';
cout << a <<std::endl;
cout << number_used<<std::endl;
--i; break;
}
}
cout << a[i]<<std::endl;
cout << number_used<<std::endl;
}
cout << number_used<<std::endl;
}
//uses iostream
void output(char a[], int& number_used)
{
usingnamespace std;
cout << "The new sentence without the repeated letters is:\n";
for (int i = 0; i < number_used; i++) {
cout << a[i];
}
cout << "\nThe size of the new array is "
<< number_used
<< endl;
cin.ignore();
cin.get();
}
If you're outputting information you don't want to, that implies there are some couts that you want to get rid of. Do any of the ones on lines 61, 62, 66, 67, and 69 seem like ones you'd want to get rid of?
#include <iostream>
void introduction();
//Explains what the program does
void fill_array(char a[], int size, int& number_used);
//Array a[] is filled with character data from the keyboard
void delete_repeats(char a[], int& number_used);
//Function will remove all repeated characters and move the rest of the characters
//foward to fill in the gap.
void output(char a[], int& number_used);
//Outputs the contents of the array and outs the new size of the array
int main()
{
usingnamespace std;
char array[100];
int number_used;
introduction();
fill_array(array, 100, number_used);
output(array, number_used);
}
//uses iostream
void introduction()
{
usingnamespace std;
cout << "Enter a text string to test:\n";
}
//uses iostream
void fill_array(char a[], int size, int& number_used)
{
usingnamespace std;
char c;
int index = 0;
cout << "Please type in a sentence and then press enter.\n";
cin.get(c);
while (c != '\n' && index < size) {
a[index] = c;
cin.get(c);
index++;
}
number_used = index;
for (int i = 0; i < number_used; i++) {
for (int j = i + 1; j < number_used; j++) {
if (a[i] == a[j]) {
cout << a[i] << " duplicates found at "
<< i << " and " << j <<std::endl;
number_used=number_used-1;
for (int k = j; k < number_used; k++)
a[k] = a[k + 1];
a[number_used] = '\0';
--i; break;
}
}
}
}
//uses iostream
void output(char a[], int& number_used)
{
usingnamespace std;
cout << "The new sentence without the repeated letters is:\n";
for (int i = 0; i < number_used; i++) {
cout << a[i];
}
cin.ignore();
cin.get();
}
Now I have to clean it up and put the namespace on the outside.