作业头内容
这个作业属于那个课程 |
这个作业要求在哪里 |
我在这个课程的目标是 |
这个作业在那个具体方面帮助我实现目标 |
参考文献 |
基础作业:
6-1 计算最长的字符串长度
本题要求实现一个函数,用于计算有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
", max_len(string, n));
return 0;
}
/* 你的代码将被嵌在这里 */
输入样例:
4
blue
yellow
red
green
输出样例:
6
实验代码:
int max_len( char *s[], int n )
{
int m=0,i,t;
for(i=0;i<n;i++)
{
t=strlen(s[i]);
if(m < t)
{
m=t;
}
}
return m;
}
实验思路:
错误截图:
错误分析:未对m赋值。
解决方法:对m赋值为0,即m=0。
运行截图:
6-2 统计专业人数
本题要求实现一个函数,统计学生学号链表中专业为计算机的学生人数。链表结点定义如下:
struct ListNode {
char code[8];
struct ListNode *next;
};
这里学生的学号共7位数字,其中第2、3位是专业编号。计算机专业的编号为02。
函数接口定义:
int countcs( struct ListNode *head );
其中head是用户传入的学生学号链表的头指针;函数countcs统计并返回head链表中专业为计算机的学生人数。
裁判测试程序样例:
#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
", countcs(head));
return 0;
}
/* 你的代码将被嵌在这里 */
输入样例:
1021202
2022310
8102134
1030912
3110203
4021205
#
输出样例:
3
实验代码:
int countcs( struct ListNode *head )
{
int n = 0 , i;
struct ListNode *p = head;
whilep != NULL)
{
if(p->code[1] == '0' && p->code[2] == '2')
n++;
p=p->next;
}
return n;
}
and
int countcs( struct ListNode *head )
{
int n = 0 , i;
struct ListNode *p = head;
for(p = head;p != NULL;p = p->next)
{
if(p->code[1] == '0' && p->code[2] == '2')
n++;
}
return n;
}
实验思路:
错误截图:
错误分析:第一段代码改第二段代码时粗心把";"写成了","
解决方法:","->";"
运行截图:
6-3 删除单链表偶数节点
本题要求实现两个函数,分别将读入的数据存储为单链表、将链表中偶数值的结点删除。链表结点定义如下:
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("
");
}
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
实验代码:
typedef struct ListNode *List;
struct ListNode *createlist()
{
int n;
struct ListNode *head=NULL,*tail=NULL,*p=NULL;
scanf("%d",&n);
while(n!=-1)
{
p=(struct ListNode *)malloc(sizeof(struct ListNode));
p->data=n;
p->next=NULL;
if(head==NULL)
head=p;
else
tail->next=p;
tail=p;
scanf("%d",&n);
}
return head;
}
struct ListNode *deleteeven( struct ListNode *head )
{
List p=head,q;
while(p!=NULL)
{
if(p->data%2==0)
{
if(p==head)
{
head=head->next;
free(p);
}
else
{
q->next=p->next;
free(p);
}
}
else
{
q=p;
}
p=p->next;
}
return head;
}
实验思路:
错误截图:
错误分析:未声明"List"
解决方法:声明"List",即添加语句"typedef struct ListNode *List;"
运行截图:
挑战作业:
虽然看了视频,但是还是不太懂。
预习作业:
从第十三周开始,将进入课程设计阶段,在本次作业中给出:
1.所在小组想要开发的项目的名称和目标;
根据一定程度上C语言基础,小组讨论决定制作的小游戏名称被命名为《小鬼战斗机》的飞行游戏,
目标:软件能顺利运行,能灵活控制。
2.项目主体功能的描述;
1、页面初始化;
2、按规律发射子弹;
3、敌机移动;
4、自动产生新敌机;
……
3.现阶段已做的准备工作;
参考资料:《C语言课程设计与游戏开发实践教程》;
……
4.小组成员名单和进度安排。(课程设计阶段:13-17周)
组员:张诚超、陈小强、邓 鹏。
安排:先了解软件制作的流程。
……
学习感悟:
(1)本周你学习哪些内容(不限于课上)?你有哪些收获?
主要学习为指针进阶部分,通过课堂学习和例题分析,其中更深刻的理解指针数组、数组指针与指针函数,和函数指针有了初步了解。
(2)本周所学内容中你觉得哪些地方是难点?对此你做了哪些措施去克服这些困难?
难点:对数组指针和指针数组的分别,以及多函数结构在运行至return处为什么继续运行自定义函数。
措施:查书、和同学探讨。
结对编程感受:
(1)过程:
本周的编程作业基础题都是先理解题目给出的程序代码在根据题目要求补写自定义函数,以完善程序;我们先一起讨论各自对已有代码的解读,再设计逻辑,因为有些解法很多但又复杂,且思路形象来表达简单,可以很好的进行建立各自观点,再对代码脉络进行编写与修改;两人一起编写代码,再通过相关软件运行进行检查代码,有问题一起检查与修改。最后,进行讨论,对问题理解清晰、相对简单的题目谈论不同思路。
(2)照片:
(3)看法:
结对编程有利于提高编程效率,同时集合两人思维多角度看问题,促进学习。
学习进度条
第十二周 | 5/13-/18 | 计12小时 | 450+ |
第十一周 | 5/5-/10 | 计9小时 | 600+ |
第九周 | 4/22-/26 | 计13小时 | 250+ |
第八周 | 4/15-/19 | 计13小时 | 150+ |
第七周 | 4/8-4/11 | 计9小时 | 250+ |
第六周 | 3/29-4/5 | 计14小时 | 300+ |
第五周 | 3/25-3/28 | 计6小时 | 200+ |
第四周 | 3/18-3/22 | 计7小时 | 300+ |
第三周 | 3/11-3/16 | 计5小时 | 200+ |
折线图