Sunteți pe pagina 1din 4

1

Name ____________________________

Fall 2015 ET-575 Extra Credit III

Code a function library for a partially filled integer array.

Use the following code as the base for your program:

#include <iostream>;
using namespace std;

int main( ) {
const int CAPACITY = 20;
int numbers[CAPACITY];
int numElements = 0;

return 0;
}

For all functions keep in mind the following:


* CAPACITY should never be exceeded.
* numElements must be updated every time elements are added/removed
* Functions must match specifications for return type and behavior.
* Use appropriate indenting and format of code.

Introduction to C++ Programming Design and Implementation S. Trowbridge 2015


2

1) Program should display the following console input menu which loops:

Array Manipulation
------------------
1. Get Index
2. Append
3. Insert
4. Remove
5. Remove First
6. Remove Last
7. Output
8. Exit program

Select:

2) Program will implement a partially filled array of capacity 20.


3) Array will be initially populated via function calls with the following
array values: 10,20,30,40,50,60,70,80,90,100
4) Program will implement all functions as specified on page 3.
5) Program will be tested with input specified on page 4.

Introduction to C++ Programming Design and Implementation S. Trowbridge 2015


3

Code the following primary functions:

1) output
a) read only parameters
b) outputs the array as a horizontal row of elements with spaces.
c) outputs the size of the array on the same line.
Example: Array: 10 20 30 40 50 Size: 5
2) append
a) add the specified element to the end of the array.
b) isFull should be used as a helper function
3) insertAt
a) insert element at specified position
b) isFull should be used as a helper function
4) removeFirst
a) remove the first element in the array.
b) return the first element in the array.
5) removeLast
a) remove the last element in the array.
b) return the last element in the array.
6) removeElement
a) remove specified element from the array.
b) return the removed element.
c) getIndex should be used as a helper function.

Code the following helper functions:

1) isFull
a) returns true if numElements == CAPACITY
2) getIndex
a) returns index of element if element exists, -1 otherwise
b) make use of containsElement helper function
3) containsElement
a) returns true if element exists in the array, false otherwise

For additional extra credit:

1. Replace insertAt function with:


sortedInsert
a) given a value, automatically determine where to place the element
in size order (preserve smallest to largest order)
b) isFull should be used as a helper function.

2. Redo the append function so that it will only append a value if it is


larger then all other elements in the array.

Introduction to C++ Programming Design and Implementation S. Trowbridge 2015


4

Test the program with the following user input:

1) Remove First
2) Remove Last
3) Get Index 55
3) Insert 55
4) Remove 70
5) Append 110
6) Output
7) End Program

Introduction to C++ Programming Design and Implementation S. Trowbridge 2015

S-ar putea să vă placă și