《C语言程序设计》形成性考核作业(4)解答(共7页)

上传人:壹****1 文档编号:493649070 上传时间:2023-02-19 格式:DOC 页数:7 大小:28.50KB
返回 下载 相关 举报
《C语言程序设计》形成性考核作业(4)解答(共7页)_第1页
第1页 / 共7页
《C语言程序设计》形成性考核作业(4)解答(共7页)_第2页
第2页 / 共7页
《C语言程序设计》形成性考核作业(4)解答(共7页)_第3页
第3页 / 共7页
《C语言程序设计》形成性考核作业(4)解答(共7页)_第4页
第4页 / 共7页
《C语言程序设计》形成性考核作业(4)解答(共7页)_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《《C语言程序设计》形成性考核作业(4)解答(共7页)》由会员分享,可在线阅读,更多相关《《C语言程序设计》形成性考核作业(4)解答(共7页)(7页珍藏版)》请在金锄头文库上搜索。

1、精选优质文档-倾情为你奉上C语言程序设计作业4解答一、选择题1. 假定有“struct BOOK char title40; float price; struct BOOK * book;”,则不正确的语句为 ( A )。A. struct BOOK * x=malloc(book);B. struct BOOK x=C+ Programming,27.0;C. struct BOOK * x=malloc(sizeof(struct BOOK);D. struct BOOK *x=&book;2. 假定有“struct BOOK char title40; float price;book

2、;”,则正确的语句为 ( B )。A. struct BOOK x=&book;B. struct BOOK * x=&book;C. struct BOOK x=calloc(BOOK);D. struct BOOK *x=BOOK;3. 表示文件结束符的符号常量为( C )。A. eofB. EofC. EOFD. feof4. C语言中的系统函数fopen( )是( D )一个数据文件的函数。A. 读取B. 写入C. 关闭D. 打开5. 从一个数据文件中读入以换行符结束的一行字符串的函数为( B )。A. gets( )B. fgets( )C. getc( )D. fgetc( )6.

3、 向一个二进制文件中写入信息的函数fwrite( )带有( D )个参数。A. 1B. 2C. 3D. 4二、填空题1. 假定一个结构类型的定义为“struct A int a, b; struct A * c;”,则该类型的大小为 12 字节。2. 假定一个结构类型的定义为“struct B int a5; char * b;”,则该类型的大小为 24 字节。3. 假定一个结构类型的定义为“struct D int a; union int b; double c; struct D * d2;”,则该类型的大小为 20 字节。4. 假定要动态分配一个类型为struct Worker的具有n

4、 个元素的数组,并由r指向这个动态数组,则使用的语句表达式为struct Worker * r= calloc(n, sizeof(struct Worker); 。5. 假定要访问一个结构x中的由a指针成员所指向的对象,则表示方法为 *(x.a) 。6. 假定要访问一个结构指针p所指对象中的b指针成员所指的对象,则表示方法为 *(p-b) 。7. 与结构成员访问表达式(*fp).score等价的表达式是 fp-score 。三、写出下列每个程序运行后的输出结果1.#include struct Worker char name15;/ 姓名int age;/ 年龄float pay;/ 工资

5、;void main( )struct Worker x=wanghua, 52, 2350;struct Worker y, * p;y=x; p=&x;printf(%s %d %6.2fn,y.name, y.age, y.pay);printf(%s %d %6.2fn,p-name, p-age, p-pay);d资程序的运行结果是: wanghua 52 2350.00wanghua 52 2350.002.#include #include struct Worker char name15;/ 姓名int age;/ 年龄float pay;/ 工资;void main( )

6、struct Worker x;char *t=liouting;int d=38; float f=493;strcpy(x.name, t);x.age=d; x.pay=f;x.age+; x.pay*=2;printf(%s %d %6.2fn,x.name, x.age, x.pay);程序的运行结果是: liouting 39 986.003.#include struct Worker char name15;/ 姓名int age;/ 年龄float pay;/ 工资;int Less(struct Worker r1, struct Worker r2) if(r1.ager

7、2.age) return 1;else return 0;void main( ) struct Worker a4=abc,25,420,def,58,638,ghi,49,560,jkl,36,375;struct Worker x=a0;int i;for(i=1; i4; i+) if(Less(x,ai) x=ai;printf(%s %d %6.2fn,x.name, x.age, x.pay);程序的运行结果是:def 58 638.00四、写出下列每个函数的功能1.void QA(struct Worker a , int n) int i;for(i=1; iname);p

8、=f;while(-n) p=p-next=malloc(sizeof(struct StrNode);scanf(%s, p-name);p-name=NULL;return f;假定结构类型struct StrNode的定义如下:struct StrNode char name15;/ 字符串域struct StrNode * Next;/ 指针域;函数功能是: 将键盘输入的n个长度小于15的字符存储在一个链表中,先输入的字符串存储在链表的表头,最后输入的字符串存储在链表的表尾,函数返回链表的表头指针。3.struct IntNode * FindMax(struct IntNdoe *

9、f) struct IntNode * p=f;if(!f) return NULL;f=f-next;while(f) if(f-datadata) p=f;f=f-next;return p;假定struct IntNode的类型定义为:struct IntNode int data;/ 结点值域struct IntNode * next;/ 结点指针域;函数的功能是: 查找由头指针f所指链表中各结点值域的最小值,函数返回值域值最小的结点指针。4.int Count(struct IntNode * f) int c=0;while(f) c+;f=f-next;return c;假定st

10、ruct IntNode的类型定义为:struct IntNode int data;/ 结点值域struct IntNode * next;/ 结点指针域;函数的功能是: 统计并返回由头指针f所指链表的结点数。5.struct IntNode * Input( int n) struct IntNode * f, * p;f=malloc(sizeof(struct IntNode);if(n=0) return NULL;f-next=NULL;printf(从键盘输入 %d 个整数: , n);while(n-) scanf(%d, &(f-data);p=f;f=malloc(sizeof(struct IntNode);f-next=p;return f-next;假定struct IntNode的类型定义为:struct IntNode int data;/ 结点值域struct IntNode * next;/ 结点指针域;函数功能是: 将键盘输入的n个整数存储在一个链表中,先输入的数据存储在链表的表尾,最后输入的数据存储在链表的表头,函数返回链表的表头指针。6.#include #include #inclu

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

当前位置:首页 > 办公文档 > 教学/培训

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