weixin_45796800 2020-03-29 18:10 采纳率: 100%
浏览 1099
已采纳

C++用结构体实现学生信息管理系统

求问大家这段代码有什么错误呢?函数调用结构体数组那里一直报错,查了好多结构体的资料改了好多次也没有成功(刚接触结构体,还不熟练)555
还想求问一下这个第四小问还怎么写,麻烦帮帮忙了!

图片说明

#include
#include
#include
#include
#include
#include
#define MAXSIZE 50 //最大学生人数,实际请更改
using namespace std;

struct STUDENT
{
string name[20]; //学生的姓名
string id[10]; //学生的学号
char sex[2]; //学生的性别
double stru; //学生的数据结构成绩
double math; //学生的数学成绩
double english; //学生的英语成绩
double all; //学生的总成绩
double average; //学生的平均成绩
int rank[100]; //学生的排名
};

void InputStu(struct STUDENT stu[], int n)
{
int i = 0;
for (i = 0; i < n; i++)
{
/*string name[20];

string id[10];

char sex[2];

double chinese,math,english,all,average;

int rank;
cout << "请依次输入第" << i + 1 << "位学生的姓名、学号、性别、语文成绩、数学成绩、英语成绩、总成绩、平均成绩、排名" << endl;
cin >> name >> id >> sex >> chinese >> math >> english >> all >> average >> rank;
stu[i] = {name,id,sex,chinese,math,english,all,average,rank};*/

    cout << "请输入第" << i+1<< "位学生的姓名:";
    cin >> stu[i].name >> endl;
    cout << "请输入第" << i+1 << "位学生的学号:";
    cin >> stu[i].id >> endl;
    cout << "请输入第" << i+1 << "位学生的性别:";
    cin >> stu[i].sex >> endl;
    cout << "请输入第" << i+1 << "位学生的数据结构成绩:";
    cin >> stu[i].stru >> endl;
    cout << "请输入第" << i+1 << "位学生的数学成绩:";
    cin >> stu[i].math >> endl;
    cout << "请输入第" << i+1 << "位学生的英语成绩:";
    cin >> stu[i].english >> endl;
    cout << "请输入第" << i+1 << "位学生的总成绩:";
    cin >> stu[i].all >> endl;
    cout << "请输入第" << i+1 << "位学生的平均成绩:";
    cin >> stu[i].average >> endl;
    cout << "请输入第" << i+1 << "位学生的排名:";
    cin >> stu[i].rank >> endl;
}

}

void OutputStu(struct STUDENT stu[], int n)
{
    int i = 0;
    cout << "学生们的姓名,学号,性别,数据结构成绩,数学成绩,英语成绩,总成绩,平均成绩,排名分别是:" << endl;
    for (i = 0; i < n; i++)
    {
        cout << "第" << i + 1 << "位学生:";
        cout << setw(3) << stu[i].name << setw(3) << stu[i].id << setw(3) << stu[i].sex;
        cout << setw(3) << stu[i].stru << setw(3) << stu[i].math << setw(3) << stu[i].english;
        cout << setw(3) << stu[i].all << setw(3) << stu[i].average << setw(3) << stu[i].rank;
    }
}

void SearchStu(struct STUDENT stu[], int n)
{
    //查找英语成绩大于九十分的学生信息
    int i = 0;
    cout << "英语成绩大于九十分的学生信:" << endl;
    for (i = 0; i < n; i++)
    {
        if (stu[i].english>90)
            cout << setw(3) << stu[i].name << setw(3) << stu[i].id << setw(3) << stu[i].sex;
        cout << setw(3) << stu[i].chinese << setw(3) << stu[i].math << setw(3) << stu[i].english;
        cout << setw(3) << stu[i].all << setw(3) << stu[i].average << setw(3) << stu[i].rank;
    }
}


void AppendStu(struct STUDENT stu[], int* pn)
{

}



void UpdateStu(struct STUDENT stu[], int n)
{
    //修改学生的数学成绩
    int i, after;     //after为修改后的数学成绩
    cout << "要修改第几位学生的数学成绩?";
    cin >> i;
    cout << "请输入修改后该生的数学成绩:";
    cin >> after;
    stu[i-1].math = after;
}

int main()
{ //在main函数中调用上述声明的函数
int n; //记录学生个数

int index;
cout<<"请输入学生记录个数n=(n<"< cin >> n;
struct Student stu[MAXSIZE];
InputStu(stu, n); // 预先处理输入, 建表

while (1)     // 永真循环,重复显示菜单, 直至退出 
{
    cout << endl << "**********************学生信息管理主菜单**********************" << endl;
    cout<<"1.显示学生信息"<<endl;
    cout<<"2.查找学生信息" << endl;
    cout << "3.修改学生信息" << endl;
    cout << "4.添加学生信息"<<endl;
    cout << "5.退出" << endl << endl;
    cout<<"请选择(1~5): " << endl;
    cin >> index;
    cout<<endl<<"**************************************************************"<<endl;
    switch (index)
    {
    case 1:    OutputStu(stu, n); break;
    case 2:    SearchStu(stu, n); break;
    case 3:    UpdateStu(stu, n); break;
    case 4:    AppendStu(stu, &n); break;
    case 5:    UpdateStu(stu, n); break;
    default:   cout<<"输入有误,请重新输入! ";
    }
}

}



  • 写回答

1条回答 默认 最新

  • dabocaiqq 2020-03-29 21:04
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已采纳回答 5月17日

悬赏问题

  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败