Question

Modify the following C code to the changes listed below. Please format code correctly. #include <stdio.h>...

Modify the following C code to the changes listed below. Please format code correctly.

#include <stdio.h>

#include <stdlib.h>

#define SIZE 5

void displayData(int [], int s);

void getData(int array[], int size)

{

    for(int i=0; i<SIZE; i++)

    {

        scanf("%d", &array[i]);

    }

}

int main()

{

    int grades[SIZE];

    for(int i=0; i<SIZE; i++)

    {

        grades[i] = 0;

    }

    getData(grades,SIZE);

    displayData(grades, SIZE);

}

void displayData(int grades[], int size)

{

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

    {

        printf("%d ", grades[i]);

    }

}

system("pause");

return 0;

}

----

These are the changes that need to be made.

  • The main() function should:
    • Create a fixed or dynamic array, e.g., double grade[SIZE] or double *grade = malloc(...) or calloc(...)
    • Concerning the function call for getData(), pass the address of the array and its size to pointers; depending on how you change your program, it may or may not return something, but if it does, it should return an address. i.e., a pointer
    • Concerning the function call for displayData(), pass the address of the array and its size to pointers, and return nothing
    • Use the final for loop, which displays the contents of the array again without using displayData(), to demonstrate one of the ways, you can use pointers to manipulate an array; see below for more information
  • The for loops, inside of the getData() and displayData() functions, should use different ways to demonstrate how to manipulate an array, e.g., p < q vs. p + i < p + size, or whatever
0 0
Add a comment Improve this question Transcribed image text
Answer #1

// do comment if any problem arises

//code

#include <stdio.h>

#include <stdlib.h>

#define SIZE 5

void displayData(int[], int s);

void getData(int array[], int size)

{

    for (int i = 0; i < SIZE; i++)

    {

        scanf("%d", array + i);

    }

}

int main()

{

    int grades[SIZE] = {0};

    getData(grades, SIZE);

    displayData(grades, SIZE);

    // Use the final for loop, which displays the contents

    // of the array again without using displayData(),

    for (int *i = grades; i < grades + SIZE; i++)

        printf("%d ", *i);

    printf("\n");

    system("pause");

    return 0;

}

void displayData(int grades[], int size)

{

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

    {

        printf("%d ", grades[i]);

    }

    printf("\n");

}

Output:

Add a comment
Know the answer?
Add Answer to:
Modify the following C code to the changes listed below. Please format code correctly. #include <stdio.h>...
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
  • IN C PROGRAMMING, NOT C++ Rewrite the program you submitted for A8 to use pointers, pointer...

    IN C PROGRAMMING, NOT C++ Rewrite the program you submitted for A8 to use pointers, pointer notation and arithmetic, etc. as follows: If you did not complete A8, you will need to start with those instructions, and then, change your code based on the instructions here The main() function should: Create a fixed or dynamic array, e.g., double grade[SIZE] or double *grade = malloc(...) or calloc(...) Concerning the function call for getData(), pass the address of the array and its...

  • Rewrite the program you submitted for A8 to use pointers, pointer notation and arithmetic, etc. as...

    Rewrite the program you submitted for A8 to use pointers, pointer notation and arithmetic, etc. as follows: If you did not complete A8, you will need to start with those instructions, and then, change your code based on the instructions here The main() function should: Create a fixed or dynamic array, e.g., double grade[SIZE] or double *grade = malloc(...) or calloc(...) Concerning the function call for getData(), pass the address of the array and its size to pointers; depending on...

  • Fix this C++ code so that the function prototypes come before main. Main needs to be...

    Fix this C++ code so that the function prototypes come before main. Main needs to be declared first. Then call to the functions from inside of main. #include<cstdlib> using namespace std; //prompt user for input void getGrades(int gradeArray[],int size) { for(int i=0; i<size; i++) { cout<<"Enter the grade "<<i+1<<": "; cin>>gradeArray[i]; } } // finding average of all numbers in array float computeAverage(int numbers[],int size) { float sum=0; for(int i=0; i<size; i++) { sum = sum + numbers[i]; //compute sum...

  • Modify this C++ below to show the selection sorting algorithm method. Then write a test program...

    Modify this C++ below to show the selection sorting algorithm method. Then write a test program and show that it works. HINT: Replace the bubbleSort function with the selectionSort. Your test program should perform the following steps: Create an array of random numbers. Display the array in its original order. Pass the array to your sorting function. Display the array again to show that it has been sorted. Provide a screen shot showing that the above steps are working. CODE:...

  • Consider the syntactically correct C code below, which is missing a function copy_positive. #include <stdio.h> /*...

    Consider the syntactically correct C code below, which is missing a function copy_positive. #include <stdio.h> /* copy_positive(A, Aout, size) * Given an array A, which will have the provided size, copy all positive * (non-negative/non-zero) elements of A into the provided output array Aout. * Return the size of the resulting array. */ /* (your code from below would be placed here) */ void print_array(int arr[], int n){ for( int i = 0; i < n; i++ ) printf("%d ",...

  • Please in C Language Thank you! The following program source code is incomplete 1 #include <stdio.h> 2 3 // TODO:...

    Please in C Language Thank you! The following program source code is incomplete 1 #include <stdio.h> 2 3 // TODO: 1) Add the typedef here: 5// TODO: 2) Modify the parameter of repeat to add irn the function pointer for the function to be called repeatedly: 8 void repeat (int times) for (int k 0; k < times; ++k) 12 // TODO: 3) Add the call to the function pointer here: 14 15 17 void test (void) 18 printf("Test!\n"); 19...

  • I need the pseudocode for this c program source code. #include<stdio.h> void printarray(int array[], int asize){...

    I need the pseudocode for this c program source code. #include<stdio.h> void printarray(int array[], int asize){ int i; for(i = 0; i < asize;i++) printf("%d", array[i]); printf("\n"); } int sum(int array[], int asize){ int result = 0; int i = 0; for(i=0;i < asize;i++){ result = result + array[i]; } return result; } int swap( int* pA,int*pB){ int result = 0; if(*pA > pB){ int tamp = *pA; *pA = *pB; *pB = tamp; result = 1; } return result;...

  • *** Please construct a flowchart for the following code (this was in C++): *** #include using...

    *** Please construct a flowchart for the following code (this was in C++): *** #include using namespace std; void printPrompt(int n){    switch(n){        case 1:            cout << "Enter the quiz grades:" <            break;        case 2:            cout << "Enter the assignments grades:" <            break;        case 3:            cout << "Enter the exam grades:" <            break;        case...

  • Arrays in Functions 2. Arrays in Functions You can use both the array index variables and...

    Arrays in Functions 2. Arrays in Functions You can use both the array index variables and the entire array itself as arguments to functions. The following program updates the elements of the array grades, one-by-one. Thus, we have used a call-by-reference-ish mechanism to update the values (although no & was used). Note that there is a major difference between the grade in the function call and the one in the function definition. In the statement get_grade (grades[i]); "grades" is the...

  • Please help!! I am supposed to write a program in C++ about student & grades. Needs...

    Please help!! I am supposed to write a program in C++ about student & grades. Needs to have two functions that sorts students letter grade, and another one to sort Students name in your student’s record project. Remember, to add necessary parameters and declaration in main to call each function properly. Order of functions call are as follow Read Data Find Total Find average Find letter grade Call display function Call sort letter grade function Call display function Call sort...

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