这个简单的学生信息系统调试时怎么不能进行查询成绩!!求大佬教教我!!!谢谢

这个简单的学生信息系统调试时怎么不能进行查询成绩!!求大佬教教我!!!谢谢

代码如下:


#include<iostream>
#include<iomanip>
#include<cstring>
using namespace std;
struct student
{
    char name[20];//姓名
    double sum;//总分和平均分
    double MT, EN, PH;//各科成绩
    long num;//学号
};
int readscore(student stu[])
{
    int count=0;//人数
    cout.setf(ios::right);
    cout << "名字" << setw(5);
    cout << "学号" << setw(5);
    cout << "数学" << setw(5);
    cout << "英语" << setw(5);
    cout << "物理" << setw(5);
    cout << endl;
    for (int i = 0; i < 30; i++)
    {
        cin >> stu[i].name >> stu[i].num >> stu[i].MT >> stu[i].EN >> stu[i].PH;
        if (stu[i].MT <= 0)
            break;
        count++;
    }return count;
}
int getsum(student stu[],int n)
{
    double Sum = 0;
    for (int i = 0; i < n; i++)
    {
        stu[i].sum = 0;
        stu[i].sum = stu[i].MT + stu[i].EN + stu[i].PH;
        Sum = stu[i].sum;

    }return Sum;
}
void mppx(student stu[], int n)
{
    for (int m = n-1; m >0; m--)
    {
        int max = 0;

        char name[20];//姓名

        long num = 0;//学号

        double mt = 0;//数学

        double en = 0;//英语

        double ph = 0;//物理

        for (int i = 0; i < m; i++)//排序
        {
            if (stu[i].sum <stu[i + 1].sum)
            {
                strcpy_s(name, stu[i].name);

                strcpy_s(stu[i].name, stu[i + 1].name);

                strcpy_s(stu[i + 1].name, name);

                num = stu[i].num;

                stu[i].num = stu[i + 1].num;

                stu[i + 1].num = num;

                mt = stu[i].MT;

                stu[i].MT = stu[i + 1].MT;

                stu[i + 1].MT = mt;
                en = stu[i].EN;
                stu[i].EN = stu[i + 1].EN;

                stu[i + 1].EN = en;

                ph = stu[i].PH;

                stu[i].PH = stu[i + 1].PH;

                stu[i + 1].PH = ph;

                max = stu[i].sum;

                stu[i].sum = stu[i + 1].sum;

                stu[i + 1].sum = max;
            }
        }
    }
    cout.setf(ios::left);

    cout << "总成绩表:" << endl;

    cout << "排名" << setw(5);

    cout << "姓名" << setw(5);

    cout << "学号" << setw(5);

    cout << "总分" << setw(5);

    cout << "高数" << setw(5);

    cout << "英语" << setw(5);

    cout << "物理" << setw(5);

    cout << "平均分" << endl;
    for (int j = 0; j < n; j++)
    {
        cout.setf(ios::left);
        cout << j + 1 << setw(5);
        cout << stu[j].name << setw(5);
        cout << stu[j].num << setw(5);
        cout << stu[j].sum << setw(5);
        cout << stu[j].MT << setw(5);
        cout << stu[j].EN << setw(5);
        cout << stu[j].PH << setw(5);
        cout << stu[j].sum / 3 << endl;
    }
}
int find(student stu[], int n)//查询成绩

{

    int a = 0, b = 0;

    long num;

    cin >> num;

    for (int j = 0; j < n; j++)

    {

        if (num == stu[j].num)

        {
            b++;
            a++;
        }

    }

    if (b != 0)

    {

        cout.setf(ios::left);

        cout << "排名" << setw(5);

        cout << "姓名" << setw(5);

        cout << "学号" << setw(5);

        cout << "总分" << setw(5);

        cout << "高数" << setw(5);

        cout << "英语" << setw(5);

        cout << "物理" << setw(5);

        cout << "平均分" << endl;

    }

    for (int i = 0; i < n; i++)

    {

        if (num == stu[i].num)

        {

            cout.setf(ios::left);

            cout << i + 1 << setw(5);

            cout << stu[i].name << setw(5);

            cout << stu[i].num << setw(5);

            cout << stu[i].sum << setw(5);

            cout << stu[i].MT << setw(5);

            cout << stu[i].EN << setw(5);

            cout << stu[i].PH << setw(5);

            cout << stu[i].sum / 3 << endl;

        }

    }

    if (a == 0)

    {

        cout << "查无此人!请重新输入:";

        return -1;

    }
}

int main()
{
    student stu[30];
    double a;
    a = readscore(stu);
    cout << "===============================================" << endl; getsum(stu, a);
    for (int i = 0; i < a; i++)

    {

        cout.setf(ios::left);

        cout << "姓名" << stu[i].name << setw(5);

        cout << "数学" << stu[i].MT << setw(5);

        cout << "英语" << stu[i].EN << setw(5);

        cout << "物理" << stu[i].PH << endl;

    }

    cout << "总人数:" << a << endl;

    cout << "***********************************************" << endl; mppx(stu, a);

    cout << "***********************************************" << endl;
    cout << "请输入要查找的学号:"<<endl;
    find(stu, a);
    cout << endl;
    return 0;

}
c++

1个回答

cout << "请输入要查找的学号:"<<endl;
这句话之后的代码,我都没看到你有让用户输入要查找学号的逻辑。能查找就见鬼了。
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问