[Solved] COMP1410 Lab 5-More on Pointers

$25

File Name: COMP1410_Lab_5-More_on_Pointers.zip
File Size: 292.02 KB

SKU: [Solved] COMP1410 Lab 5-More on Pointers Category: Tag:
5/5 - (1 vote)

: Learn to use pointers and operators at a more advanced level.

  1. Pointer Operators

Type the following program and document every line by explaining its function and output. If any line produces an error, comment that specific line and explain the nature of the error. Write your code for this part in a file called: Lab5a.c

#include <stdio.h>

int main()

{

int a = 7 ;

int *aPtr ;

aPtr = &a ;

printf( %p, &a );

printf( %p, aPtr );

printf( %p, &aPtr );

printf( %d, a );

printf( %d, *aPtr );

printf( %p, *&aPtr );

printf( %p, &*aPtr );

printf( %d, *&a );

printf( %d, &*a );

return 0;

}

  1. Array Manipulation with Pointers

Write, document and test each of the following function specifications (write your code for this part in a file called: Lab5b.c):

[You should use only pointer arithmetic DO NOT USE array indices (i.e. subscripts)].

  1. A function called FillArray() that accepts a pointer to a integer as the array name, an integer for its size. This function pseudo-randomly fills the array with integers ranging from 0 to 100. Do not be concerned about possible duplicate values.
  2. A function called PrintArray() that accepts a pointer to a integer as the array name, an integer for its size. This function only prints the array elements.
  3. A function called BubbleSort() that accepts a pointer to a integer as the array name, an integer for its size. The function should sort the array passed, in descending order. Use the function Swap() that you designed in the last Lab #4, to swap any values in the function BubbleSort().
  4. In the main() function:
  1. Declare an integer array called NumList of size SIZE (define SIZE as 20, using #define).
  2. Populate the array with pseudo-random numbers [0 -100] by calling the function FillArray().
  3. Display the Array contents by calling the function PrintArray().
  4. Sort the array NumList in descending order by calling the function BubbleSort().
  5. Display the SORTED array by calling the function PrintArray().

For your convenience, the function prototypes are given bellow:

void FillArray ( int *array, int size ); void PrintArray ( int *array, int size ); void BubbleSort ( int *array, int size ); void Swap ( int *x, int *y );

Summary of the lab requirements: You must complete Part A above by writing a program called Lab5a.c. Parts B must be completed by writing a single C language program called Lab5b.c. Remember to fully document your programs.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] COMP1410 Lab 5-More on Pointers
$25