Academic Misconduct InputOutput Conditionals Writing a Simple Algorithm - PowerPoint PPT Presentation

About This Presentation
Title:

Academic Misconduct InputOutput Conditionals Writing a Simple Algorithm

Description:

All assignments must reflect an individual effort, and must be ... Possible ineligibility for the co-op program. Questions? Input and Output. Input and Output ... – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 41
Provided by: ccGa
Category:

less

Transcript and Presenter's Notes

Title: Academic Misconduct InputOutput Conditionals Writing a Simple Algorithm


1
Academic MisconductInput/OutputConditionalsWrit
ing a Simple Algorithm
Lecture 3
2
Who are these people and why are they looking at
me?
3
Academic Misconduct
4
From the syllabus...
  • All assignments must reflect an individual
    effort, and must be completed "from scratch". It
    is a violation of the honor code to copy or
    derive solutions from textbooks, internet
    resources or previous instances of this course.
    Copying of solutions from other students,
    including those who previously took the course is
    prohibited. A good guideline is that you must be
    able to explain and/or reproduce anything that
    you submit.

5
Dear CS1311 Students,
  • Be forewarned about the consequences of cheating
    in CS 1311, and give them serious thought. In the
    end your costs strongly outweigh your benefits.
    Even though the class can be confusing and
    sometimes even overwhelming, you must not let
    your frustration get the best of you. When and if
    you are still unsure just turn in what you have,
    dont take the risk of copying someone elses
    work. Taking the attitude that you are
    invincible and that you will never get caught
    could land you in the Deans office at the end of
    the quarter. So dont take the cheat finder
    lightly because it really does exist (for
    homework and lab projects!) Unfortunately, as a
    former CS 1311 student, I can personally assure
    that if you are going to cheat you are going to
    pay a heavy toll for it. Smart people learn from
    their own mistakes, geniuses learn from others
    mistakes.
  • Sincerely,
  • Anonymous CS 1311 Student

6
What is cheating?
  • Cheating is gaining an unfair advantage over
    others and/or misrepresenting yourself on your
    work for academic gain.
  • The intent to cheat is not a prerequisite for
    cheating to occur.

Its not worth it!
7
Consequences
  • F in the course is probable
  • University probation
  • Mandatory participation in community service
    hours
  • Loss of Hope Scholarship or any other scholarship
  • Lowered GPA- with possible probation or even
    expulsion from the university
  • Loss of job opportunities
  • Possible ineligibility for the co-op program

8
Questions?
9
Input and Output
10
Input and Output
  • I/O Operators allow us to communicate with the
    outside world, the world beyond the algorithm
    itself.
  • Were not concerned with formatting.

11
Print
  • Displays output items to the user
  • Syntax
  • print(item_1, item_2, ..., item_n)
  • Examples
  • print(Please enter your info.)
  • print(num_one, my_char, is_Student)

12
Read
  • Obtains input items from the user
  • Syntax
  • read(item_1, item_2, ..., item_n)
  • Examples
  • read(menu_choice)
  • read(is_Student, name, age)
  • No automatic prompting!

13
Input and Output Examples
  • algorithm IO_Example
  • num_one, num_two, average isoftype Num
  • // obtain two numbers
  • print(Please enter two numbers)
  • read (num_one, num_two)
  • // output a literal text message and the
  • // value of the sum
  • print (Sum , num_one num_two)
  • // output a string literal and average
  • average lt- (num_one num_two) / 2
  • print (Average , average)
  • endalgorithm


14
ESP Formatting
LB
  • Conventional languages require you to learn
    complex, intricate and often tricky formatting
    techniques.
  • With pseudocode the situation is much simpler
  • All tricky formatting manipulations are
    accomplished by just thinking about it and it
    happens
  • Leading edge pseudocode...
  • ...its whats for dinner.

15
Questions?
16
Conditionals
17
Relational Operators
  • Greater than gt
  • Greater or equal gt
  • Equal to
  • Less than or equal lt
  • Less than lt
  • Not equal to lt gt

18
Using Relational Operators
  • Combining relation operators with operands
    generates a boolean value
  • Examples
  • 4 gt 5 FALSE
  • apple lt cat TRUE (alphabetic)
  • 5 ltgt 6 TRUE
  • 42 42 TRUE
  • g gt x FALSE

LB
19
Boolean Operators
  • Boolean operators allow us to express compound
    expressions.
  • AND
  • OR
  • NOT

20
AND
  • AND - all conditions must be true
  • ((5gt4) AND (4gt7)) is FALSE
  • TRUE FALSE

21
OR
  • OR - only one condition must be true
  • ((5gt4) OR (4gt7)) is TRUE
  • TRUE FALSE

22
NOT
  • NOT - reverses the boolean value
  • NOT (4gt7) is TRUE
  • FALSE

23
Boolean Expressions
  • Boolean expressions evaluate to TRUE or FALSE and
    are composed of
  • boolean variables(is_too_young) // a boolean
  • expressions with relational operator(10 lt y)
  • - expression with logical operators
  • ((10 gt x) AND (x lt 20)) OR (y -4)
  • (0 lt age lt 20) is not legal and should be written
    ((0 lt age) AND (age lt 20)).

24
Naming Boolean Variables
LB
  • Names should be chosen to make clear what the
    true or false value represents
  • Bad Examples
  • red_or_green
  • gender
  • pass_fail
  • on_off
  • Good Examples
  • is_red
  • is_male
  • did_pass
  • is_on

25
Decision Statements
  • Conditionals allow us to make decisions based
    upon simple logic. Results of conditionals are
    always TRUE or FALSE, i.e., boolean values.
  • Natural Language
  • The number of hours is greater than or equal to
    15.
  • Picture
  • num_of_hours gt 15
  • Code
  • if (num_of_hours gt 15) then...

TRUE
FALSE
26
Simple Conditionals
  • Allows for some instructions to be conditionally
    executed.
  • Basic template
  • if ( BOOLEAN_EXPRESSION ) then
  • any instructions
  • endif

27
If-Then-Endif
  • if ( BOOLEAN_EXPRESSION ) then
  • any instructions
  • endif
  • If the BOOLEAN_EXPRESSION is TRUE, then execute
    all of the instructions in the then clause and
    continue the algorithm.
  • If the BOOLEAN_EXPRESSION is FALSE, then skip to
    the endif and continue the algorithm.

28
If-Then-Endif Example
  • wake up
  • if ( is_raining ) then
  • stay inside and play board games
  • go to see a movie
  • read a book
  • call friends
  • endif
  • go to sleep

29
If-Then-Else-Endif
  • if ( BOOLEAN_EXPRESSION ) then
  • any instructions to execute if true
  • else
  • any instructions to execute if false
  • endif
  • If the BOOLEAN_EXPRESSION is TRUE, then execute
    all of the instructions in the then clause until
    you reach else, then skip down to the endif and
    continue the algorithm.
  • If the BOOLEAN_EXPRESSION is FALSE, then execute
    all of the instructions in the else clause and
    continue the algorithm.
  • Cannot do both the if clause and the else clause
    only one or the other.

30
If-Then-Else-Endif Example
  • if ( is_raining ) then
  • stay inside and read a book
  • go to see a movie
  • else
  • go to the park
  • go swimming
  • endif
  • go to sleep

31
Nested Conditionals
Conditionals can reside inside other conditionals
  • if (today Sunday) then
  • if (NOT raining) then
  • go to the park
  • else
  • stay home read a book
  • endif
  • else
  • go to work
  • endif

Use indenting to make the code clear!
32
The Optional Elseif Clause
  • Often we want a way to select one from many
  • if (grade gt 90) then
  • print(You get an A)
  • elseif (grade gt 80) then
  • print(You get a B)
  • elseif (grade gt 70) then
  • print(You get a C)
  • elseif (grade gt 60) then
  • print(You get a D)
  • else // the default
  • print(Sorry, you get an F)
  • endif

Why not gradegt 80 AND lt 90 ?
33
A Complex Conditional
  • if (withdrew_from_course TRUE) then
  • print(Sorry to see you leave)
  • elseif (((quiz_grade gt 60) or
  • (final_exam gt 60)) and
  • (did_homework)) then
  • print(You pass the course)
  • else
  • print(Sorry, see you next term)
  • endif

See anything redundant?
34
A Complex Conditional
  • if (withdrew_from_course) then
  • print(Sorry to see you leave)
  • elseif (((quiz_grade gt 60) or
  • (final_exam gt 60)) and
  • (did_homework)) then
  • print(You pass the course)
  • else
  • print(Sorry, see you next term)
  • endif

35
Questions?
36
Writing Algorithms
37
Recipe for Writing Algorithms
  • Write the shell
  • Outline the logic
  • Code the main ideas
  • Verify declarations
  • Verify constants
  • Walk through the code
  • - syntax errors
  • - logic errors

Note that you still have work to do after youve
finished writing the code!
38
Writing a Simple Algorithm
algorithm // constants // declarations //
program endalgorithm
Get_Circumference //
Get_Cirumference
PI is 3.14159265
  • Write the shell

radius isoftype Num diameter isoftype Num circumf
isoftype Num
3
  • Name the algorithm

6
18.85
  • Outline the logic
  • Fill in the algorithm

// Get the data // Compute circumference //
Output the answer
  • Declare the variables

print(Enter the radius) read( radius )
  • Define the constants
  • Walk the code

3
Enter the radius
diameter lt- radius 2 circumf lt- diameter PI
Diameter is 6
Circumference is 18.85
print(Diameter is , diameter) print(Circumfere
nce is , circumf )
Done!
39
Questions?
40
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com