m0_63999697 2022-03-15 13:10 采纳率: 93.5%
浏览 42
已结题

插入学生信息 为什么刚插入一个就出错

问题描述
请设计一个简单的学生成绩管理系统,要求系统实现以下功能:
学生信息包括学号、姓名、性别、语文、数学、英语。
插入学生信息:
Insert id name sex x y z 其中的参数分别为学号、姓名、性别、三门课的成绩,成绩为浮点数。
退出程序:
Quit或者Exit
输入
输入有多行,每行一条指令,指令格式如下:
Insert id name sex x y z
插入学生信息,分别为学号、姓名、性别和三门课(语文、数学、英语)的成绩。
Quit或者Exit
输出"Good bye!"后结束程序。
输出
输出有多行,对应命令的输出如下:
Insert id name sex x y z
插入后在单独的一行中输出"Insert:",然后在第二行中显示学生信息,数据之间用一个空格分开,成绩保留1位小数。
Quit或者Exit
在单独一行中输出"Good bye!"后结束程序。
输入样列
Insert 0911001 zhangsan F 87 78 65
Insert 0911003 Lisi F 77 72 55
Insert 0911002 zhaoliu F 97 90 55
Insert 0911004 Wangwu F 68 56 95
Quit
输出样例
Insert:
0911001 zhangsan F 87.0 78.0 65.0
Insert:
0911003 Lisi F 77.0 72.0 55.0
Insert:
0911002 zhaoliu F 97.0 90.0 55.0
Insert:
0911004 Wangwu F 68.0 56.0 95.0
Good bye!

#include<bits/stdc++.h>
using namespace std;
typedef struct Student{
    char id[20];
    char name[20];
    char sex[2];
    double x,y,z;
    struct Student* next;
}Student;
void inputSingle(Student *s)
{
    cin>>s->id>>s->name>>s->sex>>s->x>>s->y>>s->z;
} 
void outputSingle(Student *s)
{
    printf("%s %s %s ",s->id,s->name,s->sex);
    printf("%.1f %.1f %.1f\n",s->x,s->y,s->z);
}
Student *createList()
{
    Student *L;
    L=(Student*)malloc(sizeof(Student));
    L->next=NULL;
    return L;
}
void insert(Student *L,Student *s)
{
    Student *pre,*p;
    pre=L;
    p=L->next;
    while(p!=NULL){
        pre=p;
        p=p->next;
    }
    s->next=pre->next;
    pre->next=s;
}
void outputList(Student *L)
{
    Student *p;
    p=L->next;
    while(p!=NULL){
        outputSingle(p);
        p=p->next;
    }
}
int main()
{
    string order;
    Student *L,*s;
    L=(Student *)malloc(sizeof(Student));
    while(1){
        cin>>order;
        if(order=="Insert"){
            puts("Insert:");
            s=(Student *)malloc(sizeof(Student));
            inputSingle(s);
            insert(L,s);
            outputSingle(s);
        }
        else{
            puts("Good bye!");
            break;
        }
    }
    return 0;
}

  • 写回答

1条回答 默认 最新

  • qzjhjxj 2022-03-15 13:40
    关注

    试了下,没发现错误。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 3月23日
  • 已采纳回答 3月15日
  • 创建了问题 3月15日

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?