Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ bubblesort不传递数据或不起作用_C++_Arrays_Sorting_Bubble Sort_Median - Fatal编程技术网

C++ bubblesort不传递数据或不起作用

C++ bubblesort不传递数据或不起作用,c++,arrays,sorting,bubble-sort,median,C++,Arrays,Sorting,Bubble Sort,Median,我正在为一项作业编写一个程序,其中程序将分数存储在数组中,有一个函数输入分数并存储在数组中并返回分数,处理多达20个分数,有一个函数对分数数组进行排序,还有一个单独的函数取排序后的数组并返回中值。我已经编写了代码,但它没有对数组进行排序。不知道我做错了什么。任何帮助都将不胜感激 #include <iostream> using namespace std; int main(); void bubbleSort(double[], int); //Function proto

我正在为一项作业编写一个程序,其中程序将分数存储在数组中,有一个函数输入分数并存储在数组中并返回分数,处理多达20个分数,有一个函数对分数数组进行排序,还有一个单独的函数取排序后的数组并返回中值。我已经编写了代码,但它没有对数组进行排序。不知道我做错了什么。任何帮助都将不胜感激

#include <iostream>

using namespace std;

int main();

void bubbleSort(double[], int); //Function prototypes
void swap(double &, double &);
void findMedian(double[], int, int, int, int, int);



int main()
{
    int numgrades;          // the number of grades in the array
    double grades[20];      // array of grades
    int first = 0,
        last,
        middle;
    double medianeven;      // median if # of elements are even
    double medianodd;       // median if # of elements are odd
    bool isEven(int);       // determines if the #of elements is even

    cout << "Please enter the number of grades. ";
    cin >> numgrades;

    for (int index = 0; index <= numgrades - 1; index++)
    {
        cout << "Enter test score "
            << (index + 1) << ":";
        cin >> grades[index];
    }

    void bubbleSort(double grades[], int numgrades);


    for (int index = 0; index <= numgrades - 1; index++)
    {
        cout << grades[index];
    }

    (((last) = (numgrades - 1)));
    (((middle) = (first + last) / 2));

    if (isEven(numgrades))
    {
        (medianeven = ((grades[middle] + grades[middle + 1]) / 2));
        cout << "The median grade is +" << medianeven << "." << endl;
    }

    else
    {
        ((medianodd = grades[middle]));
        cout << "The median grade is -" << (medianodd) << "." << endl;
    }

    return 0;
}


void bubbleSort(double array[], int numgrades)
{
    int minIndex;
    double minValue;

    for (int start = 0; start < (numgrades - 1); start++)
    {
        minIndex = start;
        minValue = array[start];
        for (int index = start + 1; index < numgrades; index++)
        {
            if (array[index] < minValue)
            {
                minValue = array[index],
                    minIndex = index;
            }
        }
        swap(array[minIndex], array[start]);
    }

}

void swap(double &a, double &b)
{
    double temp = a;
    a = b;
    b = temp;
}

bool isEven(int number)
{
    bool status;

    if (number % 2 == 0)
        status = true;
    else
        status = false;

    return status;
}
#包括
使用名称空间std;
int main();
void bubbleSort(双精度[],整数)//功能原型
无效掉期(双倍&,双倍&);
void findMedian(double[],int,int,int,int,int);
int main()
{
int numgrades;//数组中的等级数
双等级[20];//等级数组
int first=0,
最后,,
中间的
double medianeven;//元素的#为偶数时的中值
double medianoded;//如果元素的#为奇数,则为中值
bool isEven(int);//确定元素的#是否为偶数
cout>numgrades;
对于(int index=0;indexIn
main

void bubbleSort(double grades[], int numgrades);
bubbleSort
函数的前向声明,而不是对它的调用

bubbleSort(grades, numgrades);
将调用函数。

main

void bubbleSort(double grades[], int numgrades);
bubbleSort
函数的前向声明,而不是对它的调用

bubbleSort(grades, numgrades);

将调用函数。

当前的输入和输出是什么(int index=0;index
((last)=(numgrades-1));
括号没有任何作用。您从未调用过
bubbleSort
函数。当前的输入和输出是什么(int index=0;index
((last)=(numgrades-1));
括号没有任何作用。您从未调用过
bubbleSort
函数。