Write a program to exchange the values in two different ...



CSCI 515 C/C++ Programming Fall 2002

Dr. Creider

Lab 8 Assignment

Manipulating a three dimension array

Write a program to create a compile time three dimension short array that has 10 pages, 10 rows, and 10 columns. The program will enter data into the array and determine which pages contains the largest and smallest sums. The program will also find the largest 3 dimensional diagonal if the data in the array is a cube (same number of pages, rows, and columns). A three dimension compile time array has the following format: type name [page size][row size][column size].

Write a main program to read from a disk file (lab8.dat) three values which represent the number of pages, rows, and columns of data to be stored into the three dimension array.

Write a function to read the data for the array from the same disk file and store it in the compile time three dimension array created in main. Pass to the function the file pointer, the array name, the number of pages, number of rows, and number of columns that were obtained from the data file. The data in the file will be stored by rows by pages. Each new line in the file will contain one row of data and all the data for the first page will come before the data for the following pages. The values in the file will be 1 or 2 digit positive or negative integers.

Write a function to find the page of a compile time three dimension array that has the largest sum and the page of the array that has the smallest sum. Pass to the function the array name, the three sizes (pages, rows, and columns), and four other arguments that will be assigned a value in the function. Pass the last four arguments by reference so that you can assign to them the largest sum, the page number that contained the largest sum, the smallest sum, and the page number that contained the smallest sum. Use the sum of the first page as the initial largest and smallest sum.

Write a function to find the 3 dimensional diagonal of a cube that has the largest sum and the diagonal that has the smallest sum. There are four 3 dimensional diagonals in a cube. They can be found in the four corners on page zero of the three dimension array. Diagonal 1 begins at element [0][0] on page 0 and ends with element [m-1][n-1] on the last page. Diagonal 2 begins at element [0][n-1] on page 0 and ends with element [m-1][0] on the last page. Diagonal 3 begins at element [m-1][n-1] on page 0 and ends with element [0][0] on the last page. Diagonal 4 begins at element [m-1][0] on page 0 and ends with element [0][n-1] on the last page. Pass to the function the array name, the three sizes (pages, rows, and columns), and four other arguments that will be assigned a value in the function. Pass the last four arguments by reference so that you can assign the diagonal number and the sum of the diagonal with the largest sum, and the diagonal number and the sum of the diagonal with the smallest sum.

Write a function to print a compile time three dimension array to the screen and to a disk file, lab8.txt. Pass to the function the file pointer, the array name and the three sizes (pages, rows, and columns). Print the array as a series of two dimension arrays. Print the pages in order where each page is displayed as a two dimension array. As you print, print the page number for each page before you print the values on the page. Align the data in columns.

In main, read the number of pages, rows and columns from the file and then call the function to enter the data in the array. Print the values in the array by calling the function to print the three dimension array. Next call the function to find the pages with the largest and smallest sums. Print the results (to the screen and the disk file) with an appropriate description of what the data represents. If the data in the array is a cube, call a function to find the 3 dimensional diagonal with the largest sum and print the results back in main to the screen and the disk file. Continue reading arrays from the file until the file is empty.

Name the file you create LAB8. Do not use any global variables for this assignment. Assignment due October 15, 2002. Hand in a hard copy of the source code, and a floppy on which is saved the source file and executable file.

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download