Question
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started