Question: Assignment: Write a program in C++ that takes a partially filled array and removes all duplicate values. Your program should use only one array (i.e.

Assignment: Write a program in C++ that takes a partially filled array and removes all duplicate values. Your program should use only one array (i.e. characters). Your array should be defined as follows:

char characters[45] = {'a','b','c','d','f','e','a','c','c','d','d','e','a','f','g','h','c','c','h','c'};

int charCount = 20;

You should create a function that takes the character array and the number of characters in the array as parameters. Within that function remove any duplicates and update the charCount variable to reflect the new character count in the array.

At the end of the program the array will contain: {'a','b','c','d','f','e','g','h'} and charCount will be 8.

HINTS:

a. Remember, you have to pass the charCount variable by reference in order to change the value in your function.

b. You will have to loop through the characters array once to find out which characters are present. Depending on how you do it you may have to loop through multiple times.

c. You will probably find it helpful to create a second function that is responsible for removing the duplicate characters.

// Skeleton

#include "stdafx.h" // this is windows specific

#include

using namespace std;

void removeDuplicates(char characters[], int& charCount);

void showResults(char characters[], int& charCount);

int main()

{

char characters[45] = { 'a','b','c','d','f','e','a','c','c','d','d','e','a','f','g','h','c','c','h','c' };

int charCount = 20;

removeDuplicates(characters, charCount);

showResults(characters, charCount);

return 0;

}

void removeDuplicates(char characters[], int & charCount)

{

// do all your deduplicating

// don't forget to update charCount

}

void showResults(char characters[], int & charCount)

{

// output some appropriate explaination and display the content of the

// deduplicated array.

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!