Psuedocode

User Generated

nzrre07

Writing

engineering matlab

Description

Psuedocode is the word representation of how you want to proceed with
the program.

Please refer to MODULE 5 (Selection Statements) Presentation to
understand what a pseudo code is.


I will attach both the presentation (MODULE 5) so you can see what
Psuedocode is, and i will upload the word document that describes what

Unformatted Attachment Preview

Branches, Flowcharts, and Pseudocode • ENGR 102 • West Virginia University • Statler College of Engineering & Mineral Resources Flowcharts: • Are visual representations of a sequence of steps and decisions needed to perform a process. • Can be used to map out the logic of a computer program. • Can be used to plan out your thoughts prior to coding or to share the logic of a program with someone who is unfamiliar with the syntax of the language. • Standard symbols are used in certain situations. Figure 1: Basic symbols and their functions Figure 2: Example of a flowchart for a simple thermostat on a furnace Pseudocode: • Pseudocode is an informal way to express the design of a computer program or an • • • • algorithm. Its goal is to communicate the basic idea of the computer code without including exact syntax. There is no “industry standard” or accepted method of writing pseudocode. Can think of pseudocode as writing the program out in words using shorthand, and not complete sentences. Sometimes it is a good way to show someone what you intend for a code to do or to plan out your own code before you actually start writing the code in MATLAB®. Pseudocode Example: • If you were ask to write a code in MATLAB which allowed a to input temperature and display if heat is turned on or off. Ask for user input of the room temperature Check to see if the temp is greater than or equal to 70 If greater than or equal to 70 Display “Turn off heat” If temp less than 70 Display “Turn on heat” End While the actual Code would look like. . .. Temp=('Please enter the temperature') if Temp>=70 disp(‘Turn off heat') else disp(Turn on heat’) end Pseudocode Example: • If you were ask to write a code in MATLAB which allowed a student to enter their grade as a percentage and the program would return their letter grade (A-C) the pseudocode could look like this. . . Ask for user input of their percentage grade Check to see if the grade is greater than or equal to 90 If greater than or equal to 90 Display “A” If grade is not greater than or equal to 90 check to see if it is greater than or equal to 80 If greater than or equal to 80 Display “B” If grade is not greater than or equal to 80 check to see if it is greater than or equal to 70 If greater than or equal to 70 Display “C” If none of the above are true Display “You Must Repeat The Class” End While the actual Code would look like. . .. Grade=input('Please enter the temperature') if Grade>=90 disp('A') elseif Grade >= 80 disp('B’) elseif Grade >= 70 disp('C’) else disp('You Must Repeat the Class’) end Conditional Statements A conditional statement is a command that allows MATLAB to decide whether or not to execute some code that follows the statement • Conditional statements almost always part of scripts or functions • They have three general forms • if-end • if-else-end • if-elseif-else-end 11 Conditional Statements: • Conditional statements allow MATLAB to make decisions • Typically that decisions is whether or not to execute a group of commands • A conditional expression is stated in the conditional statement, if this expression is true, a group if commands that follow the statement are executed, if the expression is false, the group of commands is skipped • The basic conditional statement is an if statement MATLAB Syntax if conditional expression consisting of relational and/or logic operators end Note: Every if statement must end with an end statement if Statements: • Examples: if a< b if a>=c if a==d if (a5) Example of an if-end Statement: • Example: Write a MATLAB script to calculate the shipping cost of an order, if the order weighs less than 5 lbs the shipping cost is $5.00, for every pound over 5 the shipping cost increases $0.10. MATLAB Syntax w = input('Please input the weight of the shipment in lbs '); Cost = 5.00; if w>5.00 Cost = Cost + (w-5)*(0.10); end fprintf('The shipment cost is $%f', Cost) Command Window Please input the weight of the shipment in lbs 10 The shipment cost is $5.500000 ICA • Write a matlab script to prompt the user for number and print its square root if the number is positive. If Else Statements: • The if-else statement allows the user to provide a means for choosing one group of commands, out of two possible groups of commands to be executed • Must also conclude with an end statement • The logic check occurs, if the check is false, command group 2 is executed, if the statement is true, then command group 1 is executed. Example of an if-else-end Statement: • Example: Write a MATLAB script to calculate the shipping cost of an order, if the order weighs less than 10 lbs the shipping cost is $0.00, If the weight is greater than or equal to 10 lbs the order costs $5.00 plus $0.10 for every pound over 10. MATLAB Syntax w = input('Please input the weight of the shipment in lbs '); if w 0 the program needs to display “the equation has two real roots”, if D=0, display “the equation has one real root’” if D
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

This question has not been answered.

Create a free account to get help with this and any other question!

Related Tags