Let us learn C in Code <10> flowchart

本文详细介绍了流程图作为编程工具的使用方法,包括基本符号、操作与决策表示,以及如何通过流程图设计和展示代码。同时,讨论了流程图与伪代码的区别,并强调了流程图在编程设计中的优势。
Flowchart which is a types of diagram in programming uses simple geometric symbols and arrows to define relationships among the difference sections ,represent an algorithm or data processing.  The flowcharts really like an instruments, anyone can fulfill a process step by step as the flowchart showing, but firstly, make sure the flowchart is correct.

These geometric symbols as the schematic shows below. The flowchart provides us with some reference points when dealing with  a process.


Drawing this schematic costs me so much time and energy. I should have a rest. This chapter will go on, lately i will take some examples  to practice the flowchart then code depend on the flowcharts.

Ok, let's go on the flowchart article, we have introduce the pseudocode in the previous chapter. Sometime both of the methods are very well for designing or showing the code.If you want to me explain what's the difference? I'm sorry i don't know. That really depends. Some gays like us pseudocode, some like using the flowchart, other maybe have more better method to design a program. Surely, the folks just code in mind without anything depends. But for me , i like us the flowchart to design my program. The most important issues, the flowchart is visible, logical and is easy to understand, so i really advice you to use the flowchart to design your program.

Now let us analysis some situation as below, then use the flowchart to detail these processes.

0) Please detail what have you done from morning till now. 


This schematic shows some basic geometric symbols to use in a flowchart, we can see thatONE,the arrow join the difference pars together, and the arrow is the direction, like the liquid flows higher to lower naturally, you can not reverse .So the arrow in the program like the sentences being executed  step by step.TWO,the  diamond represents a decision , and the YES or NO just a boolean value, this boolean illustrates whether the sentence is TRUE or not(FALSE),when we meet the diamond we can use the if... or  if...else...  or if..elseif...else.. to represent, lately we know there are some other keyword can be used to represent this decision(diamond) like switch.Then relaying on the boolean value to decide where to jump  .THREE , the rectangle used to illustrate an operation ,action or a process, you can fulfill a calculation or a algorithm or a procession.FOUR, oval just marks the starting or ending point of the program, most time it contains "start" or "end" word. 

Here we just list some important issues ,you can refer to the codes listed previous chapters.Here, let introduce a new conception called comment , the comment is programmer readable annotations in our source code .In C code, there are two ways to write the comments in our program.

Time limited, next time let us go on this chapter, we will code depends on the flowchart above, then add some comments in our code.

Have a nice day !

你遇到的情况是由于你使用的 `changeObjectToXml` 函数在处理数组时,会递归地遍历数组中的每个元素。但问题在于:**它将字符串当作数组来处理了**。 --- ### 你的输入对象是: ```typescript const obj = { bmidConditionSet: ['1000', '19688CD852603000'] }; ``` 其中 `bmidConditionSet` 是一个数组,数组中的每个元素是一个字符串(如 `'1000'`)。 --- ### 原函数的处理逻辑: ```ts for (var subObjKey in obj[key]) { resultString = resultString + Object2Xml.changeObjectToXml(obj[key][subObjKey]); } ``` 这里用了 `for...in` 遍历数组,这在 JavaScript/TypeScript 中是不推荐的,因为 `for...in` 实际上是遍历对象的键(包括数组索引,但也会遍历其他可枚举属性)。 **更严重的问题是:当处理字符串时,`for...in` 会把字符串当作类数组对象处理,遍历的是字符索引。** 例如: ```js for (let i in "1000") { console.log(i, "1000"[i]); } ``` 输出: ``` 0 "1" 1 "0" 2 "0" 3 "0" ``` 所以函数会把字符串 `'1000'` 拆分成一个个字符,然后递归调用 `changeObjectToXml`,将每个字符作为独立节点输出。 --- ### 所以你看到的输出是这样的: ```xml <bmidConditionSet> <0>1</0> <1>0</1> <2>0</2> <3>0</3> <0>1</0> <1>9</1> <2>6</2> ... </bmidConditionSet> ``` 这是函数错误地把字符串当作数组处理,将每个字符作为数组元素来生成 XML。 --- ### 正确的输出应该是: ```xml <bmidConditionSet> <item>1000</item> <item>19688CD852603000</item> </bmidConditionSet> ``` --- ### ✅ 正确的修复方法 你需要在函数中区分 **数组** 和 **字符串**,确保字符串不会被当作数组处理。 --- ### ✅ 修复后的代码如下: ```ts static changeObjectToXml(obj: any): string { let resultString = ''; if (Array.isArray(obj)) { // 如果是数组,则统一用 <item> 标签包裹每个元素 for (let i = 0; i < obj.length; i++) { resultString += `<item>${obj[i]}</item>`; } } else if (typeof obj === 'object' && obj !== null) { // 如果是对象 for (let key in obj) { if (obj.hasOwnProperty(key)) { const value = obj[key]; resultString += `<${key}>`; if (Array.isArray(value)) { for (let i = 0; i < value.length; i++) { resultString += `<item>${value[i]}</item>`; } } else if (typeof value === 'object' && value !== null) { resultString += Object2Xml.changeObjectToXml(value); } else { resultString += value != null ? String(value) : ''; } resultString += `</${key}>`; } } } else { // 基本类型直接输出 resultString += obj; } return resultString; } ``` --- ### ✅ 修复后的输出 输入: ```ts const obj = { bmidConditionSet: ['1000', '19688CD852603000'] }; ``` 输出: ```xml <bmidConditionSet> <item>1000</item> <item>19688CD852603000</item> </bmidConditionSet> ``` --- ###
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值