-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