wujr5 / c-and-cpp-language-learning

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

计科:week6 第四次实验 程序流程图和伪代码 #18

Open wujr5 opened 8 years ago

wujr5 commented 8 years ago

week6 第四次实验 程序流程图和伪代码

实验目的:当大家学习了程序的控制结构之后,代码就变得复杂起来。在这时,我们解决问题就需要有很严密的逻辑思维。程序流程图和伪代码就是帮助我们去描述我们解决问题的方法(也称为算法)的工具。本次实验在于让大家学习如何使用这些工具,这对大家以后的编程有很大的帮助。

1 Flowchart (程序流程图)

A flowchart is a type of diagram that represents an algorithm, workflow or process, showing the steps as boxes of various kinds, and their order by connecting them with arrows. This diagrammatic representation illustrates a solution model to a given problem. Flowcharts are used in analyzing, designing, documenting or managing a process or program in various fields.

From wikipedia

Detailed Description: flowchat

There is an example:

ab

And this is the flowchart:

sample

2 Pseudocode (伪代码)

Pseudocode is an informal high-level description of the operating principle of a computer program or other algorithm.

From wikipedia

There is an example:

1

We can describe this question by this way rather than write a C++ program immediately:

main {
    input two integers height and n
    initialize answer = 0

    loop for n times {
        input tree_height
        if height >= tree_height:
            answer = answer + 1
    }

    print answer
}

Pseudocode is used to express your thought, you do not need to care about the grammar.

3 Pre Assignment

Learn about Flowchart and Pseudocode.

4 Assignment (100pts)

4.1 Assignment 0 (20pts)

Choose one question from soj.me in week6 in our course and then write the Pseudocode.

4.2 Assignment 1 (35pts)

Translate the following flowchart into Pseudocode

Description

Several surveys indicate that the taller you are, the higher you can climb the corporate ladder. At TALL Enterprises Inc. this "de facto standard" has been properly formalized: your boss is always at least as tall as you are. Furthermore, you can safely assume that your boss earns a bit more than you do. In fact, you can be absolutely sure that your immediate boss is the person who earns the least among all the employees that earn more than you and are at least as tall as you are. Furthermore, if you are the immediate boss of someone, that person is your subordinate, and all his subordinates are your subordinates as well. If you are nobody's boss, then you have no subordinates. As simple as these rules are, many people working for TALL are unsure of to whom they should be turning in their weekly progress report and how many subordinates they have. Write a program that will help in determining for any employee who the immediate boss of that employee is and how many subordinates they have. Quality Assurance at TALL have devised a series of tests to ensure that your program is correct. These test are described below.

May be you can not write out the problem, the only work you will do is write out this program from the following flowchart(Since there are many methods to sort, so you can use one of them, the flowchart does not display in the flow chat, instead a dashed line).

Flowchart

flowchart 2

Simple input and output

Input

2
3
123456 14323 1700000
123458 41412 1900000
123457 15221 1800000
123458
4
200002 12234 1832001
200003 15002 1745201
200004 18745 1883410
200001 24834 1921313
200002

Output

(0,2)
(200004,0)

4.3 Assignment 2 (35pts)

Draw a flowchart from the following C++ language program which constructs a bubble sort algorithm.

#include <iostream>
using namespace std;

void print(int* pData, int count) {
    for (int i = 0; i< count; i++) {
        cout << pData[i] << " ";
    }
    cout << endl;
}

void BubbleSort(int* pData, int count) {
    int temp;
    for (int i = 1; i < count; i++) {
        bool flag = true;

        for (int j = 0; j < count - i; j++) {
            if (pData[j] > pData[j+1]) {
                temp = pData[j+1];
                pData[j+1] = pData[j];
                pData[j] = temp;
                flag = false;
            }
        }

        if (flag) break;

        cout << "The "<< i <<" round:" << endl;
        print(pData, count);
        cout << "----------------------------" << endl;

    }
}

int main() {
    int n;
    int data[100];

    cout << "How many numbers you want to input ? (less than 100)" << endl;
    cin >> n;
    cout << "Please input " << n << "numbers, separating with space: " << endl;

    for (int i = 0; i < n; i++) {
        cin >> data[i];
    }

    BubbleSort(data, n);

    cout << "The sort result:" << endl;

    print(data, n);

    return 0;
}

5 Extended Assignment (10pts)

Draw a flowchart and write Pseudocode as well as a C++ language program for the following description.

extend

6 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 decribe a problem that you meet and how you solve 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.

    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.
  3. First come, first get the opportunity.

    option 3: Helping others

You can help others to slove any problems the will meet. Detailedly decribe the quesion, the solution and your personal experience as well.

Notice that

  1. it's 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.

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

    7 Report Template

There will be no Report Template this time which means it's all depends on yourself.

Notice that

  1. the report is the most important document for your project, you should pay more attention to it.
  2. you are supposed to write a report that is friendly to your 'users', which means that you need to consider about the typesetting, the logical structure of the content.
  3. There should contain one item, self grading that you should give a score to evaluate your job as well as a reason.

For example: sinew

8 Flowchart Tool: Process On

Process on is a good tool for drawing flowchart. link

9 Submit List

2

Notice that: 13331314 means your student id. the first assignment need to name your file with your chosen problem id.

10 Deadline

23:59 on Nov 12th, 2015

11 Notification

  1. Submit after deadline will cause a 30% penalty.
  2. If your file structure of filename is wrong, you will probably get 0 in that part.
  3. Any questions, you can ask us and email is better.
  4. Full mark will be 100, but you may get more than 100 within this project.
  5. You can use any tool include word, process on to draw a flowchart. You can use any form to write your Pseudocode but should be of high readability. If TA can not understand your Pseudocode clearly, you will get low points.(you can use Chinese to write Pseudocode if you like).
MattMu commented 8 years ago

师兄,怎样制作流程图,用word?

ghostbody commented 8 years ago

@MattMu 仔细看要求,里面有

linzhk commented 8 years ago

作业5的数据范围是什么东西?

Kunlun-Zhu commented 8 years ago

流程图是用手画吗,还是用软件制作

Kunlun-Zhu commented 8 years ago

没有soj.me这个网站呀

Kunlun-Zhu commented 8 years ago

week6是2041 loop
2040 Strings 吧

Icenowy commented 8 years ago

soj.me是西西里旧域名吧

---- yyh15336264编写 ----

没有soj.me这个网站呀


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

Kunlun-Zhu commented 8 years ago

伪代码要用google style吗

yonglc commented 8 years ago

请问那个代码风格检测的网站在哪里有啊?

wujr5 commented 8 years ago

soj是sicily,如何画流程图上面有写工具,伪代码没有固定格式。大家仔细看作业要求,都是作业里面有详细说明的。

wujr5 commented 8 years ago

在线检测调试中,建议大家用cpplint

no553216989 commented 8 years ago

我有一个流程图用的work打的。。没有问题吧

wujr5 commented 8 years ago

可以,不过建议使用推荐的工具

no553216989 commented 8 years ago

实验报告可以是DOC格式吗

wujr5 commented 8 years ago

看要求!pdf

StealMyGirl commented 8 years ago

69 1 9 2b72qwzjiqs 1 w 师兄这个错误是什么意思?

wujr5 commented 8 years ago

这个可以忽略不管

Kunlun-Zhu commented 8 years ago

option 1: Github Discussion Comment at this issue and decribe a problem that you meet and how you solve detailedly 不知道怎么判断一个数a是否是回文数 百度了一下,有思考了良久 发现只要再定义两个数b=a,c=b%10 并循环使b=b/10,c=c*10+b%10,直到b=0 在判断c==a是否成立,若成立则为回文数

SgLy commented 8 years ago

@yyh15336264 可以考虑把数字当做字符串读入和处理,一是操作方便,二是不受长度限制

Tonystark64 commented 8 years ago

师兄file structure of filename is wrong到底是什么意思?是指打包提交文件的什么?

wujr5 commented 8 years ago

@Tonystark64 就是要根据这个图来安排你的文件和文件名: image

iceinJune commented 8 years ago

请问一下,下面我写的应该属于伪代码吧

BEGAIN 输入 两个正整数 x,y
定义 正整数i(1,2...) 临时变量temp

无限循环,直到i<x或者i<y为止 (if x%i=0 && y%i=0
把i的值赋予 temp ) ,

输出temp

OVER

wujr5 commented 8 years ago

太长了,可以更简洁些

Tonystark64 commented 8 years ago

Assignment1有要求写c++代码吗?怎么要提交Source.c?

Lin-Frontend commented 8 years ago

@wujr5 我在代码里用了goto,可以么?

SgLy commented 8 years ago

@wujr5 Extra Option 2里面

Have a simple presentation in the lab class on Monday...

我们的课是星期五的吧…… 然后关于这个presentation,应该如何报名?准备的内容关于什么?是否有其他的要求?

Tonystark64 commented 8 years ago

回文素数那个,伪代码要写具体的素数及回文数的判断方式吗?

wujr5 commented 8 years ago

@SgLy 改过来了。报名的话直接私聊我,内容自己决定。要求就是上面的要求。

wujr5 commented 8 years ago

@Tonystark64 要写具体判断方式

MattMu commented 8 years ago

一种int转化为string的方法 qq 20151111211055 qq 20151111211126

使用string对象来代替字符数组。这样可以避免缓冲区溢出的危险。
Tonystark64 commented 8 years ago

Assignment2冒泡排序可以用自己的算法制流程图或伪代码吗?表示那个有些看不懂

wujr5 commented 8 years ago

@Tonystark64 需要使用给出的代码。

wujr5 commented 8 years ago

@MattMu 这方法不错。建议详细讲一下,让同学们都了解一下。放在 课程分享那里

Tonystark64 commented 8 years ago

print(pData, count)和print(pData, count)怎么区分?

wujr5 commented 8 years ago

@Tonystark64 不明白你的问题?

Tonystark64 commented 8 years ago

我没有看到count有赋值?还有就是---------上面那行print(pData,count)指什么?

wujr5 commented 8 years ago

@Tonystark64 这是一个函数调用

iceinJune commented 8 years ago

伪代码可以用Word来写吗,我想用不同的颜色标记变量可以吗(我感觉这样更直观,更具有可读性)?还有,必须按照《算法导论》来写伪代码吗?让人更快更好读懂算法就可以吧!

wujr5 commented 8 years ago

@iceinJune 可以。

zzz0906 commented 8 years ago

你们好厉害 伪代码不是只要是伪的就可以吗 可以用易语言的伪代码风格吗

wujr5 commented 8 years ago

@zzz0906 仔细阅读以下伪代码的定义。其实是能表明程序逻辑就可以了,没有规定的语法。

EtherCS commented 8 years ago

判断回文数时,我开始的思想是通过判断左右对称位置的数是否全部相等来判断是否是回文数 if (n/(pow(10,sum)) == n%10) { m = pow(10,sum); n = n % m; n = n / 10; 后面发现如果要判断的数如果有“0”(例如30203),这个方法就行不通,最终找到了一种简便的方法: m *= 10; m += n % 10; n = n / 10; 即将待判断的数“n”倒过来写(最终写成上面代码的“m”),然后在判断m与n是否相等,最后得出结论

wujr5 commented 8 years ago

@yyh15336242 参考相关Markdown语法,改一下你的评论吧。

zhuzq5 commented 8 years ago

那个 assignment 1 需要提交source么 题目上要求只要伪代码 提交格式上看到要交source?

wujr5 commented 8 years ago

@zhuzq5 不需要source,伪代码就可以了。

yonglc commented 8 years ago

20:48:12 卷柏 2015/11/12 20:48:12 main(){ 构造函数 print (int*pData, int count){ for i <- 0 to count by i++{ cout << pData[i] << " " ; } cout << endl ; }

构造函数 Bubblesort (int *pData, int count){
    for i <- 1 to cout by i ++ {
        bool flag <-ture ;
        for j <-0 to count-1 by j ++{
            if pData[j] > pData[j+1]
            then pData[j] <-> pData[j+1] ;
            flag = flase ;
        }
        if flag = flase 
        then cout << "The" << i << "round" << endl ;
        then 调用函数 print(pData, count);
        cout << "----------------------------" << endl ; 
} 

cin >> n ;
cout << "How many numbers you want to input ? (less than 100)" << endl;
cout << "Please input " << n << "numbers, separating with space: " << endl;
for i <-0 to n by i ++ {
cin >> data[i];
}
调用函数 Bubblesort(data, n);
cout << "The sort result:" << endl ; 
调用函数 print(data, n) ;
return 0 ; 

}

卷柏 2015/11/12 20:48:38 Ta请问一下伪代码可以写成这样吗?

卷柏 2015/11/12 20:48:43 打扰一下

zhuzq5 commented 8 years ago

@wujr5 assignment 2要写伪代码么 题目上并没有哎

wujr5 commented 8 years ago

@yonglc 不能这样写。这样只是稍微修改一下源程序而已

yonglc commented 8 years ago

那伪代码有什么要求吗。。。这样感觉写伪代码好麻烦啊。。。基本构思的时候就是按源代码想的啊