wujr5 / c-and-cpp-language-learning

C和C++编程语言学习 - 2015级
68 stars 34 forks source link

计科:week7 第五次实验报告 #25

Open wujr5 opened 9 years ago

wujr5 commented 9 years ago

计科:week7 第五次实验报告

1 编程相关

1.1 C++程序完成思路

  1. 对于复杂的逻辑需求,先写伪代码或者画程序流程图得到清晰的逻辑结构。
  2. 自顶向下逐步求精解决问题(大问题分解为可解决的小问题),写出C++程序。
  3. 修改C++程序的编译错误。
  4. 通过测试,修改C++程序的逻辑错误。

    1.2 命令行编译

为什么使用命令行编译?

  1. 可以获得比集成编译系统(IDE)更高的自由度。
  2. 为之后的linux编程工具链打下基础。
  3. 更好的理解c++程序编译执行过程。

配置方法:

1、打开Dev Cpp,并且找到对应的安装路径。

dev

2、找到定义的MinGW目录下的bin目录这个是dev cpp的核心编译器。

3、配置系统环境变量,在系统的高级选项中找到path(可见第一周python配置方法)

path

4、打开cmd窗口,输入gcc --version输出编译器版本信息,配置完成。

编译方法:

  1. 找到一个c++源代码所在的文件夹,在文件夹中按住shift+鼠标右键,选择在此处打开命令行。
  2. 输入g++ + 空格 + 你要编译的文件 -o 编译出来之后的可执行程序的名字, 如:g++ main.cpp -o main.exe(如果省略-o后面的命令,则会生成a.exe)
  3. 在命令行中输入 main.exe 即可运行程序。

    1.3 测试数据的文件输入输出

现在大家做题一般的输入方法就是,按照西西里的测试例子,键盘输入,当程序错误的时候需要一次次输入非常繁琐,现在给大家提供一种高效而且重要的方法,文件流输入代替键盘流输入。

其实,在抽象的层面上,键盘输入、文件输入和网络输入等都是IO,是等价的。我们可以利用这个进行文件代替键盘输入。

  1. 在刚才我们编译的程序之中,我们生成了main.exe的程序。假设现在我们的程序是做a-b的简单运算。我们现在在源代码的同一个目录下新建一个文件"input.txt"。我们打开文件输入两个数100和99。
  2. 接着我们在命令行输入命令main.exe < input.txt。我们很惊喜地发现,程序自动输出了1,我们不需要手动去使用键盘输出。

对于长而复杂的输入,这无疑是一个简化的过程。

对于文件输出,同样是可以的 main.exe < input.txt > output.txt

2 断点调试法(课题讲解)

#include<iostream>
using namespace std;

struct employee {
    long id, salary, height, boss, subordinate;
};
int main() {
    struct employee a[10000], temp, current_deal, potential_boss, search;
    int total_test, current_test, current_e, e_num, id_search;
    int i, k, j, m, n, t, u;
    for (u = 1;u <= 10000;u++) {
        a[u].subordinate = 0;
        a[u].boss = 0;
        a[u].height = 0;
        a[u].id = 0;
        a[u].salary = 0;
    }
    cout << "How many test do you want to have?\n";
    cin >> total_test;

    current_test = 1;
    while (current_test <= total_test) {
        cout << "please input the number of employees\n";
        cin >> e_num;

        current_e = 1;
        for (i = 1;current_e <= e_num;i++) {
            printf("please input No.%d empolyees' id, salary, height(seperated by space)\n", i);
            scanf("%d %d %d", &a[i].id, &a[i].salary, &a[i].height);
            current_e ++;
        }
        for (k = 1;k <= (e_num - 1);k++) {
            for(j = 1;j <= (e_num - 1);j++) {
                if(a[j].salary > a[j+1].salary) {
                    temp = a[j];
                    a[j] = a[j+1];
                    a[j+1] = temp;
                }
            }
        }

        for (m = 1;m <= e_num;m++) {
            current_deal = a[m];
            for(n = e_num;n <= (m + 1);n--) {
                potential_boss = a[n];
                if(current_deal.height <= potential_boss.height) {
                    a[m].boss = potential_boss.id;
                    a[n+1].subordinate += 1;
                }
            }
        }

        cout << "please input the id you want to search for its boss and subordinates\n";
        cin >> id_search;

        for (t = 1;t <= e_num;t++) {
            if (id_search == a[t].id) {
                search = a[t];
            }
        }

        cout << "(" << search.boss  << ", " << search.subordinate;
        current_test ++;
    }

    return 0;
}
  1. 设置断点
  2. 运行程序
  3. 添加监控变量
  4. 执行程序、单步运行

    3 实验报告内容 Breakpoint Debug

    3.1 Pre Assignment

  5. Learn about breakpoint debug method.
  6. Learn about file stream input for a C++ executable program.
  7. Learn about how to compile a program using command line interface.

Notice that

These knowledge is very important for you and it is a good preparation for the course project as well as some other following courses. You can ignore this assignment, but you are responsible for the yourself.

3.2 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).

3.3 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 program.

Questions:

  1. What is the bugs of the program and how can you find the bug? (8 pts)
  2. What test data you use in the debug process? (8 pts)
  3. Tell the problems about coding styling in the following program.(8 pts)
  4. Understand three sorting algorithm(Bubble sort, selection sort and insertion sort), and then write Pseudo code or Flowchart for them respectively.(16 pts)
  5. Correct these three programs include its style problems respectively and note that you should submit your source code. (55pts )

Notice that

  1. Style is very important while coding, so if your new program is still ugly in style, 50% score will be deducted.
  2. We will use black box test this time with auto running scripts. So if your file structure is wrong or your program result in errors will cause 0pts. And the grade depends on how many test cases passed like that in YOJ.
  3. You should not add prompt statement this time like "please input an integer". The testing program will consider it to be wrong answer if you do it.
  4. Sample input and output for all the three correct program.

Input: The first line contain an integer n which indicates the number of test cases. There will be n line in the flowing. For each line, there will be an integer m at the first of the line which means the size of the array. And there will be m integers. Note that, 1<n<20, 1<m<10000.

Output: For each input output the sorted array(from small to big) with spaces between elements.

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: bubble sort insertion sort selection sort

3.3.1 Program 1 Bubble sort

#include<iostream>
using namespace std;

int main() {
int num[10000];
int n;
int i, j, temp;
int m, k, p, q, o;
int result[2000];

cin >> n;

for(i = 0; i < n; i++) {
cin >> 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++) {
cout << num[i] << " ";
}
cout << num[i] << endl;

return 0;
}

3.3.2 Program 2 Insertion sort

#include <iostream>
using namespace std;

int main() {
  int num[10000];
  int n;
  int i, j, temp;
  cin >> n;
  for(i = 0; i < n; i++) {
  cin >> 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++) {
  cout << num[i] << " ";}
  cout << num[i] << endl;
  return 0;
}

3.3.3 Program 3 Selection sort

#include <iostream>
using namespace std;

int main() {
  int num[10000];
  int n;
  int i, j, temp;
  int min;
  cin >> n;
  for(i = 0; i < n; i++)
    cin >> 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++) {
    cout << num[i] << " ";}
  cout << num[i] << endl;
  return 0;
}
}
}

3.4 Report

  1. part one: Assignment 0
  2. part two: Assignment 1
  3. part three: Discussion,Cooperation and Summary (optional)

格式无要求,part two必须截图表明你使用了断点调试的技巧来调试你的代码,包括但不限于:如何添加断点,如何删除断点,如何运行下一条语句,如何运行到下一个断点,如何添加查看,如何删除查看,等等。

3.5 Submit lists

作业发给学委,不要发压缩包,注意文件命名必须完全一致,否则机器测试无法进行,0分处理。

3.6 Deadline

19 Nov. 2015, 23:59

Please submit your homework on time.

4 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.

You should note this part in your report

option 1: Github Discussion

Comment at this issue and describe a problem that you meet and how you solve it detailedly.

Notice that

  1. you should not copy and paste your personal report simply.
  2. you should not write a very simple one and your comment will be deleted if you do that.
  3. you should not post meaningless questions.
  4. Show me in your report about your discussion on github with screenshot.

    option 2: Simple Presentation

Have a simple presentation in the lab class on Friday (4 persons limited). And after the presentation, everyone is encouraged to ask questions and you can get bonus by asking good questions.

Notice that

  1. The presentation is no more than 5 minutes and there will be 5 extra minutes for discussion.
  2. You should prepare much for it. PPT is encouraged.
  3. First come, first get the opportunity.
  4. You can describe a algorithm you have learn, but you should make a majority of your classmates know what you are describing.
  5. You can also share with us your learning experience about C++, and give some advice about how to learn it well.
  6. The theme of your presentation is very important, if you are not sure whether your theme is good or not, you can contact me for some advice.

    option 3: Helping others

You can help others to solve any problems the will meet. Detailedly describe the question, the solution and your personal experience as well.

Notice that

  1. it is no need to consult with others that I help you, you help you to get marks. You can simply send email to me and I will give you the marks. No worry about that, if you do have helped others and spent a lot of time on it, you deserve the score.

    option 4: Personal Summary

Write personal summary for yourself. List at least 10 problems that you have met in your learning in C++ language and describe the solution as well.

Notice that

  1. you should not have ten very simple problems, you must let me know your learning method and also the method to solve problems.
SchroDeCat commented 9 years ago

不做option拿不了全分吗?

SchroDeCat commented 9 years ago

image

调试出现这个怎么办 -点yes image -点no 正常运行,没有调试

SgLy commented 9 years ago

@wujr5

What is the bugs of the program and how can you find the bug? (8 pts) What test data you use in the debug process? (8 pts)

几个排序算法的问题很容易看出来……感觉不需要调试,所以要强行调试吗

Understand three sorting algorithm(Bubble sort, selection sort and insertion sort), and then write Pseudo code or Flowchart for them respectively.(16 pts)

制作一个排序算法的流程图非常花费时间,上次我还因此迟交。分数和时间代价是否不成比例?

linzhk commented 9 years ago

如果输出出现8.7e+002 这是有什么造成的?应该如何把他变成有两位小数的情况呢?

SgLy commented 9 years ago

@yyh14353191

如果是输出一个浮点数的话,在代码头加上

#include <iomanip>

然后使用

cout << fixed << setprecision(2) << YourFloatNumber;

no553216989 commented 9 years ago

流程图和伪代码是在实验报告里面一起上交吗?

SchroDeCat commented 9 years ago

image 前面的调试无法进行的问题搞定了,我的是在Tools > Compiler Options > Compiler set to configure 里调成debug的设置,有类似问题的同学可以参考下

Icenowy commented 9 years ago

调试程序是要生成调试信息的。但是发布的程序不能带有调试信息,一是这种东西太大,二是没必要,三是(对于闭源软件)泄漏内部信息,四是方便破解。 所以编译器大多可以选择是否生成调试信息。 比如gcc(其他UNIX系cc类似)用-g参数指定调试信息的生成。

---- SchroDeCat编写 ----

前面的调试无法进行的问题搞定了,我的是在Tools > Compiler Options > Compiler set to configure 里调成debug的设置,有类似问题的同学可以参考下

— Reply to this email directly or view it on GitHub.

StealMyGirl commented 9 years ago

sicily上显示Your program got fatal errors in runtime......受到了惊吓。。。在Dev上运行的很正常,这种runtime error主要应该是什么问题?

Icenowy commented 9 years ago

dev和sicily用的基础C库不一样/你的程序处理的数据范围太小

---- StealMyGirl编写 ----

sicily上显示Your program got fatal errors in runtime......受到了惊吓。。。在Dev上运行的很正常,这种runtime error主要应该是什么问题?


Reply to this email directly or view it on GitHub: https://github.com/wujr5/c-and-cpp-language-learning/issues/25#issuecomment-156771184

Icenowy commented 9 years ago

哪道题

---- StealMyGirl编写 ----

......所以有什么可提供的方法解决吗达神......


Reply to this email directly or view it on GitHub: https://github.com/wujr5/c-and-cpp-language-learning/issues/25#issuecomment-156771556

StealMyGirl commented 9 years ago

输出分数最高的前两名那个

Icenowy commented 9 years ago

你试试搞个大的数据范围。。。随机生成1000000个数据试试?

---- StealMyGirl编写 ----

输出分数最高的前两名那个


Reply to this email directly or view it on GitHub: https://github.com/wujr5/c-and-cpp-language-learning/issues/25#issuecomment-156771737

Icenowy commented 9 years ago

提示 的rand()函数能生成0到RAND_MAX(常量)范围的随机数

---- StealMyGirl编写 ----

输出分数最高的前两名那个


Reply to this email directly or view it on GitHub: https://github.com/wujr5/c-and-cpp-language-learning/issues/25#issuecomment-156771737

zhuzq5 commented 9 years ago

那个输出分数最高的两名用冒泡排序应该可以吧

Icenowy commented 9 years ago

不需要。用冒泡排序反而效率低下+容易造成程序错误。用“打擂台”方式,如果新的数据大于现在的第一名,就让现在的第一成为第二,新数据成为第一;如果新的数据大于现在的第二,就让新的数据成为第二。(看得懂么,逃

---- point.point编写 ----

那个输出分数最高的两名用冒泡排序应该可以吧


Reply to this email directly or view it on GitHub: https://github.com/wujr5/c-and-cpp-language-learning/issues/25#issuecomment-156772145

zhuzq5 commented 9 years ago

哇 我真的看不懂 你说的详细点吧

Icenowy commented 9 years ago

int max1,max2; for(int i = 0; i<n; i++) { int tmp; cin >> tmp; if (tmp > max1) { max2 = max1; max1 = tmp; } else if (tmp > max2) { max2 = tmp; } }

}

---- point.point编写 ----

哇 我真的看不懂 你说的详细点吧


Reply to this email directly or view it on GitHub: https://github.com/wujr5/c-and-cpp-language-learning/issues/25#issuecomment-156773919

snowdreamzcl commented 9 years ago

include

include

using namespace std;

int main(){ ofstream output; output.open("number.txt"); output << "1 " << "2 " << "3" << endl; output.close();

ifstream input;
input.open("number.txt");
int a;
while (!input.eof()){
    input >> a;
    cout << a;
} 
input.close();
return 0;

} 这是一个文件输入输出的操作,我想先创建一个文件number.txt来保存1 2 3,再读取输出文件的内容,但是为什么是1233,会多出一个3呢? 求解

Icenowy commented 9 years ago

读入number.txt的时候第一次input.eof() = false, a = 1, 继续循环第二次input.eof() = false, a = 2, 继续循环第三次input.eof() = false, a = 3, 继续循环第四次input.eof() = true, 但因为先执行的input.eof()判断后执行的input >> a, 所以a读入失败,还是3然后下一次循环的时候,input.eof()终于是true了,然后退出所以输出1233

Date: Sun, 15 Nov 2015 04:22:45 -0800 From: notifications@github.com To: c-and-cpp-language-learning@noreply.github.com CC: icenowy@outlook.com Subject: Re: [c-and-cpp-language-learning] 计科:week7 第五次实验报告 (#25)

include

include

using namespace std;

int main(){

ofstream output;

output.open("number.txt");

output << "1 " << "2 "  << "3" << endl;

output.close();

ifstream input; input.open("number.txt"); int a; while (!input.eof()){ input >> a; cout << a; } input.close(); return 0;

} 这是一个文件输入输出的操作,我想先创建一个文件number.txt来保存1 2 3,再读取输出文件的内容,但是为什么是1233,会多出一个3呢? 求解

― Reply to this email directly or view it on GitHub.

snowdreamzcl commented 9 years ago

@Icenowy 但不是当第四次循环开始时判断input.eof() = true 就不能执行循环体了么,为什么还要考虑循环体内的a读入失败呢?

Icenowy commented 9 years ago

因为第三次读的时候还没有eof(别忘了你输出的endl),第四次读的时候发现找不到数字才eof的,第三次读完文件里还有了\n没读呢~

---- 四月的雨季编写 ----

@Icenowy 但不是当第四次循环开始时判断input.eof() = true 就不能执行循环体了么,为什么还要考虑循环体内的a读入失败呢?


Reply to this email directly or view it on GitHub: https://github.com/wujr5/c-and-cpp-language-learning/issues/25#issuecomment-156809660

snowdreamzcl commented 9 years ago

哦,这样,还有一个空格,谢啦

Icenowy commented 9 years ago

not 空格 but endl

---- 四月的雨季编写 ----

哦,这样,还有一个空格,谢啦


Reply to this email directly or view it on GitHub: https://github.com/wujr5/c-and-cpp-language-learning/issues/25#issuecomment-156810625

Kunlun-Zhu commented 9 years ago

配置系统环境变量后,用g++ --version提示g++不是内部或外部命令是怎么回事 Path:C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\C:\Dev-Cpp\mingw32\bin

Icenowy commented 9 years ago

没有加;

---- yyh15336264编写 ----

配置系统环境变量后,用g++ --version提示g++不是内部或外部命令是怎么回事 Path:C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\C:\Dev-Cpp\mingw32\bin


Reply to this email directly or view it on GitHub: https://github.com/wujr5/c-and-cpp-language-learning/issues/25#issuecomment-157236084

Kunlun-Zhu commented 9 years ago

在哪加;,求助

Kunlun-Zhu commented 9 years ago

C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Dev-Cpp\mingw32\bin; 这样可以吗

------------------ 原始邮件 ------------------ 发件人: "Thomastsing";notifications@github.com; 发送时间: 2015年11月18日(星期三) 凌晨0:09 收件人: "wujr5/c-and-cpp-language-learning"c-and-cpp-language-learning@noreply.github.com; 抄送: "klz"516455665@qq.com; 主题: Re: [c-and-cpp-language-learning] 计科:week7 第五次实验报告 (#25)

[Uploading QQ图片20151118000823.png…]()

@yyh15336264 看图片

— Reply to this email directly or view it on GitHub.

Icenowy commented 9 years ago

分号不对,应该是英语分号(;)不是中文分号。关掉输入法再输入那个分号

---- yyh15336264编写 ----

C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Dev-Cpp\mingw32\bin; 这样可以吗

------------------ 原始邮件 ------------------ 发件人: "Thomastsing";notifications@github.com; 发送时间: 2015年11月18日(星期三) 凌晨0:09 收件人: "wujr5/c-and-cpp-language-learning"c-and-cpp-language-learning@noreply.github.com; 抄送: "klz"516455665@qq.com; 主题: Re: [c-and-cpp-language-learning] 计科:week7 第五次实验报告 (#25)

[Uploading QQ图片20151118000823.png…]()

@yyh15336264 看图片

— Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub: https://github.com/wujr5/c-and-cpp-language-learning/issues/25#issuecomment-157587549

Kunlun-Zhu commented 9 years ago

C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0;C:\Dev-Cpp\mingw32\bin;这样也不行

------------------ 原始邮件 ------------------ 发件人: "Icenowy Zheng";notifications@github.com; 发送时间: 2015年11月18日(星期三) 中午11:04 收件人: "wujr5/c-and-cpp-language-learning"c-and-cpp-language-learning@noreply.github.com; 抄送: "klz"516455665@qq.com; 主题: Re: [c-and-cpp-language-learning] 计科:week7 第五次实验报告 (#25)

分号不对,应该是英语分号(;)不是中文分号。关掉输入法再输入那个分号

— Reply to this email directly or view it on GitHub.

Icenowy commented 9 years ago

Dev-C++装在C:\Dev-Cpp?什么版本?

---- yyh15336264编写 ----

C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0;C:\Dev-Cpp\mingw32\bin;这样也不行

------------------ 原始邮件 ------------------ 发件人: "Icenowy Zheng";notifications@github.com; 发送时间: 2015年11月18日(星期三) 中午11:04 收件人: "wujr5/c-and-cpp-language-learning"c-and-cpp-language-learning@noreply.github.com; 抄送: "klz"516455665@qq.com; 主题: Re: [c-and-cpp-language-learning] 计科:week7 第五次实验报告 (#25)

分号不对,应该是英语分号(;)不是中文分号。关掉输入法再输入那个分号

— Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub: https://github.com/wujr5/c-and-cpp-language-learning/issues/25#issuecomment-157588962

Kunlun-Zhu commented 9 years ago

4.9.9.0

------------------ 原始邮件 ------------------ 发件人: "Icenowy Zheng";notifications@github.com; 发送时间: 2015年11月18日(星期三) 中午11:28 收件人: "wujr5/c-and-cpp-language-learning"c-and-cpp-language-learning@noreply.github.com; 抄送: "klz"516455665@qq.com; 主题: Re: [c-and-cpp-language-learning] 计科:week7 第五次实验报告 (#25)

Dev-C++装在C:\Dev-Cpp?什么版本?

— Reply to this email directly or view it on GitHub.

Icenowy commented 9 years ago

这么老的版本不行哒~(其实可以,但是。。。)装个最新版吧

---- yyh15336264编写 ----

4.9.9.0

------------------ 原始邮件 ------------------ 发件人: "Icenowy Zheng";notifications@github.com; 发送时间: 2015年11月18日(星期三) 中午11:28 收件人: "wujr5/c-and-cpp-language-learning"c-and-cpp-language-learning@noreply.github.com; 抄送: "klz"516455665@qq.com; 主题: Re: [c-and-cpp-language-learning] 计科:week7 第五次实验报告 (#25)

Dev-C++装在C:\Dev-Cpp?什么版本?

— Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub: https://github.com/wujr5/c-and-cpp-language-learning/issues/25#issuecomment-157593977

Kunlun-Zhu commented 9 years ago

可以了,多谢

------------------ 原始邮件 ------------------ 发件人: "Icenowy Zheng";notifications@github.com; 发送时间: 2015年11月18日(星期三) 中午11:30 收件人: "wujr5/c-and-cpp-language-learning"c-and-cpp-language-learning@noreply.github.com; 抄送: "klz"516455665@qq.com; 主题: Re: [c-and-cpp-language-learning] 计科:week7 第五次实验报告 (#25)

这么老的版本不行哒~(其实可以,但是。。。)装个最新版吧

— Reply to this email directly or view it on GitHub.

Kunlun-Zhu commented 9 years ago

option 1: Github Discussion

Comment at this issue and describe a problem that you meet and how you solve it detailedly. 今天使用DEV C++编译程序,设置断点后程序没有在断点处停止,结果搜索,解决方案如下: 1 打开DEV C++后,打开一个项目,点击菜单中的“project”-->"project options",选择“compiler”-->"link",选择“generate debugging information”,将其置为 “YES” 2 设置断点,在需要设置的那行前面双击,则那一行显示为红色,表明断点设置成功。 3 编译后,按F8,程序运行到断点处停止,并且该行变成绿色,然后按照软件下端列的功能自行选择就可以了。 心得:可能是因为第一步没有设置,所以开始一直设置断点都没用。 1、在“工具”-》编译选项-》"Add following commands when calling complier"下面的编辑框里加上:-g3 2、在下面的"Add these commands to the linker command line" 下的编辑框上加上:-g3

3、转到programs页,把gcc行修改为:gcc.exe -DDEBUG 4、把g++行修改为g++.exe -DDEBUG ,点击ok。 重新编译,就能调试了。

Icenowy commented 9 years ago

不需要加-DDEBUG,而且在programs里面加编译参数是一种很坏的习惯,应该加在参数应该在的地方 (就是Add following commands when calling complier)

Date: Thu, 19 Nov 2015 04:49:14 -0800 From: notifications@github.com To: c-and-cpp-language-learning@noreply.github.com CC: icenowy@outlook.com Subject: Re: [c-and-cpp-language-learning] 计科:week7 第五次实验报告 (#25)

option 1: Github Discussion

Comment at this issue and describe a problem that you meet and how you solve it detailedly.

今天使用DEV C++编译程序,设置断点后程序没有在断点处停止,结果搜索,解决方案如下:

1 打开DEV C++后,打开一个项目,点击菜单中的“project”-->"project options",选择“compiler”-->"link",选择“generate debugging information”,将其置为 “YES”

2 设置断点,在需要设置的那行前面双击,则那一行显示为红色,表明断点设置成功。

3 编译后,按F8,程序运行到断点处停止,并且该行变成绿色,然后按照软件下端列的功能自行选择就可以了。

心得:可能是因为第一步没有设置,所以开始一直设置断点都没用。

1、在“工具”-》编译选项-》"Add following commands when calling complier"下面的编辑框里加上:-g3

2、在下面的"Add these commands to the linker command line" 下的编辑框上加上:-g3

3、转到programs页,把gcc行修改为:gcc.exe -DDEBUG

4、把g++行修改为g++.exe -DDEBUG ,点击ok。

重新编译,就能调试了。

― Reply to this email directly or view it on GitHub.

Tonystark64 commented 9 years ago

是要求三种排序方法的程序都是和样本的输入输出一样吗?

linzhk commented 9 years ago

(!input.eof())是什么意思呢??

zzz0906 commented 9 years ago

为什么我的命令行编译文件input与output以后会出来一个叫做:gmon.out的东西 解决方法:百度 随着我们调试会发现一个叫gmon的文件 这是:    这个文件是进行性能分析时用的。结合 gprof 使用,会告诉你函数表调用的次数,各函数执行的时间等等。     解决方案:工具→编译选项→代码生成/优化→代码性能→生成代码性能信息选No→确定

shyuZzz commented 9 years ago

使用dev编写程序时,进行Google style的检查总会出现Tab found; better to use spaces [whitespace/tab] 后来经过思考才发现原来dev中默认使用了Tab做为标签,我们可以在编译器环境中来进行设置。

shyuZzz commented 9 years ago

学习插入排序:插入排序将已排序部分定义在左端,将未排序部分元的第一个元素插入到已排序部分合适的位置。每次处理就是将无序数列的第一个元素与有序数列的元素从后往前逐个进行比较,找出插入位置,将该元素插入到有序数列的合适位置中)

yyh15337003 commented 8 years ago

在后面的插入排序上面遇到了很多的问题,但是都解决了,主要是先了解这个排序的大概内容和步骤,然后写出算法和为代码,然后再一步步的通过断点调试来一步步的发现上面测试程序的错误,然后再改正,最后变成正确的程序。