如何将伪代码转换为源代码? [英] How can I convert a pseudo code into source code ?

查看:1414
本文介绍了如何将伪代码转换为源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Input: S= set of cameras; T = set of targets; P= set of discrete
pans; K= No. of set covers
Output: C=Collection of Set Covers C1, C2....CK
1: SENSORS= S
2: /*SENSORS keeps track of the list of unused sensors */
3: k = 0
4: while SENSORS 6= ∅ do
5: /* a new set cover Ck will be formed */
6: k= k + 1
7: Ck=∅
8: TARGETS= T
9: /*TARGETS contains the uncovered targets */
10: while TARGETS 6= ∅ do
11: /* more targets have to be covered */
12: Find Dmin = minD(t) : t ∈ T
13: if |Dmin| = 0 then
14: /*TARGETS contains some uncoverable targets*/
15: goto marker
16: else
17: S′ = ∅
18: Find the targets having cardinality equals Dmin
and create a set T ′
19: for each t ∈ T ′
20: for each (si, pj) ∈ −1(t)
21: S′ = S′ ∪ {(si, pj)}
22: Find the most contributing (su, pv) such that:
23: (su, pv)←argmaxsu∈S’,1≤v≤quv∩TARGETS
24: /* selects (su, pv) covering maximum targets */
25: In case of tie, create a subset S′′ ⊆ S′ with
all sensor-pan pairs having same contribution
26: Let (si, pj) ∈ S′′ has the maximum force F′
ij
among all sensor-pan pairs in S′′, i.e.:
27: F′
ij = argmaxvFuv; ∀su ∈ S; ∀pv ∈ P;
∀si ∈ S; ∀pj ∈ P;
28: Ck = Ck ∪{(si, pj)}
29: SENSORS = SENSORS \ {si}
30: TARGETS = TARGETS \ {ij}
31: end if
32: end while
33: C = C ∪ Ck
34: end while
35: marker: return the collection of set covers C





我的尝试:



需要帮助才能理解如何将此算法转换为c ++



What I have tried:

need help to understand how to convert this algorithm into c++

推荐答案

1。编写一个C ++主函数

2.定义一个C ++函数来实现你的伪代码:你需要决定需要传递给这个函数的值,以及什么是所需的输出

3.在main函数中创建或构造函数的输入(仅作为测试代码的示例)

4.实现函数:分析伪代码中的每个语句并将它们转换为C ++语句;不要忘记正确定义伪代码语句中引入的任何变量。

5.根据需要测试并更正代码;如果遇到一个你不知道如何解决的特定的问题,请回到这里并询问
1. write a C++ main function
2. define a C++ function to implement your pseudo code: you need to decide what values need to passed to this function, and what is the desired output
3. create or construct the inputs to your function in the main function (just as an example to be able to test your code)
4. Implement the function: Analyze each statement in your pseudo code and translate them into C++ statements; don't forget to properly define any variables introduced in a pseudo code statement.
5. test and correct your code as needed; if you run into a specific problem that you don't know how to solve, come back here and ask


实现任何新项目的方式:



1)研究伪代码并提取算法。

2)设计代码(最好不要使用goto)来实现算法。 br />
3)对设计进行编码。

4)测试代码。

在任何时候,根据需要返回到早期阶段直到它工作。
The way you implement any new project:

1) Study the pseudo code and extract the algorithm.
2) Design the code (preferably eliminating the goto's) to implement the algorithm.
3) Code the design.
4) Test the code.
At any point, go back to an earlier stage as necessary until it works.


Quote:

如何将伪代码转换为源代码?

How can I convert a pseudo code into source code ?



伪代码是您的老师用来描述程序如何工作的惯例,它不是特定于编程语言,而是与其相关的域特定。

重读关于伪代码和C ++的课程。



这段代码是一个函数:

- 生成C ++骨架。

- 粘贴伪代码空函数骨架。

- 使每一行成为注释。

- 在每行伪代码之后,添加与伪代码匹配的C ++代码。



如果您有具体问题,请说明您的所作所为。


Pseudo code is a convention used by your teacher to describe how the program would work, it is not specific to a programming language, it is rather specific to the domain it is related to.
Reread your courses about pseudo code and C++.

This code is a function:
- make C++ skeleton.
- paste pseudo code in empty function skeleton.
- make each line a comment.
- after each line of pseudo code, add the C++ code that match the pseudo code.

If you have specific question, show what you have done.


这篇关于如何将伪代码转换为源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆