Assignment 4
Complete the following the Assignment. The deadline is
Tuesday, 3/12, 11:59pm
Use the ecampus dropbox.
For programs you submit, include your name and program description in a comment block.
1. Write simple C++ statements (not full C++ programs) to accomplish each of the following:
a) Display the value of the seventh element of character array f. b) Input a value into element 4 of single-subscripted double array b. c) Initialize each of the 5 elements of single-subscripted integer array g to 8. d) Total and print the elements of double array c which has 100 elements. e) Copy array a into the first portion of array b. double a[ 11 ], b[ 34 ]; Submit the answers in the plain text file, problems1-2.txt.
2. Write statements that perform the following single-subscripted array operations:
a) Initialize the 10 elements of the integer array counts to zero. b) Add 1 to each of the 15 elements of the integer array bonus (use a for loop). c) Read 12 values for the double array monthlyTemperatures from the keyboard (use a for loop). d) Print the 5 values of the integer array bestScores, one value per line (use a for loop). Submit the answers in the plain text file, problems1-2.txt.
3. Read the cplusplus.com tutorial section on Arrays as parameters (http://cplusplus.com/doc/tutorial/arrays/). Additionally, read http://tinyurl.com/cztfq2y. Make the following changes to the C++ array example 2 at http://tinyurl.com/cuwmo87:
Use a function called showArrayHistogram to display a histogram, given an int array n and the length of the array n. The showArrayHistogram function should take the following parameters: - an int array - the int length of the int array In the program, include a function prototype for the showArrayHistogram function. Submit the program as histogramFunction.cpp.
4. Do an internet search for a C++ program that uses a bubblesort function to sort an array of integers. Insert a comment block to explain how the bubblesort function works and why it is an inefficient algorithm. Add code to use the bubblesort function to sort the following int array:
int n[10] = { 19, 3, 15, 7, 11, 9, 13, 5, 17, 1 }; Display the contents of array n after it is sorted. Submit the program as bubbleSortFunction.cpp.