2019第十二周做业编程
这个做业属于哪一个课程 | C语言程序设计ll |
这个做业要求在哪里 | (https://edu.cnblogs.com/campus/zswxy/software-engineering-class2-2018/homework/3234) |
我在这个课程的目标是 | 可以掌握二级指针的概念,以及指针数组的应用;了解指针与函数的关系,掌握指针做为函数返回值;掌握单向链表的概念和操做 |
这个做业在哪一个具体方面帮助我实现目标 | 了解了指针函数和函数指针的区别 |
参考文献 | (https://blog.csdn.net/u012741741/article/details/66478883) |
本题要求实现一个函数,用于计算有n个元素的指针数组s中最长的字符串的长度。数组
int max_len( char *s[], int n );
其中n个字符串存储在s[]中,函数max_len应返回其中最长字符串的长度。函数
#include <stdio.h> #include <string.h> #include <stdlib.h> #define MAXN 10 #define MAXS 20 int max_len( char *s[], int n ); int main() { int i, n; char *string[MAXN] = {NULL}; scanf("%d", &n); for(i = 0; i < n; i++) { string[i] = (char *)malloc(sizeof(char)*MAXS); scanf("%s", string[i]); } printf("%d\n", max_len(string, n)); return 0; } /* 你的代码将被嵌在这里 */
4 blue yellow red green
6
#include <stdio.h> #include <string.h> #include <stdlib.h> #define MAXN 10 #define MAXS 20 int max_len( char *s[], int n ); int main() { int i, n; char *string[MAXN] = {NULL}; scanf("%d", &n); for(i = 0; i < n; i++) { string[i] = (char *)malloc(sizeof(char)*MAXS); scanf("%s", string[i]); } printf("%d\n", max_len(string, n)); return 0; } int max_len(char *s[],int n) { int i,max=0; for(i=0;i<n;i++) { int len = strlen(s[i]); if(len>max) { max=len; } } return max; }
本题在调试过程当中没有遇到任何问题
本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义以下:学习
struct ListNode { char code[8]; struct ListNode *next; };
这里学生的学号共7位数字,其中第二、3位是专业编号。计算机专业的编号为02。测试
int countcs( struct ListNode *head );
其中head是用户传入的学生学号链表的头指针;函数countcs统计并返回head链表中专业为计算机的学生人数。this
#include <stdio.h> #include <stdlib.h> #include <string.h> struct ListNode { char code[8]; struct ListNode *next; }; struct ListNode *createlist(); /*裁判实现,细节不表*/ int countcs( struct ListNode *head ); int main() { struct ListNode *head; head = createlist(); printf("%d\n", countcs(head)); return 0; } /* 你的代码将被嵌在这里 */
1021202 2022310 8102134 1030912 3110203 4021205 #
3
#include <stdio.h> #include <stdlib.h> #include <string.h> struct ListNode { char code[8]; struct ListNode *next; }; struct ListNode *createlist(); /*裁判实现,细节不表*/ int countcs( struct ListNode *head ); int main() { struct ListNode *head; head = createlist(); printf("%d\n", countcs(head)); return 0; } int countcs(struct ListNode *head) { int sum=0; while(head) //用计数器记录字符串第二三个是否为02就能够了 { if(head -> code[1] == '0' && head -> code[2] == '2') //指向运算符-> { sum++; } head = head -> next; } return sum; }
问题:·一开始while语句的条件不会写,致使编译错误.net
解决方法:·问了个人搭档,而后看了其余博主的博客设计
本题要求实现两个函数,分别将读入的数据存储为单链表、将链表中偶数值的结点删除。链表结点定义以下:3d
struct ListNode { int data; struct ListNode *next; };
struct ListNode *createlist(); struct ListNode *deleteeven( struct ListNode *head );
函数createlist从标准输入读入一系列正整数,按照读入顺序创建单链表。当读到−1时表示输入结束,函数应返回指向单链表头结点的指针。指针
函数deleteeven将单链表head中偶数值的结点删除,返回结果链表的头指针。
#include <stdio.h> #include <stdlib.h> struct ListNode { int data; struct ListNode *next; }; struct ListNode *createlist(); struct ListNode *deleteeven( struct ListNode *head ); void printlist( struct ListNode *head ) { struct ListNode *p = head; while (p) { printf("%d ", p->data); p = p->next; } printf("\n"); } int main() { struct ListNode *head; head = createlist(); head = deleteeven(head); printlist(head); return 0; } /* 你的代码将被嵌在这里 */
1 2 2 3 4 5 6 7 -1
1 3 5 7
#include <stdio.h> #include <stdlib.h> struct ListNode { int data; struct ListNode *next; }; struct ListNode *createlist(); struct ListNode *deleteeven( struct ListNode *head ); void printlist( struct ListNode *head ) { struct ListNode *p = head; while (p) { printf("%d ", p->data); p = p->next; } printf("\n"); } int main() { struct ListNode *head; head = createlist(); head = deleteeven(head); printlist(head); return 0; } struct ListNode *createlist() { struct ListNode *head,*p; head = (struct ListNode *)malloc(sizeof(struct ListNode)); p = head; head->next=NULL; //指向运算符-> int num; while(scanf("%d",&num)!=EOF&&num!=-1) { p->next= (struct ListNode *)malloc(sizeof(struct ListNode)); p=p->next; p-> data=num; p->next=NULL; } head=head->next; return (head); } struct ListNode *deleteeven(struct ListNode *head) { struct ListNode *p,*a; if(head == NULL) { return NULL; } p=head; a=p->next; while(a!=NULL) { if(a->data%2==0) { p->next=a->next; free(a); a=p->next; } else { p=p->next; a=p->next; } } if(head->data%2==0) { head=head->next; } return(head); }
问题:本题不太会作,想法简单,作起来难。感受要想清楚的点有不少。while语句及if语句的判断条件我不会写。
解决方法:查了资料,看了其余博客的代码,上面这个代码就是看的别人的代码,正在努力读懂及理解中
本周学习了第11章指针进阶,主要讲了如下几点的区别及用法:
数组指针:数组指针强调的是指针,而且这个指针指向一个数组,即指针变量存放的是数组地址。eg:int (a)[10],其中a是一个指针,而且指向一个含有10个整型元素的数组。
指针数组:指针数组强调的是数组,而且数组元素是指针类型。eg:int a[10],其中a是一个数组,数组元素是指针(int)。
指针函数:指针函数指带有指针的函数,即其本质是一个函数,只不过这种函数返回的是一个对应类型的地址。eg:int function(int m){printf("this is a function");return m; } int main(){int p, data = 5;p = function(&data);printf("%d\n", p); //打印出data的值}
函数指针:函数指针是指向可执行代码段或调用可执行代码段的信息块的指针,而不是指向某种数据的指针。函数指针是将函数当作普通数据那样存储和管理。eg:void test(char str);void (p)(char),其中p是一个指针,而且指向一个函数,这个函数参数是char,返回类型是void型。
二级指针:二级指针指的是A(即B的地址)是指向指针的指针,用于存放二级指针的变量称为二级指针变量.根据B的不一样状况,二级指针又分为指向指针变量的指针和指向数组的指针。eg:int i,p,**pi;p=&i; pi=π
单向链表:单向链表(单链表)是链表的一种,其特色是链表的连接方向是单向的,对链表的访问要经过顺序读取从头部开始。 经过指针链接起来,可是只能单向遍历的内存块。eg:这里有一个单向链表的经典示例
感悟:感受这周的做业前两题还行,最后一题对我来讲比较难。继续努力吧!加油!
开发的项目名称:贪吃蛇
目标:能清楚的把贪吃蛇这个游戏搞出来
首先先构造出小蛇,让小蛇移动,而后让玩家控制小蛇移动,让系统判断游戏失败,最后让小蛇吃食物增长长度。
初步定了游戏开发项目,而后了解游戏内容,打算继续看书,深刻了解游戏并开发
小组成员:熊亚婷,章满,张英杰
进度安排:初步定了游戏,后期小组将继续讨论游戏,完成游戏的后期操做
本周三晚自习依旧是咱们结对编程的时间,我和搭档在寝室讨论了一番,可是仍是有不少地方不清楚,咱们俩都不会最后一题。而后就各自查资料了,总的来讲仍是有收获的。
周/日期 | 这周所花的时间 | 代码行数 | 学到的知识点简介 | 目前比较迷惑的问题 |
---|---|---|---|---|
2/25-3/3 | 三天 | 45 | 数组的认识及用法 | 数组长度的理解 |
3/4-3/10 | 两天 | 37 | 编写程序时处理文件 | fscanf与fprintf的具体用法 |
3/11-3/17 | 三天 | 53 | 二维数组的使用及文件插入 | 二维数组的用法、上三角的判断及文件的处理 |
3/18-3/24 | 两天 | 113 | 选择排序法、二分查找法、二维数组的引用与矩阵 | 不清楚选择排序法和冒泡排序法的区别 |
3/25-3/31 | 两天 | 78 | 判断回文、一维字符数组的用法、使用字符串编程 | 使用字符串编程 |
4/1-4/7 | 两天 | 88 | 指针变量的基本运算,内存单元和地址之间的关系 | 不太了解指针数组 |
4/8-4/14 | 两天 | 96 | 指针、数组和地址之间的关系 | 对于指针数组和数组指针的区别不是特别清楚 |
4/15-4/21 | 两天 | 128 | 字符串和字符指针、经常使用的字符串处理函数 及用指针实现内存动态分配 | 对于指针都不是特别懂 |
4/22-4/28 | 两天 | 120 | 定义结构,使用结构变量与结构数组进行编程 | 结构体参与判断 |
4/29-5/4 | 一天 | 0 | 结构数组及结构指针 | 结构指针 |
5/5-5/11 | 两天 | 26 | 递归函数的定义及使用 | 递归函数的使用 |
5/12-5/18 | 两天 | 153 | 指针函数与函数指针的区别 | 不太会用二级指针 |
时间 | 代码行数 | 博客字数 |
---|---|---|
第一周 | 45 | 870 |
第二周 | 37 | 1055 |
第三周 | 112 | 1158 |
第四周 | 113 | 1696 |
第五周 | 78 | 1854 |
第六周 | 114 | 2977 |
第七周 | 96 | 3019 |
第八周 | 128 | 3264 |
第九周 | 120 | 3540 |
第十周 | 0 | 3216 |
第十一周 | 26 | 3186 |
第十二周 | 153 | 3045 |