1 / 40

Academic Misconduct Input/Output Conditionals Writing a Simple Algorithm

Lecture 3. Academic Misconduct Input/Output Conditionals Writing a Simple Algorithm. Who are these people and why are they looking at me?. Academic Misconduct. From the syllabus.

giddensm
Download Presentation

Academic Misconduct Input/Output Conditionals Writing a Simple Algorithm

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 3 Academic MisconductInput/OutputConditionalsWriting a Simple Algorithm

  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, don’t take the risk of copying someone else’s work. Taking the attitude that you are invincible and that you will never get caught could land you in the Dean’s office at the end of the quarter. So don’t 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 other’s 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. It’s 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. We’re 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 <- (num_one + num_two) / 2 print (“Average = “, average) endalgorithm

  14. LB ESP Formatting • 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... ...it’s what’s for dinner.

  15. Questions?

  16. Conditionals

  17. Relational Operators • Greater than > • Greater or equal >= • Equal to = • Less than or equal <= • Less than < • Not equal to < >

  18. Using Relational Operators Combining relation operators with operands generates a boolean value Examples: 4 > 5 FALSE “apple” <= “cat” TRUE (alphabetic) 5 <> 6 TRUE 42 = 42 TRUE ‘g’ > ‘x’ FALSE LB

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

  20. In use there would be some variables! AND F T F F F T F T AND AND - all conditions must be true ((5>4) AND (4>7)) is FALSE TRUE FALSE

  21. OR F T F F T T T T OR OR - only one condition must be true ((5>4) OR (4>7)) is TRUE TRUE FALSE

  22. NOT F T T F NOT • NOT - reverses the boolean value NOT (4>7) 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 < y) - expression with logical operators ((10 >= x) AND (x < 20)) OR (y = -4) (0 < age < 20) is not legal and should be written ((0 < age) AND (age < 20)).

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

  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 >= 15 Code: if (num_of_hours >= 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 >= 90) then print(“You get an ‘A’”) elseif (grade >= 80) then print(“You get a ‘B’”) elseif (grade >= 70) then print(“You get a ‘C’”) elseif (grade >= 60) then print(“You get a ‘D’”) else // the default print(“Sorry, you get an ‘F’”) endif Why not: grade>= 80 AND < 90 ?

  33. A Complex Conditional if (withdrew_from_course = TRUE) then print(“Sorry to see you leave”) elseif (((quiz_grade >= 60) or (final_exam >= 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 >= 60) or (final_exam >= 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 you’ve finished writing the code!

  38. algorithm // constants // declarations // program endalgorithm Get_Circumference // Get_Cirumference Writing a Simple Algorithm 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 <- radius * 2 circumf <- diameter * PI Diameter is: 6 Circumference is: 18.85 print(“Diameter is: “, diameter) print(“Circumference is: “, circumf ) Done!

  39. Questions?

More Related