-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
软件:week7 实验:c程序测试与断点调试 #17
Comments
Lab 3 : Breakpoint DebugPre Assignment:
Notice that: Assignment 0(10pts)Learn about command line compile and file input. And then use the method on one of the questions in week 7 in sicily (write this part in your report and snap shoots are recommended). Assignment 1(80pts):Learn about breakpoint debug method yourself and using it to debug the following three C programs. Target: A solution with three correct C source programs. Questions:
Notice that:
input:
3
3 1 3 2
5 1 2 3 4 5
4 99 100 22 33
output:
1 2 3
1 2 3 4 5
22 33 99 100 Also Notice that the output of the flowing program is not correct at all, please correct it link: Program 1 Bubble sort#include <stdio.h>
int main() {
int num[10000];
int n;
int i, j, temp;
int m, k, p, q, o;
int result[2000];
scanf("%d", &n);
for(i = 0; i < n; i++) {
scanf("%d", &num[i]);
}
for(i = 0; i <= n; i++) {
for(j = 0; i + j < n; j++) {
if(num[j] > num[j + 1]) {
temp = num[j];
num[j + 1] = num[j];
num[j] = temp;
}
}
}
for(i = 0; i < n - 1; i++) {
printf("%d ", num[i]);
}
printf("%d\n", num[i]);
return 0;
} Program 2 Insertion sort#include <stdio.h>
int main() {
int num[10000];
int n;
int i, j, temp;
scanf("%d", &n);
for(i = 0; i < n; i++) {
scanf("%d", &num[i]);}
for(i=1; i<n; i++){
temp = num[i];
for(j=i-1; j>-1&&num[j]>temp;j--) {
num[i]=num[j]; num[j]=temp;}}
for(i = 0; i < n - 1; i++) {
printf("%d ", num[i]);}
printf("%d\n", num[i]);
return 0;
} Program 3 Selection sort#include <stdio.h>
int main() {
int num[10000];
int n;
int i, j, temp;
scanf("%d", &n);
for(i = 0; i < n; i++)
scanf("%d", &num[i]);
for(i=0; i < n; i++){
min = num[i];
for(j = i; j < n; j++) {
if(min>num[j]) {
temp = num[j];
num[j] = min;
min = temp;
} for(i = 0; i < n - 1; i++) {
printf("%d ", num[i]);}
printf("%d\n", num[i]);
return 0;
} Discussion,Cooperation and Summary (15pts)In this part, you will have some options, if you do more options, you will learn more and get more marks. option 1: Github DiscussionComment at the issue which is opened for dicuss for week7 and decribe a problem that you meet and how you solve detailedly. Notice that
option 2: Simple PresentationHave a simple presentation in the lab class on Monday (4 persons limited). And after the presentation, everyone is encouraged to ask questions and you can get bonus by asking good questions. Notice that
option 3: Helping othersYou can help others to slove any problems the will meet. Detailedly decribe the quesion, the solution and your personal experience as well. Notice that
option 4: Personal SummaryWrite personal summary for yourself. Notice that
Report:Contents: Submit作业发给学委,不要发压缩包,注意文件命名必须完全一致,否则机器测试无法进行,0分处理。 Deadline:18:00 Nov 19th Note that homework after deadline will not be accepted this time whatever your reasons. |
Extra作业:1、 期中考试没有全部Accepted的同学,请将没有ac的题目重新做完,自行测试好。 Submit:1、没做完的题目的源代码,以pid.c命名,即1000.c等放在自己学好的文件夹。 2、发给学习委员,统一整理后发给我 Deadline:2015年11月22日晚9点 不接受缓交 |
实验3:c程序断点调试
C程序完成一般思路
高效c语言编程方法
1、命令行编译与高效文本编辑器
为什么使用命令行编译?
配置方法:
1、打开Dev Cpp,并且找到对应的安装路径。
2、找到定义的MinGW目录下的bin目录这个是dev cpp的核心编译器。
3、配置系统环境变量,在系统的高级选项中找到path(可见第一周python配置方法)
4、打开cmd窗口,输入gcc --version输出编译器版本信息,配置完成。
编译方法:
1、找到一个c源代码所在的文件夹,在文件夹中按住shift+鼠标右键,选择在此处打开命令行。
2、输入gcc + 空格 + 你要编译的文件 -o 编译出来之后的可执行程序的名字, 如:
gcc main.c -o main.exe
(如果省略-o后面的命令,则会生成a.exe)3、在命令行中输入 main.exe 即可运行程序。
高效文本编辑器:
高效文本编辑器是一些专门为编程者设计的编辑器,他们具有自动缩进、自动补全代码、自由配置的特点,深受程序员喜爱。这些编辑器不仅仅c语言使用,c++、pyhton、html、markdown和许多其他语言都适用。他们有,vim、emacs、sublime等。
现在我们介绍sublime-text 3,这是一款收费软件,可是有无限试用期。
下载和使用请自行百度。
2、测试数据的文件输入输出代替键盘输入输出(重点)
现在大家做题一般的输入方法就是,按照西西里的测试例子,键盘输入,当程序错误的时候需要一次次输入非常繁琐,现在给大家提供一种高效而且重要的方法,文件流输入代替键盘流输入。
其实,在抽象的层面上,键盘输入、文件输入和网络输入等都是IO,是等价的。我们可以利用这个进行文件代替键盘输入。
1、在刚才我们编译的程序之中,我们生成了main.exe的程序。建设现在我们的程序是做a-b的简单运算。我们现在在源代码的同一个目录下新建一个文件"input.txt"。我们打开文件输入两个数100和99。
2、接着我们在命令行输入命令
main.exe < input.txt
。我们很惊喜地发现,程序自动输出了1,我们不需要手动去使用键盘输出。对于长而复杂的输入,这无疑是一个简化的过程。
对于文件输出,同样是可以的 'main.exe < input.txt >output.txt'
3、断点调试法(课题讲解)
错误示例代码(来源于同学)
1、设置断点
2、运行程序
3、添加监控变量
4、执行程序、单步运行
The text was updated successfully, but these errors were encountered: