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日

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据