



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
During the course work of Thinking Like Computers, we study the key concept of artificial intelligence. The main points in these lecture slides are given as:Conditional Repetition, While Loops, While Loop Page, Priming Loop, Loop Tests, Counter-Driven Loops, Infinite Loops, Variables and Repetition, Countdown Page, Hailstone Sequences, Strings Objects
Typology: Slides
1 / 7
This page cannot be seen from the preview
Don't miss anything!




this is often backwards from the way we think about loops e.g., read input until you get a positive number (i.e., until input > 0) while (input <= 0) {... } e.g., keep rolling dice until you get doubles (i.e., until roll1 == roll2) while (roll1 != roll2) {... } e.g., keep rolling dice until you get double fours (i.e., until roll1 == 4 && roll2 = 4) while (roll1 != 4 || roll2 != 4) {... }
DeMorgan's Law: !(X && Y) == (!X || !Y) !(X || Y) == (!X && !Y)
examples :
data: a sequence of characters, enclosed in quotes operations include: make upper case, make lower case,
OOP encourages programmers to design programs around software objects the programmer identifies the real-world objects involved in a system (e.g., for a banking program: bank account, customer, teller, …) then designs and builds software objects to model these real-world objects
OOP is effective for managing large systems, since individual objects can be assigned to different teams and developed independently OOP also supports code reuse, since the same or similar objects can be combined in different ways to solve different kinds of problems
e.g., a string object has a length property that identifies the number of characters in the string
e.g., the toLowerCase method makes a copy of the string with all upper-case letters converted to lower-case
a property is a special kind of a variable (it stores a value) a method is a special kind of function (it performs some action)
e.g., each string object will have its own variable to stores it length
str1 = "foo"; str2 = "Hi there"; len1 = str1.length; len2 = str2.length;
e.g., str.toLowerCase() calls the toLowerCase method on str (which returns a lower-case copy of the string) e.g., str.toUpperCase() calls the toUpperCase method on str (which returns an upper-case copy of the string)
instead, they return modified copies of the string
components are identifiable via indices , or numbers that correspond to the order in which individual characters occur in a string indices are assigned in ascending order from left to right, so that the first character in the string is at index 0
it takes an index as an input and returns the character at that particular index word = "foo"; ch = word.charAt(0); // ASSIGNS ch = "f"