-2
所以我的程序的重點是從文本文件中讀取數字並將其放入數組中。然後我必須使用插入排序對數組進行排序並找到中值。我也必須計算平均值,並顯示平均值和中位數。我使用的語言是C++。這是我的設計:混淆關於傳遞變量到函數
Pseudocode for main:
CAll the fileReadArray(intArray, MAX_ELEMS) function and assign return value to numElems
If the numElems <=0, then print an error message and return
Call the doCalculations(average, median, intArray, numElems) function
Call the printOutput(average, median) function
END main
fileReadArray
Return Value: numElems (int)
Reference parameters: intArray (array of ints)
Receives: maxElems (int)
Preconditions: maxElems indicates the physical size of intArray (already declared)
Logic: Open the input file (up to you if you want to read the filename). If the file doesn't open, return -1. If it opens, read one number at a time and store in the intArray until the index of the array reaches maxElems or the end of file. Close the file and return the index after the last one read.
doCalculations
Return Value: (none)
Reference parameters: average (double), median (int)
Receives: intArray (array of ints), numElems (int)
Preconditions: intArray has been populated, numElems indicates how many elements are used in intArray
Logic: Calculate the mean average. Calculate the median.
calcAverage
Return Value: average (double)
Reference parameters: (none)
Receives: intArray (array of ints), numElems (int)
Preconditions: intArray has been populated, numElems indicates how many elements are used in intArray
Logic: Calculate the mean average by finding the sum of the elements, then dividing by numElems
calcMedian
Return Value: median (int)
Reference parameters: (none)
Receives: intArray (array of ints), numElems (int)
Preconditions: intArray has been populated, numElems indicates how many , elements are used in intArray
Logic: Sort the array, return the middle element or the average (ruonded) of the 2 middle elements
insertionSortArray
Return Value: (none)
Reference parameters: data (array of ints)
Receives: data (array of ints), numElems (int)
Preconditions: data has been populated, numElems indicates how many elements are used in data array
Logic: Sort the array using the insertion sort.
printOutput
Return Value: (none)
Reference parameters: (none)
Receives: average (double), median (int)
Preconditions: average and median have been calculated
Logic: Print the average and median with labels
我混淆了哪些變量傳遞給我的函數。我使用的語言是C++
請指定語言。 –
非常抱歉。我正在使用的語言是C++ –
你可以讓這個問題變小嗎? – ergonaut