Write a code in C++

label Programming
account_circle Unassigned
schedule 1 Day
account_balance_wallet $5

Write a piece of code in C++. Function that checks binary file char elements and delete the repeating ones (for example, if in file I have a a b c b, output should be a b c)

May 13th, 2015

#include <iostream>
using namespace std;

void fillArray(int a[], int size, int& numberUsed);

void sort(int a[], int numberUsed);

void deleteRepeats(char a[],int& n);

int indexOfFirst(const int a[], int startIndex, int numberUsed);

int main()
{
    cout << "This program sorts characters and deletes any repeated characters.\n";

    int size = 4;
    char a[10];

    fillArray(sampleArray, 10, numberUsed);
    sort(sampleArray, numberUsed);
    deleteRepeat(a, size);

    cout << "In sorted order the letters are:\n";
    for (int index = 0; index < numberUsed; index++)
        cout << sampleArray[index] << " ";
    cout << endl;

    return 0;
}

void fillArray(int a[], int size, int& numberUsed)
{
    cout << "Enter up to " << size << " letters or characters.\n"
         << "Mark the end of the list with a negative number.\n";
    int next, index = 0;
    cin >> next;
    while ((next >= 0) && (index < size))
    {
        a[index] = next;
        index++;
        cin >> next;
    }

    numberUsed = index;
}

void sort(int a[], int numberUsed)
{
    int indexOfNextSmallest;
    for (int index = 0; index < numberUsed - 1; index++)
    {
        indexOfNext = indexOfFirst(a, index, numberUsed);

    }
}

void delete_Repeats(char a[],int& n)
{
    int i,j,k;

    for(i=0; i<n-1; i++)
        for(j=i+1; j<n; j++)
            if(a[i]==a[j])
            {
                for(k=j; k<n; k++)
                {
                    a[k]=a[k+1];
                        n--;
                        j--;
                }
}

int indexOfSmallest(const int a[], int startIndex, int numberUsed)
{
    int min = a[startIndex],
        indexOfMin = startIndex;
    for (int index = startIndex + 1; index < numberUsed; index++)
        if (a[index] < min)
        {
            min = a[index];
            indexOfMin = index;
        }
    return indexOfMin;

May 13th, 2015

Studypool's Notebank makes it easy to buy and sell old notes, study guides, reviews, etc.
Click to visit
The Notebank
...
May 13th, 2015
...
May 13th, 2015
Sep 21st, 2017
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer