ADM-201 dump PMP dumps pdf SSCP exam materials CBAP exam sample questions

《卷轴教程之C++入门》#9 条件语句一 – 译学馆
未登陆,请登陆后再发表信息
最新评论 (0)
播放视频

《卷轴教程之C++入门》#9 条件语句一

Using Conditional Statements in C++ Part 1

好了 现在我们看一下下个程序的问题说明
Ok, so let’s take a look at our problem statement for our next program.
在这个特定的问题中 我们会看到一些虚拟的植物学
And in this particular problem statement, we’re gonna see some fictitious botany,
所以不要把这当成字面意思来理解
so don’t take any of this as being literal.
我们要做的事情之一是阅读这个问题说明
And one of the things that we want to do is we read through this problem statement,
分析这篇说明并且找出可能的输入是什么
just try to analyze it and find out maybe what our inputs are gonna be,
可能有什么样的条件
what sort of conditions we may have,
以及我们有兴趣产生什么样的输出
and then what sort of output we’re interested in producing.
文中说有一颗红色的种子 并且我们知道这颗红色种子会长成一朵花
So we have here a red seed and we’re told that this red seed will grow into a flower,
那么 让我把“红色种子”用荧光笔标记上
so let me go ahead and mark that we’re talking about ‘red seed’ here with a little highlighter…
种在温度在75度以上的土壤中时 种子会长成一朵花
So, it’ll grow into a flower when planted in soil temperatures above 75 degrees, so…
所以必须在75度以上才能长成花
we got to be above 75 to get a flower,
否则它会长成蘑菇
otherwise it will grow into a mushroom.
所以 “否则会长成蘑菇”
So we say, “otherwise we get a mushroom” here.
假设温度符合长成花的条件
Assuming the temperature meets the conditions for growing a flower,
把种子种在湿润的土壤中 所以说如果把种子种在湿润的土壤中
planting the red seed in wet soil, so if we plant it in wet soil,
它会变成向日葵
it will produce a sunflower,
把红色种子种在干燥的土壤中
and planting the seed, red seed, in dry soil,
标记上“干燥土壤”
so we mark this “dry soil”,
它会变成蒲公英
it’s gonna produce dandelion.
这就是第一段的主要信息
So that’s really the main pieces of information there from the first paragraph,
被标记出来的是非常重要的
and being able to pick that out is fairly important.
好了 下面我们看一下蓝色种子
All right, so the next thing we’re looking at is a blue seed,
现在我们就有了红色种子还是蓝色种子的选择
so we got this choice between a red seed and a blue seed,
种在温度为60~70度的土壤中时 蓝色种子会长成花
and it will grow into a flower when planted in soil temperatures that range between 60 and 70,
否则它就会变成蘑菇
and then otherwise it’s also gonna grow into a mushroom.
所以说如果温度不是60~70度 它就会长成蘑菇
So if it’s not planted between 60 and 70 it’s gonna grow into a mushroom,
就和红色种子种在75度温度以下时一样
just like our red seed did for temperatures that were below 75 degrees.
假设温度符合长成花的情况
So assuming that the temperature meets the conditions for growing a flower,
把蓝色种子种在湿润的土壤中 它会变成一朵蒲公英
planting the blue seed in wet soil, so in wet soil, it will produce a dandelion,
种在干燥的土壤中 它会变成向日葵
and planting the blue seed in dry soil will produce a sunflower,
基本上和之前红色种子相反
so basically the opposite of what we had before.
接下来要做什么呢? 我们要写一个程序接收用户的输入
So what do we have to do? We gotta write a program that will ask the user to input
用户需要输入种子颜色以及土壤温度
the seed color, and then they have to input the soil temperature,
最后要输入土壤是湿润还是干燥 也就是土壤湿度
and then finally they will input whether the soil is wet or dry, so basically, the soil moisture,
程序需要输出种子会长成什么
and then it need to output what will it grow,
它会长成蘑菇 蒲公英还是向日葵?
so is it gonna grow a mushroom, is it gonna grow a dandelion, or is it gonna grow a sunflower,
基本上我们有这3个选择
that’s basically the three choices we have.
我们已经读了问题说明 并且在一定程度上分析了它
So, we’ve read our problem statement, we’ve analyzed that to a certain degree
我们知道了输入和基本条件
we realize what our inputs are, we know the basic conditions that we have,
也知道了在给定条件下 种子会长成什么
and we also know under what conditions, what will actually grow.
接下来我们打开Eclipse
So let’s go ahead and go over to Eclipse,
开始写一下伪代码
and start writing up some pseudocode for this.
好了 看起来我们已经准备好去写“问题4”的伪代码了
All right, so it looks like we’re ready to start doing some pseudocode here for ‘Program4’.
我已经创建了“问题4”的项目文件夹
So I’ve already created the ‘Program4’ project folder,
也在里面创建了“问题4”的源文件
and also created the ‘Program4’ source file within that project folder.
这是问题说明 我只是把它复制进来
Here we are with the problem statement, so I just copied this in,
所以我们可以在写代码的时候引用它
so we can reference it as we write our pseudocode.
如果你需要返回到问题1 2或3
If you need to go back to Program1, 2, or 3,
或者是其他问题 我会演示如何创建项目文件夹
and any of those, I’ll show you how to create a project folder,
以及如何在Eclipse中把源文件包含进来
and also how to include a source file in Eclipse.
我们看一下如何写伪代码
Ok, so let’s take a look at writing the pseudocode.
伪代码中我们要考虑的第一件事是
So the first thing that we need to think about for pseudocode is,
我们要接受用户的什么输入
what input we need to get from the user.
我们要接收来自用户的三部分信息
So there’s really three pieces of information that we need to get from the user,
第一部分是种子颜色
one’s the seed color,
第二部分是土壤温度
two is the temperature of the soil,
第三部分是土壤湿度 即湿润还是干燥
and three is the moisture of the soil, so is it wet or is it dry.
我可能会只写“接收种子颜色”来表示
So I might just indicate this by doing ‘Get seed color’,
然后是“接收温度”
and then we need to ‘Get temperature’,
最后是“接收土壤湿度”
and then finally we need to ‘Get the soil moisture’.
土壤湿度
right. the soil moisture.
一旦有了这三部分数据
So once we have those three pieces of data,
我们就能真正做一些决策了
then we can actually make some decisions.
根据种子颜色 我们会执行一系列的动作
So based off the seed color we’ll do one set of actions,
根据土壤温度 我们会执行另外一些动作
based off of the temperature we’ll do something else,
根据土壤是湿润还是干燥
and then based off of the, whether the soil is moist or wet or dry,
我们会执行另外一些动作
then we’ll do some other set of actions.
首先看一下 如果有一颗红色种子
So the first thing we need to look at, is if we have a red seed,
如果是红色种子 我们会执行一些动作
so ‘if red seed’, we’ll do some set of actions.
如果是蓝色种子 我们会执行另外一些动作
‘if blue seed’, we’ll do some other set of actions.
把光标定位在‘如果是红色种子“下面 按Tab键缩进
So I’m gonna come in here and tab over below this ‘if red seed’,
这就是说:如果我们有一颗红色种子
so this is saying that “if it turns out that we have a red seed,
我们要执行这些动作 这就是我在这缩进的原因
let’s do these set of actions”, so that’s why I tabbed over here, you see,
这里的伪代码和那些执行的动作是相关联的
so I’m associating this set of pseudocode with that action.
现在我们可以看一下……
All right, so now we can look at… what,
回到这 可以看到 如果土壤温度在75度以上
well, if we come back up here we see that if the soil temperature is above 75 degrees,
我们会得到一些花
and then we’ll get some sort of flower;
否则会得到蘑菇
and then if it’s not, then we’ll get a mushroom.
所以我们可以说”如果温度大于等于75度”
So we can say ‘if temperature is greater than or equal to 75’,
我们要做一些列的行动
we’ll do one set of things, and ‘Otherwise’,
否则我们会得到蘑菇 我就只写“输出蘑菇”
we’ll get a mushroom, so I’ll just say ‘Output mushroom’.
如果实际上温度大于等于75度
Ok, so if the temperature is in fact greater than or equal to 75,
我们有两个选择
we have two alternatives there:
一个是结果为向日葵 另一个是结果为蒲公英
one, results in a sunflower, and the other, results in a dandelion.
“如果土壤湿润”
So, ‘If the soil is wet’,
就写“输出蒲公英”
we’ll want to ‘Output dandelion’.
“如果土壤干燥”
‘If the soil is dry’,
结果是……
then we’ll result in a……
事实上我需要回到前面
so actually I have it exactly backwards.
我确认一下这对不对 哦 这写错了
Let me make sure I get this right, so that was a mistake,
这应该是“向日葵”
so that should be ‘sunflower’ there.
这里应该是“蒲公英”
And this should be ‘dandelion’ down here.
所以“如果土壤湿润” “输出向日葵”
Ok, so ‘If the soil is wet’, ‘Output sunflower’,
所以“如果土壤干燥“ “输出蒲公英”
and ‘If the soil is dry’, ‘Output dandelion’.
你们需要让我直截了当 确保我不说错
All right, so you guys need to keep me straight here and make sure I’m not saying the wrong stuff,
这里是这么说的 在伪代码里我却写成另外的
it says one thing here and I’m trying to type out something else here for our pseudocode.
这样 在我们开始前 解决方案就被完全破坏了
Now that totally destroyed our solution before we even gets started,
这很不好
so that’s not good.
这就是关于红色种子需要做的事
All right, so that’s pretty much what’s going on with our red seed.
如果是红色种子 我们可以检查温度
So if the red seed, we can check on the temperature,
湿度以及土壤是干燥还是湿润
and then check on the moisture, whether it’s wet or dry.
如果温度不满足条件 也就是不在75度以上
If it doesn’t meet the temperature, if it’s not above 75,
不在75度及以上 我们会得到蘑菇
or at least 75 and above, then we’ll get a mushroom.
现在我们看一下是蓝色种子时会发生什么
All right, so let’s look at blue seed, and what happens.
如果是蓝色种子 回到这看一下问题说明概述
So with blue seed, if we scroll back up here and look at the problem statement briefly,
可以看到如果温度在60~70度之间 我们会得到花
we see that we get some sort of flower if the temperatures range between 60 and 70.
我们要测试一下这个条件 来到这
Ok, so we’ll test that…so I’ll come down here and say,
“如果温度在60~70度之间” 我们要做一系列行动
‘if temp is between 60 and 70’, we’ll do one set of actions.
“否则” 我们会得到什么?就像前面一样得到一个蘑菇
‘Otherwise’, if it’s not, what do we get? We get a mushroom just like before.
所以这里写“输出蘑菇”
So we want to ‘Output mushroom’.
现在我们来看如果实际温度在60~70度之间会发生什么
Ok, so let’s focus in on what happens if the temperature is in fact between 60 and 70.
回到这里 这写着:如果温度在60~70度之间
So we’re going back up here it says that if the temperature’s between 60 and 70,
也就是满足温度条件
so it meets the temperature conditions,
把蓝色种子种在湿润土壤中会变成蒲公英
then planting the blue seed in wet soil will produce a dandelion,
种在干燥土壤中会变成向日葵
and planting the blue seed in dry soil we’ll get a sunflower,
这和红色种子正好相反
so it’s exactly opposite of what we had with the red seed,
刚才红色种子的时候 我正想这样写
even though I tried to type that backwards when we were dealing with the red seed,
现在我们可以写“如果土壤湿润”
but now we can type out ‘If the soil is wet’,
我们会得到蒲公英
then we’ll get a dandelion.
有时“蒲公英”是个很难拼写的词 可能就是这样拼
‘dandelion’ is hard a word to spell sometimes. Maybe it’s just my typing.
“如果土壤干燥”
And ‘If the soil is dry’,
我们会“输出向日葵”
then we’ll output a sunflower.
基本就是这样 这就是大体上的伪代码
And that’s basically it, so this is the general pseudocode that we have here.
我们检查了种子的颜色
We have the check to see what kind of seed we have,
根据种子 检查了温度
then based off the seed, we look at the temperature,
如果温度满足变成花的条件
and then if the temperature is in the right conditions for a flower,
再查看土壤是湿润还是干燥
we look at whether the soil is wet or dry,
并且我们也正确输出了信息
and we output that information appropriately.
这就是程序的伪代码
So that is our pseudocode,
现在回到这里 我们要写一些真正的源代码了
so now, we’ll come back and start filling in some actual source code.

发表评论

译制信息
视频概述

本节课程介绍了问题四及其伪代码的编写,分析了三种不同条件。

听录译者

HX

翻译译者

[B]hugue

审核员

豆子

视频来源

https://www.youtube.com/watch?v=4XsjZshqq9Y

相关推荐