Download Harvard University's CS S-111: Intensive Introduction to Computer Science with Scratch and more Study notes Computer Science in PDF only on Docsity! Intensive Introduction to Computer Science Course Overview Programming in Scratch Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Unit 1, Part I Welcome to CS S-111! Computer science is not so much the science of computers as it is the science of solving problems using computers. Eric Roberts • This course covers: • the process of developing algorithms to solve problems • the process of developing computer programs to express those algorithms • fundamental data structures for imposing order on a collection of information • the process of comparing data structures & algorithms for a given problem Computer Science and Programming • There are many different fields within CS, including: • software systems • computer architecture • networking • programming languages, compilers, etc. • theory • AI • Experts in many of these fields don’t do much programming! • However, learning to program will help you to develop ways of thinking and solving problems used in all fields of CS. A Rigorous Introduction • Intended for: • future concentrators who plan to take more advanced courses • others who want a rigorous introduction • no programming background required, but can also benefit people with prior background • Allow for 20-30 hours of work per week • start work early! • come for help! • don't fall behind! Algorithms • In order to solve a problem using a computer, you need to come up with one or more algorithms. • An algorithm is a step-by-step description of how to accomplish a task. • An algorithm must be: • precise: specified in a clear and unambiguous way • effective: capable of being carried out Programming • Programming involves expressing an algorithm in a form that a computer can interpret. • We will primarily be using the Java programming language. • one of many possible languages • The key concepts of the course transcend this language. What Does a Program Look Like? • Here's a Java program that displays a simple message: public class HelloWorld { public static void main(String[] args) { System.out.println("hello, world"); } } • Like all programming languages, Java has a precise set of rules that you must follow. • the syntax of the language • To quickly introduce you to a number of key concepts, we will begin with a simpler language. Scratch • A simple but powerful graphical programming language • developed at the MIT Media Lab • makes it easy to create animations, games, etc. Scratch Basics • Scratch programs (scripts) control characters called sprites. • Sprites perform actions and interact with each other on the stage. drag building blocks here to create scripts the stage building blocks for programs/ scripts Program Building Blocks • Grouped into color-coded categories: • The shape of a building block indicates where it can go. Flow of Control: Responding to an Event • Hat blocks (ones with rounded tops) can be put on top of a script. • They wait for an event to happen. • when it does, the script is executed What Does a Program Look Like? • Recall our earlier Java program: public class HelloWorld { public static void main(String[] args) { System.out.println("hello, world"); } } • Here's the Scratch version … and here's the result: Stage Coordinates • Dimensions: 480 units wide by 360 units tall • Center has coordinates of 0, 0 What does this program draw? How many changes would be needed to draw this figure instead? (What are they?) How could we draw this figure? Program Building Blocks: Operators • Operators create a new value from existing values/variables. Our Program with Variables and Operators Getting User Input • Use the ask command from the sensing category. • The value entered by the user is stored in the special variable answer, which is also located in the sensing category. • Allowing the user to enter numSides and numCopies: Program Building Blocks: Boolean Expressions • Blocks with pointed edges produce boolean values: • true or false • Boolean operators: Flow of Control: Conditional Execution • conditional execution = deciding whether to execute one or more statements on the basis of some condition • There are C-shaped control blocks for this: • They have an input area with pointed edges for the condition. Flow of Control: Conditional Execution (cont.) • If the condition is true: • the statements under the if are executed • the statements under the else are not executed • If the condition is false: • the statements under the if are not executed • the statements under the else are executed