Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ABOVE ARE THE OUTPUTS FOR THIS PROGRAM, PLEASE HELP ME TO COMPLETE THE C++ CODES.THE FIRST OUTPUT IS UNORDERED ARRAY AND THE SECOND IS ORDERED

image text in transcribed

image text in transcribed

ABOVE ARE THE OUTPUTS FOR THIS PROGRAM, PLEASE HELP ME TO COMPLETE THE C++ CODES.THE FIRST OUTPUT IS UNORDERED ARRAY AND THE SECOND IS ORDERED ARRAY . THANK YOU!

#include

#include

#include

using namespace std;

// -------------------------------------------- functions to be implemented by you

void filter_1(int *a, int& n, int countThreshold)

{

// Input array a[] is not ordered.

// Remove numbers in a[] that appear less than countThreshold number of times.

// Relative order of elements retained in the array need not be preserved.

// Do NOT sort the array a[] in your answer.

}

void filter_2(int *a, int& n, int countThreshold)

{

// Input array a[] is sorted in ascending order.

// Remove numbers in a[] that appear less than countThreshold number of times.

// Relative order of elements retained in the array should be preserved.

}

// ------------------------------------------- functions given to you

void printArray(const char *header, int* a, int n)

{

cout

for (int i = 0; i

{

if (i > 0 && i % 10 == 0)

cout

cout

}

cout

}

void test_1(const char *header, int *a, int& n, int threshold)

{

cout

printArray(header, a, n);

cout

filter_1(a, n, threshold);

printArray(header, a, n);

}

void part_1()

{

cout

int a[] = {1, 2, 3, 3, 1, 4, 4, 4, 5, 8, 6, 6, 5, 5, 2, 5, 5, 1, 7, 7};

int n = 20;

test_1("a[]", a, n, 3);

int b[] = {1, 3, 2, 4, 3, 2, 6, 7, 8, 7};

int m = 10;

test_1("b[]", b, m, 3);

int c[] = {1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 2, 1, 2, 2, 1, 1, 0};

int r = 20;

test_1("c[]", c, r, 5);

}

void test_2(const char *header, int *a, int& n, int threshold)

{

cout

printArray(header, a, n);

cout

filter_2(a, n, threshold);

printArray(header, a, n);

}

void part_2()

{

cout

cout

int a[] = {1, 1, 2, 2, 2, 2, 5, 5, 6, 6, 7, 7, 7, 9, 9, 9, 10, 12, 13, 13};

int n = 20;

test_2("a[]", a, n, 3);

int b[] = {1, 1, 2, 2, 3, 4, 6, 7, 7, 8};

int m = 10;

test_2("b[]", b, m, 3);

int c[] = {0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2};

int r = 20;

test_2("c[]", c, r, 5);

}

int main()

{

part_1();

part_2();

system("pause");

return 0;

}

-ox ID: Work\TEACH\EE2331 - C-Plus-Plus 2020-01\Project-2020-01\Debug Project-2020-01.exe Part_1: Unordered array a[], size = 20 1, 2, 6, 6, 3, 5, 3, 5. 1, 2. 4, 5, 4, 5, 4, 1. 5, 7. 8, 7. Remove numbers that appear less than 3 times. a[], size = 11 1, 1, 5, 5, 1, 4, 4, 4, 5, 5, 5, - , 8, 7, b[], size = 10 1, 3, 2, 4, 3, 2, 6, 7, Remove numbers that appear less than 3 times. b[l, size = 0 C[], size = 20 0, 1, 1, 2, 1, 2, 2, 1, 1, 0, Remove numbers that appear less than 5 times. c[], size = 13 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ID: Work\TEACH\EE2331 - C-Plus-Plus 2020-01\Project-2020-01\Debug\Project-2020-01.exe Part_2: Ordered array a[], size = 20 1, 1, 7, 7, 2, 7, 2, 9, 2, 9, 2, 9, 5, 10, 5, 12, 6, 13, 6, 13, Remove numbers that appear less than 3 times. a[], size = 10 2, 2, 2, 2, 1, 7, 7, 9, 9, 9, ----------- ------------ b[], size = 10 1, 1, 2, 2, 3, 4, 6, 7, 7, 8, Remove numbers that appear less than 3 times. b[], size = 0 - - - - - - - i 1, 2, 1, 2, C[], size = 20 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, Remove numbers that appear less than 5 times. c[l, size = 20 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

More Books

Students also viewed these Databases questions

Question

Challenges Facing Todays Organizations?

Answered: 1 week ago