Project #60828 - C++

  1. All variables must be declared BEFORE ANY CODE.
  2. No variables declared in loops like for(int x;   The int x must be at the top of your code.  See rule 1.
  3. No use of break or continue in loops.
  4. All variable must have meaningful names. For rows and columns must be r and c or row and col or row and column.  Not i, j, a, b or anything not meaning full.
  5. Code must be properly indented and formatted.
  6. Use .c file NOT .cpp
  7. Visual Studio 

 

Functions

 

Objectives:

·        First assignment using C functions

·        Practice using modules to “divide and conquer”

·        Passing arrays to functions

Description:

Write a C program with functions that do the following:

void fillArray( … ) // fills an array with random integers

void printArray( .. ) // prints an array to stdout using printf

void arrayStats( two arguments, two arrays)

void printStats( one argument )

int searchArray(int key, array…)

void doSearches(array, # of times to perform searches)

int main( .. )

declares arrays, calls fill, print, stats, print Stats and do searches

Details:

The size of the array will be defined at top of program and used in all the code.  See main() below

#include <stdio.h>

#define SIZE 1000

void fillArray(int a[SIZE] ) // fills an array with random integers

receives an array that can hold SIZE integers and fills it with random numbers

 

void printArray( .. ) // prints an array to stdout using printf

prints the array 8 numbers per line with spacing

 

void arrayStats( two arguments, two arrays)

first argument the array

second argument stats array where 0 is min (smallest), 1 is max (largest) and 2 is sum of numbers in array

Must initialize variables as described in class

 

void printStats( one argument )

receives the statistics array and prints the results with labels one per line

calculates and prints average also

 

int searchArray(int key, array…)

receives an integer in the key and the array of integers

returns the index of where the key is in the array

or -1 if not found

a loop that starts at index 0 and compares each element to the key, stops when found and returns index or if no where else to look returns -1.  Remember no break or continue statements in loop, you must use a proper Boolean expression to control the loop.

 

void doSearches(array, # of times to perform searches)

receives the array and an integer which is number of searches to perform

loops # of times

Generates random integer key

calls searchArray

prints key and position found or not found

int main( .. )

    int array[SIZE];

    int stats[3]; // min, max, sum

// calls fill array

// print Array

// array stats

// print stats

// do Searches

Subject Computer
Due By (Pacific Time) 03/05/2015 07:00 am
Report DMCA
TutorRating
pallavi

Chat Now!

out of 1971 reviews
More..
amosmm

Chat Now!

out of 766 reviews
More..
PhyzKyd

Chat Now!

out of 1164 reviews
More..
rajdeep77

Chat Now!

out of 721 reviews
More..
sctys

Chat Now!

out of 1600 reviews
More..
sharadgreen

Chat Now!

out of 770 reviews
More..
topnotcher

Chat Now!

out of 766 reviews
More..
XXXIAO

Chat Now!

out of 680 reviews
More..
All Rights Reserved. Copyright by AceMyHW.com - Copyright Policy