Lab7

Home Up

 

 Lab1 ] Lab2 ] Lab3 ] lab4 ] lab5 ] lab6 ] [ Lab7 ] Lab8 ] Lab9 ] Lab10 ]

CP107  LAB 7

 

 

LAB OBJECTIVES:

Use of array data structure
Use of Random number generator
Learn how to populate an array and print it's contents
Sorting an array using the BubbleSort Algorithm
Using linear search method to search for an item in the array
Using Binary search method to search for an item in the array
Use of pointers
Passing pointers as an argument to a function to pass information by reference

 

LAB ASSIGNMENT

write a program the does the following

Declare two constants, SIZE = 10, and MAXRANGE 1000
Create an array of size SIZE. Fill the array with random numbers. Range of numbers are 0 to MAXRANGE. Print content of the array.

Write a function BubbleSort that will sort the array using Bubble Sort algorithm. The function BubbleSort calls a function swap every time it needs to swap two numbers. Print content of the sorted array.

Write a function FindMax that will go through an entire array and print the largest number in the array.

Use the maximum value found before as an argument for a binarySearch function to see if the number is
in the array and how many passes it took for binary search to find that number.

The following functions are REQUIRED to the lab. You do not have to write a recursive version of FindMax.
int GetRandomNumber(const int MaxRange);
int FindMax( const int array[], int nHighestIndex, const int MaxRange);
void BubbleSort( int array[], int arraySize );
int binarySearch( const int b[], int searchKey, int nLow, int nHigh, int &nPassCount );
void swap(int *p, int *q); 

 

 

Copyright (c) Yusuf Family Website 2001