Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CONVERT TO C++ NEED ASAP PLEASE #include #include #include int arr[1000]; int size; // thread to calculate average void *calculate_avg(){ int sum = 0, i;

CONVERT TO C++

NEED ASAP PLEASE

#include

#include

#include

int arr[1000];

int size;

// thread to calculate average

void *calculate_avg(){

int sum = 0, i;

float average = 0;

for(i=0; i < size; i++){

sum += arr[i];

}

average = sum / size;

printf("The average value is %f ", average);

}

// thread to calculate minimum

void calculate_min(){

int i, minimum = 999999999;

for(i=0; i < size; i++){

if(minimum > arr[i]){

minimum = arr[i];

}

}

printf("The minimum value is %d ", minimum);

}

// thread to calculate maximum

void *calculate_max(){

int i, maximum = -999999999;

for(i=0; i < size; i++){

if(maximum < arr[i]){

maximum = arr[i];

}

}

printf("The maximum value is %d ", maximum);

}

// the main function

void main(int argc, char *argv[]){

if(argc <= 1){

printf("Please enter at least one argument through command line ");

printf("Exitting . . . ");

exit(1);

}

pthread_t avg_thread;

pthread_t max_thread;

pthread_t min_thread;

int i;

size = argc - 1;

// read the values from command line convert them to integer

// values and insert into array

for(i=1; i <= size; i++){

arr[i-1] = atoi(argv[i]);

}

// create three threads

pthread_create(&avg_thread, NULL, (void *)calculate_avg, NULL);

pthread_create(&min_thread, NULL, (void *)calculate_min, NULL);

pthread_create(&max_thread, NULL, (void *)calculate_max, NULL);

// wait for completion of each of the threads.

pthread_join(avg_thread, NULL);

pthread_join(min_thread, NULL);

pthread_join(max_thread, NULL);

}

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

U11 Informing Industry: Publicizing Contract Actions 317

Answered: 1 week ago

Question

4. Did you rethink your decision?

Answered: 1 week ago

Question

3. Did you seek anyones advice?

Answered: 1 week ago

Question

7. What traps should she avoid?

Answered: 1 week ago