Question

PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU!

Hint: the number array in task 2 is work for task 3 in figure 1.  

Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #in

Task 2: (15 pts) Complete the given program by adding the following to the main() function. To hand in: The source program. a

3.2 (15 pts) Complete the definition of the new function, and test it by using the two arrays you prepared for the first task

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program logic:

  • In the function averageDifference(), set sum = 0
  • then loop through each element of arr1
    • subract the current element of arr1 and its counter part in arr2.
    • add the result to sum
  • once the fucntion is out of the loop, divide the sum by SIZE and return the value

flow chart

오로 false HITE

function definiton:

double averageDifference(int arr1[SIZE], int arr2[SIZE]){
int sum = 0;
for(int i = 0; i<SIZE; i++){
sum += arr1[i]-arr2[i];
printf("arr1[%d] - arr2[%d]: %d\n", i,i,arr1[i]-arr2[i]);
}
return (double)(sum/SIZE);
}

program to call this function:

#define SIZE 9
#include <stdio.h>

int compareAndCount(int[], int[]);
double averageDifference(int[], int[]);

void main(){
int arr1[] = {111,2,333,44,55,16,27,83,99};
int arr2[] = {-11,22,13,88,99,101,34,25,-22};
double ave = averageDifference(arr1,arr2);
printf("The average difference between items in array A and array B: %.2f\n", ave);
}

double averageDifference(int arr1[SIZE], int arr2[SIZE]){
int sum = 0;
for(int i = 0; i<SIZE; i++){
sum += arr1[i]-arr2[i];
printf("arr1[%d] - arr2[%d]: %d\n", i,i,arr1[i]-arr2[i]);
}
return (double)(sum/SIZE);
}

output:

arr1[0] arr2[0]: 122 arr1[1] - arr2[1]: -20 arr1[2] - arr2[2]: 320 arr1[3] - arr2[3]: -44 arr1[4] - arr2[4]: -44 arr1[5] - ar

Add a comment
Know the answer?
Add Answer to:
PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU! Hint:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU! Given...

    PLEASE HELP ME WITH THIS TASK 3.1 (FLOWCHART) AND TASK 3.2 (SOURCE PROGRAM). THANK YOU! Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count = 0; for (int i = 0; i < SIZE; i++) { if (arri[i] > arr2[i]) count++; } return count;...

  • Given below is a partially completed C program, which you will use as a start to...

    Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count - @; for (int i = 0; i < SIZE; i++) { if (arri[i] > arr2[i]) count++; return count; Task 1: (10 pts) Show the design of the function compareAndCount() by writing a pseudocode. To...

  • I NEED HELP WITH THIS 2 PROBLEMS PLEASE! THANK YOU SO MUCH Given below is a...

    I NEED HELP WITH THIS 2 PROBLEMS PLEASE! THANK YOU SO MUCH Given below is a partially completed C program, which you will use as a start to complete the given tasks. #define SIZE 9 #include <stdio.h> int compareAndCount (int[], int[]); double averageDifference (int[], int[]); void main() { } int compareAndCount(int arr1[SIZE], int arr2[SIZE]) { int count = @; for (int i = 0; i < SIZE; i++) { if (arr1[1] > arr2[i]) count++; return count; } Task 1: (10...

  • Your goal is to create an ‘Array’ class that is able to hold multiple integer values....

    Your goal is to create an ‘Array’ class that is able to hold multiple integer values. The ‘Array’ class will be given functionality through the use of various overloaded operators You will be given the main() function for your program and must add code in order to achieve the desired result. Do not change any code in main(). If something is not working, you must change your own code, not the code in main(). Assignment 5: overloading member functions. Overview:...

  • I NEED HELP WITH THE FLOWCHART AND PSEUDOCODES OF THIS PROGRAM PLEASE! +3) (5 pts) Show...

    I NEED HELP WITH THE FLOWCHART AND PSEUDOCODES OF THIS PROGRAM PLEASE! +3) (5 pts) Show the screen output of running the following program. #include <stdio.h> Screen output: int f1(int, int); //function declaration void f2(int); int main() { printf("calling f1( ) ..\n"); int flResult = f1(7,-8); printf("flResult = %d\n", f1Result); }//main) int f1(int a, int b) { printf("in f1(): a = %d, b = %d\n", a, b); int data = -1; if (a >b) data = a - b: return...

  • I need this program converted to c++ Please help if you can import java.util.*; // Add...

    I need this program converted to c++ Please help if you can import java.util.*; // Add two arrays of the same size (size) // Each array is a representation of a natural number // The returned array will have the size of (size + 1) elements public class Fibonacci { private static String arrToString(int[] arr) {           String s = "";           for (int i = 0; i < arr.length; i++) {               s = s + arr[i];           }...

  • Complete a program In C#: some code is included, you edit the areas that have not...

    Complete a program In C#: some code is included, you edit the areas that have not been filled. For your C# program you will complete code that plays the War card game. In this game, the deck of cards is evenly divided among two players. The players are not allowed to look at the cards in their hand. On each round of the game, both players lay down the top card from their hand. The player with the higher value...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • COULD YOU PLEASE HELP ME************************** write a better mode computation function that uses the ideas in...

    COULD YOU PLEASE HELP ME************************** write a better mode computation function that uses the ideas in the word file and improves on the mode computation function in the cpp file. ===========source.cpp #include <ctime> #include <iomanip> #include <iostream> #include <string> #include <random> using namespace std; default_random_engine e(static_cast<unsigned>(time(NULL))); void fill(int a[], int size, int value) { for(int i = 0; i < size; i++) a[i] = value; } void randomFill(int a[], int size, int lb, int up) { uniform_int_distribution<int> u(lb, up); for(int...

  • in C++ and also each function has its own main function so please do the main...

    in C++ and also each function has its own main function so please do the main function as well. Previously when i asked the question the person only did the function and didn't do the main function so please help me do it. 1-1. Write a function that returns the sum of all elements in an int array. The parameters of the function are the array and the number of elements in the array. The function should return 0 if...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT