assignment 4.cpp - \/Created by Abhilash Bajracharya\/Razo 1337.002#include <iostream>#include <cstdlib> using namespace std int createArray(int&size cfw

assignment 4.cpp - /Created by Abhilash Bajracharya/Razo...

This preview shows page 1 - 2 out of 2 pages.

//Created by Abhilash Bajracharya //Razo 1337.002 #include <iostream> #include <cstdlib> using namespace std; int* createArray(int &size) { int *arrPTR; arrPTR = new int [size]; for (int i = 0; i < size; i++) { arrPTR[i] = rand()%100; } return arrPTR; } void findStats(int *arr, int size, int &min, int &max, double &average) { min = 100; max = 0; for (int i = 0; i < size; i++) { if (arr[i] < min) min = arr[i]; } for (int i = 0; i < size; i++) { if (arr[i] > max) max = arr[i]; } double sum = 0; for (int i = 0; i < size; i++) { sum += arr[i]; } average = sum / size; } int * searchElement(int *arr, int size, int *element) { for (int i = 0; i <size; i++) { if (*element == arr[i]) { return &arr[i]; } } return NULL; } int main() { char input; while (1) { cout << "Please choose one of the following options" << endl << "A : Create and initialize a dynamic array" << endl << "B : Display statistics on the array" << endl << "C : Search for an element" << endl << "D : Quit" << endl; cin >> input; int size;
Image of page 1
int *arr; if (input == 'A') { cout << "Please enter the size of the array you want to create: ";
Image of page 2

You've reached the end of your free preview.

Want to read both pages?

  • Spring '14
  • Max, Carriage return, endl, size, int *arr

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture