Question

IN C PROGRAMMING, NOT C++ Rewrite the program you submitted for A8 to use pointers, pointer...

IN C PROGRAMMING, NOT C++

  1. 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 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; see the Notes - Pointers and second video in C10, if necessary
    • Your grade will be better, if your code thoroughly demonstrates using pointers, and pointer notation and arithmetic, and follows the Code Conventions, etc.
  2. Make sure your program thoroughly follows the Code Conventions, including tabs, not multiple spaces, appropriate comments at the top, PPR comments above the function definitions, heading type comments and single blank lines throughout your code to group and organize your code, e.g., // Prototypes, // Input, // Output, etc.

Here is Assignment A8 for reference.

  1. Above main(), where appropriate, create a constant for the size of the array in step 2.
  2. In main(), create an array called grade using the constant from step 1 and initialize it to zero.
  3. Below main(), create a function called getData(), which takes and processes an array called array along with its size, and fills it with numbers given by the user. Use an array reference, not a pointer, and do NOT use a constant for this function. Also, the function does not return anything.
  4. In main(), call getData() passing the grade array and its size to the function.
  5. Below main(), create a function called displayData(), which takes and processes an array called array along with its size, and retrieves and displays the values from the array to the screen formatted professionally with decimal points aligned if appropriate. Use an array reference, not a pointer, and do NOT use a constant for this function. Also, the function does not return anything.
  6. In main(), call displayData() passing the grade array and its size to the function.
  7. In main(), using a for loop, display the data in the grade array. Do NOT use the function displayData() for this step.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

#include<stdio.h>
#include<conio.h>

#define SIZE 6 //define the size of array

void getData(double *array, int size){
  
   int i;
   printf("Please Enter %d numbers\n", size);
  
   for(i=0; i<size; i++){
       scanf("%lf", (array+i));//input the values from command line
   }
}

void displayData(double *array, int size){
  
   printf("\n\n ----------------- Displaying the array data ----------------------\n\n");
  
   int i;
  
   printf("\n------- Method 1 ----------\n\n");
  
   for(i=0; i<size; i++){
       printf("%.2lf ", array[i]);//print the numbers to 2 decimal places
   }
  
   printf("\n\n\n------- Method 2 ----------\n\n");
  
   for(i=0; i<size; i++){
       printf("%.2lf ", *(array+i));//print the numbers to 2 decimal places
   }
  
   printf("\n\n\n------- Method 3 ----------\n\n");
  
   for(i=0; array+i < array+size; i++){
       printf("%.2lf ", array[i]);//print the numbers to 2 decimal places
   }
  
   printf("\n\n\n------- Method 4 ----------\n\n");
  
   for(i=0; array+i < array+size; i++){
       printf("%.2lf ", *(array+i));//print the numbers to 2 decimal places
   }
}

void main(){
  
   double grade[SIZE];//create grade array of size=SIZE i.e 6
   getData(grade, SIZE);//input the data to the array
   displayData(grade, SIZE);//print the array data
   getch();//hold the console output
}

SCREENSHOTS:

OUTPUT:

In case of any doubts, dolet me know in the comments section. I'll get it resolved :)

Add a comment
Know the answer?
Add Answer to:
IN C PROGRAMMING, NOT C++ Rewrite the program you submitted for A8 to use pointers, pointer...
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
  • 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...

  • 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;...

  • Write in C code: Define an array f=[23,-12,34,-56,-10,12,19], using call-by-reference (use pointers), to pass the array...

    Write in C code: Define an array f=[23,-12,34,-56,-10,12,19], using call-by-reference (use pointers), to pass the array to a function, named Summation. In main: Define array, pass array, print out the array and the result returned from Summation on screen. In function Summation: 1)take array and size from main 2) sum each element according to the following rules 3) if the value of f(i) is positive, add 2*f(i) to the sum 4)if the value of f(i) is negative, add -3*f(i) to...

  • C programming. 1.Create a program that does the following - Creates three pointers, a character pointer...

    C programming. 1.Create a program that does the following - Creates three pointers, a character pointer professor, and two integer pointers student_ids, grades - Using dynamic memory, use calloc to allocate 256 characters for the professor pointer - Prompts the professor for their name, and the number of students to mark. - Stores the professor’s name using the professor pointer and in an integer the number of students to mark. - Using dynamic memory, use malloc to allocate memory for...

  • Here's an assignment that'll give you some practice with pointers. All you have to do is...

    Here's an assignment that'll give you some practice with pointers. All you have to do is write a program that allows the user to populate an array of doubles (5 values) by calling the function InitArray. After the user has entered all the values, then call the function DispRevArray to display the array in reverse. Main will create and allocate space for an array of type double for 5 elements. Then you will create and allocate a pointer that will...

  • Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers...

    Hello I need help with this program. Should programmed in C! Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...

  • C programming 3. (40 pts) Define an array fof size 10, using call-by-reference (that is, use...

    C programming 3. (40 pts) Define an array fof size 10, using call-by-reference (that is, use of pointers), to pass the array to a function, named summation In main: define array, pass array, print out the array and the results on screen In function summation: take array from main and sum the array using the formula below: 10 fO 2 246 NOTE: you must use call-by-reference (the pointer) to call functions, as required; otherwise, no credits will be given.

  • Using C programming

    Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...

  • In Exercise 1, displayAnimal uses an Animal reference variable as its parameter. Change your code to...

    In Exercise 1, displayAnimal uses an Animal reference variable as its parameter. Change your code to make the displayAnimal function anim parameter as an object variable, not a reference variable. Run the code and examine the output. What has changed? Polymorphic behavior is not possible when an object is passed by value. Even though printClassName is declared virtual, static binding still takes place because anim is not a reference variable or a pointer. Alternatively we could have used an Animal...

  • Question: C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to prov......

    Question: C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to prov... C Programming Problem: Pointer and Struct Description: The purpose of this assignment is to provide practice programming using structs and pointers. Your program will accept user input and store it in a dynamic array of structs. First, you will define a structure to describe a item to be bought. Your program will prompt the user for the initial size of the array. It will...

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