c语言实验预习报告

上传人:共*** 文档编号:61635075 上传时间:2018-12-07 格式:DOCX 页数:6 大小:18.74KB
返回 下载 相关 举报
c语言实验预习报告_第1页
第1页 / 共6页
c语言实验预习报告_第2页
第2页 / 共6页
c语言实验预习报告_第3页
第3页 / 共6页
c语言实验预习报告_第4页
第4页 / 共6页
c语言实验预习报告_第5页
第5页 / 共6页
点击查看更多>>
资源描述

《c语言实验预习报告》由会员分享,可在线阅读,更多相关《c语言实验预习报告(6页珍藏版)》请在金锄头文库上搜索。

1、信息工程学院实 验 报 告课程名称:        程序设计基础           实验名称:实验类型:验证性综合性设计性实验室名称:      信息工程学院机房      班级:    学号:姓名:  报告类型:实验报告  预习报告预习报告成绩:         指导教师审核(签名):           &nbs

2、p;               年    月    日一、实验目的1.掌握结构体的用法;2.掌握数组的用法;3.掌握指针的用法;4.理解链表的概念,初步学会对链表进行操作。二、实验设备和环境具备i7cpu,win10系统的计算机,使用Dev-C+运行软件。三、实验内容设计一种结构体,用来保存学生信息(包括学号、姓名、三科成绩、平均成绩)。除平均成绩外,各项数据均由键盘输入。现在要求输入若干学生的信息,并实现以下功能:(可以使用数组或链表实现)1)计算学生的平均成绩,并填入相应的数据域

3、;2)插入学生;3)删除学生;4)查询学生。四、程序代码#include#include#includestruct studentint studentId;char name20;char sex5;int score;struct student *next;struct student *ListCreate(int n)    struct student *head=NULL,*curpt,*prept;    int i;    for(i=1;i<=n;i+) curpt="(struct"

4、student="" struct="" curpt-="">studentId);        printf("请输入学生姓名:n");        scanf("%s",curpt->name);getchar();        printf("请输入学生性别:n");        scanf(

5、"%s",curpt->sex);getchar();        printf("请输入学生成绩:n");        scanf("%d",&curpt->score);        curpt->next=NULL;        if(i=1)          head=curpt; &

6、nbsp;      else          prept->next=curpt;        prept=curpt;        return head;struct student *ListInsert(struct student *head,struct student *p)    struct student *curpt,*prept;    if(head=NUL

7、L)            head=p;        p->next=NULL;        else            curpt=head;        while(curpt!=NULL&&curpt->studentId<=p->studentId)       &nb

8、sp;            prept=curpt;            curpt=curpt->next;                if(curpt!=NULL)                    if(curpt=head)       &nb

9、sp;                    p->next=head;                head=p;                        else                 &nb

10、sp;          prept->next=p;                p->next=curpt;                            else                    

11、prept->next=p;            p->next=NULL;                return head;struct student *ListDelete(struct student *head,int id)    struct student *curpt,*prept;    if(head=NULL)         &nb

12、sp;  printf("原表为空!n");        return NULL;        else            curpt=head;        while(curpt!=NULL&&curpt->studentId!=id)                 &n

13、bsp;  prept=curpt;            curpt=curpt->next;                if(curpt!=NULL)                    if(curpt=head)                 &n

14、bsp;          head=curpt->next;                free(curpt);                        else                        

15、   prept->next=curpt->next;                free(curpt);                        printf("学号为%d的学生已被成功删除n",id);                else  

16、;        printf("学号为%d的学生不存在n",id);         return head;    void ListPrint(struct student *head)    struct student *p=head;    while(p!=NULL)            printf("学号:%d姓名:%s性别:%s分数 %dn&qu

17、ot;,p->studentId,p->name,p->sex,p->score);        p=p->next;    void ListFind(struct student *head,int id)    struct student *p=head;    while(p!=NULL)            if(p->studentId)=id)     &nbs

18、p;      printf("学号:%d姓名:%s性别:%s分数 %dn",p->studentId,p->name,p->sex,p->score);break;        p=p->next;    main()    struct student *head,*p;    int n,v,k,m;    printf("请输入学生人数:n");   &nb

19、sp;scanf("%d",&n);    head=ListCreate(n);    printf("原链表为:n");    ListPrint(head);    printf("请输入要查找的学号:n");    scanf("%d",&v);    ListFind(head,v);    p=(struct student *)malloc(siz

20、eof(struct student);    printf("请输入要插入学生的信息:n");    scanf("%d%s%s%d",&p->studentId,p->name,p->sex,&p->score);    head=ListInsert(head,p);    printf("输出插入节点之后的链表:n");    ListPrint(head);    p

21、=(struct student *)malloc(sizeof(struct student);    printf("请输入要插入学生的信息:n");    scanf("%d%s%s%d",&p->studentId,p->name,p->sex,&p->score);    head=ListInsert(head,p);    printf("输出插入节点之后的链表:n");    Li

22、stPrint(head);    printf("请输入要删除的学生的学号:n");    scanf("%d",&k);    head=ListDelete(head,k);    printf("输出删除节点后的链表:n");    ListPrint(head);    printf("请输入要删除的学生的学号:n");    scanf("%d&q

23、uot;,&k);    head=ListDelete(head,k);    printf("输出删除节点后的链表:n");    ListPrint(head);    printf("请输入要查找的学号:n");    scanf("%d",&m);    ListFind(head,m);   测试数据   结果分析   存在的问题及解决方法     1.过程中存在较多的符号错误,运行时检测出。调整符号重新开始。2.空格不当,导致输出结果连在一起,不能很好的分辨。重新调整空格输出,效果明显好转。3程序过长,输入时容易输入错。且输入时间过长。   实验体会与总结(思考)  1输入较慢,程序不合理。  2有较多错误,以后注意。3尽量时源程序代码精简,有利于提高程序效率。减少输入时间和检查错误所用的时间。有利于工作效率的提高。

展开阅读全文
相关资源
相关搜索

当前位置:首页 > IT计算机/网络 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号