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

Please put it here so I can copy the answer. Not on a sheet of paper Project 3 W

ID: 3599464 • Letter: P

Question



Please put it here so I can copy the answer. Not on a sheet of paper Project 3 Write a function called delete_repeats that has a partially filled array of characters as a formal parameter and that deletes all repeated letters from the array. Since a partially filled array requires two arguments, the function will actually have two formal parameters: an array parameter and a formal parameter of type int that gives the number of array positions used. Whern a letter is deleted, the remaining letters are moved forward to fill in the gap This will create empty positions at the end of the array so that less of the array is used. Since the formal parameter is a partially filled array, a second formal parameter of type int wll tell how many array positions are filled This second formal parameter will be a call-by-reference parameter and will be changed to show how much of the array is used after the repeated letters are deleted

Explanation / Answer

Solution:

code:

#include<iostream>
using namespace std;
  
void introduction();
void input(char word[], int& size);
void delete_repeats(char word[], int& size);
  
int main()
{
    int counter, size, A;
    char array[81];
    input(array,size);
    delete_repeats(array,size);
    cout << "resulting array: ";
    for( int i = 0; i < size; i++ ) {
       cout << array[i] << " ";
    }
    cout << endl << endl << endl;
    system("pause");
    return 0;
}

void input(char word[], int& size)
{
    int counter = 0;
    cout << endl;
    cout << "counter = " << counter; // for testing purposes
    cout << endl;

    do
    {
        cin.get(word[counter]);
        cout << endl;
        cout << "counter = " << counter; // for testing purposes
        cout << "; word[" << counter << "] = " << (int)word[counter];
        cout << endl;
        counter++;

    }while (word[counter-1] != ' ');
    size = counter - 1;
    cout << size << " size"; // for testing purposes
    cout << endl;
    cout << endl;
    cout << "counter = " << counter; // for testing purposes
    cout << endl;
}
void delete_repeats(char word[], int& size)
{
    int counter = 0;
    for (int i = 0; i < size; i++)
    {

        for (int j = i+1; j < size; j++)
        {
            if (word[i] == word[j])
            {
  
                for (int k = j; k < size - 1; k++)
                {

                    word[k]= word[k + 1];
                }
                j--;
                size--;
            }
            cout << "size = " << size;
            cout << endl;
        }
    }
}

Please, please upvote and ask your doubts in the comments.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote