In: Computer Science
An alien spaceship has landed in your backyard full of various
types of aliens. They all are saying “I come in peace”,
but you’re not so sure. You consult your
trusty guide to alien encounters to find out
that that there are three criteria that
determine if an alien is telling the truth:
number of heads, type of weapon and
intensity of their eyes.
Friendly features: squirt gun as weapon
Unfriendly features: weapon (as long as it’s
not a squirt gun), beady eyes, more than two
heads
Don’t ask about the type of weapon if you know the alien does
not have a weapon
If an alien has two or more unfriendly features he is
unfriendly
o So beady eyes, three heads, but no weapon & the alien is an
enemy
o So squirt gun, regardless of other features, the alien is
friendly
Pseudocode (10 points)
Create the document in using Microsoft Office Word or Power Point
or the Open Office equivalent, as
long as I am able to open it.
Start with a pseudocode. Write the pseudocode in English, step by
step what you need to do to solve the
problem. There are many ways this can be done. Take your time and
think about it.
No flowchart is required, but you can certainly draw one if it
helps you.
put your name, date, section, and description of the program at
the top of the page.
save the file lastname_ch3AlienPseudocode
The program will perform the below checks in order to solve the problem.
The complete Pseudocode to solve the problem is given as below along with the detailed explanation in next section:
----------------------------------------------------------------------------------------------------
START:
Set : enemyfeature = 0 //Set the unfriendly feature to 0 in starting of the program.
IF: Alien has weapon // check if the alien is having weapon
Then: Check the weapon type //If weapon is available, check the weapon type
If weapon is other than Squirt Gun, set enemyfeature = 1;
Else: It does not have enemy weapon
ENDIF;
IF: Alien has beady eyes:
Then: Increase the emeyfeature counter
Else IF: Alien has more than two heads:
Then: Increate the enemyfeature counter
Else:
Keep the enemyfeature value same.
ENDIF;
//Let’s check the final feature count for alien and get the result
IF: enemyfeature counter >= 2 //if 2 or more enemy features are true
Then: Alien is an enemy.
Else: Alien is friendly.
ENDIF
END Program
----------------------------------------------------------------------------------------------------
Explanation of pseudocode for a better understanding:
The Pseudocode is explained in 4 steps
Set : enemyfeature = 0
IF: Alien has weapon // check if the alien is having weapon
Then: Check the weapon type //If weapon is available, check the weapon type
If weapon is other than Squirt Gun, set enemyfeature = 1;
Else: It does not have enemy weapon
ENDIF;
IF: Alien has beady eyes:
Then: Increase the emeyfeature counter
Else IF: Alien has more than two heads:
Then: Increate the enemyfeature counter
Else:
Keep the enemyfeature value same.
ENDIF;
IF: enemyfeature counter >= 2 //if 2 or more enemy features are true
Then: Alien is an enemy.
Else: Alien is friendly.
ENDIF
----------------------------------------------------------------------------------------
Please let me know if more clarification is required.