440 likes | 530 Views
Objective : Learn and be able to identify 1-way, 2-way, and Multiple-way sections. Find them in regular language word problems and use the best fitting to describe the solution. Post Objective : Identify how your coding up till now has either conformed or contrasted with these principles.
E N D
Objective : Learn and be able to identify 1-way, 2-way, and Multiple-way sections. Find them in regular language word problems and use the best fitting to describe the solution. Post Objective : Identify how your coding up till now has either conformed or contrasted with these principles. 1-2-Multiple Mr. Hudson Computer Science 1 Taylor_Hudson@allenisd.org
Structures of a Program Programs always read Top – Down. The only line of code executed before your current line, are the ones above except for specific cases which are conditional statements skipped or functions called. And they are called in previous lines so they are effectively just removed from the structure.
Conditional Statement Definition A conditional statement is a program expression that evaluates to true or false. Most conditional statements require a relational operator. All conditions must be placed inside (parentheses).
If Statement Think of an if statement without an else case, this instruction gives a particular circumstance(read condition) that must be done, if and only if your condition is met. Can anyone guess the name of the selection case that the if case signifies?
ONE WAY SELECTION Program Statement True Condition Program Statement False Program Statement Program Statement
IF - ELSE Now lets think of an if statement with an else case, this instruction gives a particular circumstance that must be done, if and only if your condition is met, generally a block of code and if your condition is not met, you must do something else giving your program some choice. Can anyone guess the name of the selection case that the if case signifies?
TWO WAY SELECTION Program Statement Condition True False Program Statement Program Statement Program Statement Program Statement
IF – ELSE IF - … - ELSE This is an advanced structure. More so useful in cases where you must check multiple circumstances. With (AND)s && , and (OR)s ||. In a moment we will talk about Boolean tables. But for now, lets just introduce this as a third selection case. Can anyone guess what type of Selection case this is?
Switch Case // declare variables. intmyInt; // myInt stored some number and is needed to move forward lets // assume it’s an average after our test. So the grade range could be // between 1 and 100. myInt = myInt / 10; switch(myInt){ case 9 : cout << “you got an A!”; break; case 8 : cout << “you got a B!”; break; case 7 : cout << “you got a C !”; break; case 6 : cout << “you got a D!”; break; default : cout << “you failed!”; break; }
Switch case • Doesn’t handle conditions, just specific cases. • Can you guess what type of selection type this is?
Multiple-Way Selection Selection Variable Match Selection Constant Program Statement No Match Match Selection Constant Program Statement No Match Match Selection Constant Program Statement No Match Program Statement
Problems A program that adds all the grades given in a loop, and stores the sum of each type and the count of each, by first asking the user to enter either A if it’s a test, B if it’s a quiz, C if it’s a homework grade or E to Exit, is an example of witch type of Selection case?
Problems If a student is Male he will have Mr. Brown as a PE teacher, if the student is Female she will have Mrs. Carr. The program will tell the student who their teacher is after learning the student’s name storing it with a string, age, and gender. What type of selection case is this type of program?
Problems Users must input positive numbers, but we as good programmers. Know that sometimes users try to break our code, so we build something right after our cin to check and make sure the number is positive or make it so. What type of selection case is this?
Problems We are creating a program to calculate our geometry homework to help tutor students. We have too first identify if the problems the students are asking are in 2 dimensions (Perimeter, distance, arc, cords, circumference, law of sine, law of cosine, etc.) or 3 dimensions (Volume, surface area, etc.) This process will take input from a user show the work and give answers. Or give instructions how to solve these problems. Can you think how you start to code this, the first thing you need to do is know which Dimension your talking about what type of selection is this case?
Continued • Can you think of any other selections this case will offer?
Objective : Today, we will talk about logic. Understand what logic is, and how it is prescribed. Talk about assignment that will be given Wednesday, along with correct methods of submission. Post Objective : Finish up any assignments not yet due, ask questions, and talk about logic as it is, and how CS uses it. Logic (Pitfalls) Mr. Hudson Computer Science 1 Taylor_Hudson@allenisd.org
Logic P.R.H. Anonymous If you think that your paper is vacuous,Use the first-order functional calculus.It then becomes logic,And, as if by magic,The obvious is hailed as miraculous.
What is Logic? Liberal Arts The Liberal Arts were divided into the Trivium “the three roads” and the Quadrivium“the four roads” The Trivium consisted of Grammar Rhetoric and Logic. The Quadrivium consisted of Arithmetic “number in itself” Geometry “number in Space” Music “number in time” and Astronomy “number in space and time”
If P, then Q Truth Follows Form All men are mortal, All Greeks are men. So…
Truth Follows Form All men are mortal, All Greeks are men. All Greeks are mortal! (Now try replacing Key Words)
Truth Follows Form All ______ are ______, All ______ are ______. All ______ are ______! (Now try replacing Key Words)
Truth Follows Form All ______ are ______, All ______ are ______. All ______ are ______! (Now try replacing Key Words) Var1 Var2 Var3 Var1 Var3 Var2
Boolean OperatorsBoolean OR A T T F F B T F T F A or B T T T F
Boolean OperatorsBoolean AND A T T F F B T F T F A and B T F F F
Boolean OperatorsBoolean NOT Continued ~B F T F T A T T F F B T F T F ~A F F T T
Truth Table #1A and (A or B) A T T F F B T F T F A or B T T T F A and (A or B) T T F F
Truth Table #2(A and B) or C A T T T T F F F F B T T F F T T F F C T F T F T F T F A and B T T F F F F F F (A and B) or C T T T F T F T F
Truth Table #3(A or B) and C A T T T T F F F F B T T F F T T F F C T F T F T F T F A or B T T T T T T F F (A or B) and C T F T F T F F F
Truth Table Facts The truth tables of equivalent Boolean expressions are identical.
Truth Table #4Is ~(A or B) = ~A or ~B ? A T T F F B T F T F A or B T T T F ~(A or B) F F F T ~A F F T T ~B F T F T ~A or ~B F T T T ^ NO ^
Assume X & Y as Boolean : • Writing Code: Logical XOR (X, Y) { return ((X||Y)&&!(X&&Y)); } C = (X or Y) D = !(X&&Y) X XOR Y = C & D XOR Truth Table
Boolean OperatorsBoolean XOR A T T F F B T F T F A xor B F T T F
Truth Table #5Is ~(A or B) = ~A and ~B ? A T T F F B T F T F A or B T T T F ~(A or B) F F F T ~A F F T T ~B F T F T ~A and ~B F F F T ^ YES ^
Truth Table #6Is ~(A and B) = ~A or ~B ? A T T F F B T F T F A and B T F F F ~(A and B) F T T T ~A F F T T ~B F T F T ~A or ~B F T T T ^ YES ^
DeMorgan’s Law not(A and B) = not A or not B not(A or B) = not A and not B This says the same thing: ~(A + B) = ~A * ~B ~(A * B) = ~A + ~B
If the maid did it, then it was done with a revolver only if it was done in the parlor. But if the butler is innocent, then the maid did it unless it was done in the parlor. The maid did it only if it was done with a revolver, while the butleris guilty if it did happen in the parlor. So the butler is guilty.
Logical Validity and Soundness Symbolic logic is a tool or machine for identification of argument goodness. It makes sense to begin, however, not with the machine, but by saying something about the argument goodness that the machinery is supposed to identify. That is the task of this chapter. AR – an argument is some sentences, one of which (the conclusion) is taken to be supported by the remaining sentences (the premises).
Consider the difference • Only citizens can vote • Herbert is a citizen • Herbert can vote • All citizens can vote • Herbert is a citizen • Herbert can vote _________________________ _________________________
Is this a good characterization? Eating Brussels sprouts results in good health Ophilia has good health Ophiliahas been eating brussels sprouts
How to Submit via N Drive • Step one naming a project. • Step two submit the whole project • Step three comment often and/or use descriptive and uniform variable names • Step four do your own work, it’s ok to ask for help but don’t rely on anyone to do your work for you. • Step five complete tasks on time.