CS102 Unit 2. Sets and Mathematical Formalism Programming Languages and Simple Program Execution

Size: px
Start display at page:

Download "CS102 Unit 2. Sets and Mathematical Formalism Programming Languages and Simple Program Execution"

Transcription

1 1 CS102 Unit 2 Sets and Mathematical Formalism Programming Languages and Simple Program Execution

2 2 Review Show how "Hi!\n" would be stored in the memory below Use decimal to represent each byte Remember how we terminate a string

3 BEING PRECISE 3

4 4 Humans and Computers Humans understand instructions differently than computers Humans easily tolerate ambiguity and abstract concepts using context to help. Add a pinch of salt. How much is a pinch? Steph Curry can shoot the lights out. It s a bear market Computers must be precise, only executing welldefined instructions (no ambiguity) and operating on digital information which is finite and discrete (a fixed number of options)

5 5 Set Introduction As we just saw, computer scientists and engineers need a certain level of precision and formalism when we express ourselves One tool from discrete mathematics that helps us with this is sets A set is an unordered collection of items (usually referred to as elements or members) Can be used to specify exactly what options we are considering, processing, inputting or outputting

6 6 Expressing Sets 0 99 Sets are usually denoted by an upper case letter with elements listed inside curly braces { }) Example: Let S be the set of the first 10 positive integers S = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 For large sets, enumerating all the elements may be difficult so we can use an ellipse to communicate the pattern for generating the members -1 S Example: Let T be the set of odd integers between 0 and 100 T = 1, 3, 5,, 99

7 7 Common Sets A few common sets: N = Natural Numbers = { 0, 1, 2, 3 } Z = Integers = {, 3, 2, 1, 0, 1, 2, 3, } Z + = Positive Integers = { 1, 2, 3, } Z = Negative Integers = {, 3, 2, 1} Q = Rational Numbers (e.g. 4/5, -2/3, etc.) R = Real Numbers R + = Positive Reals R = Negative Reals A few symbols: = element of (e.g. 2 N, 3 Z) = not an element of (e.g. 2.5 N, i N, )

8 P(x)=true P(x)=false P(x)=true P(x)=true P(x)=true 8 Set Builder Notation Sometimes listing all the elements of a set could be arduous if not impossible Instead we can use set-builder notation where we describe a set by listing what property (properties), P, must be true about its member elements Example: S = x P(x) The symbol is read as 'such that' We would read this as, "S is the set of all x, such that x meets the property(-ies), P Thus we could have described the set of the first 10 positive integers as: S = x x is an integer, 1 x 10 A comma can be read as 'AND' where both properties need to hold All potential elements x x S

9 P(x)=true P(x)=false P(x)=true 9 Restricting the Universe With sets, "universe" refers to all the possible elements being considered for membership in the set (i.e. all integers, all real numbers, all students in a class, etc.) When we use set-builder notation like: S = { x P(x) }, we are saying x can take on all options in the universe and then we'll check if P(x) is true It often helps to restrict the universe to a smaller set: S = x x is an integer, 1 x 10 could be rewritten as S = x Z 1 x 10 Read: S is the set of all integers, x, such that x is between 1 and 10 What's the difference if we left out the restriction: S = x 1 x 10 All potential elements x Z x Z S

10 10 Using Formula You can also use formula to express the items in the set: Recall: T = 1, 3, 5,, 99 This can be written with set-builder notation as: T = 2n + 1 n N, n < 50 Here we say, "T is the set of values that are 1 more than two times n such that n is a natural number less than 50 (i.e. 0 to 49)"

11 11 Practice Examples A is the set of all real numbers greater than 10 A = B is the set of the first 20 non-negative multiples of 3 B = C is the set of all integers whose square is greater than 50 C =

12 12 Practice Examples A is the set of all real numbers greater than 10 A = x R x > 10 B is the set of the first 20 non-negative multiples of 3 B = 3i i N, i < 20 C is the set of all integers whose square is greater than 50 C = i i Z, i 2 > 50

13 13 ALGORITHMS & PROGRAMMING LANGUAGES

14 14 Algorithms Algorithms are at the heart of computer systems, both in HW and SW They are fundamental to Computer Science and Computer Engineering Informal definition An algorithm is a precise way to accomplish a task or solve a problem A more formal definition: An ordered set of unambiguous, executable steps that defines a terminating process Software Hardware

15 15 Algorithm Representation An algorithm is not a program or programming language Just as a story may be represented as a book, movie, or spoken by a story-teller, an algorithm may be represented in many ways Flow chart Pseudocode (English-like syntax using primitives that most programming languages would have) A specific program implementation in a given programming language

16 16 Syntax and Semantics Programming languages have syntax and semantics Syntax: refers to the rules of a language for how it will be expressed and parsed (decomposed) Specific to the language Semantics: refers to the meaning of what is written Often transcends the language (same concept in many language) Example: A sentence The syntax refers to the proper grammatical way of writing a sentence (at least a subject and verb, capitalizing the first letter and ending with a period) The semantics refer to the meaning conveyed by the sentence C Code Example if (condition) { action } is the syntax. The semantics (meaning) is the action will only be performed if condition is true

17 17 A First Program Go to: Enter this program to print "Hello!" five times #include <iostream> int main() { for(int i=0; i < 5; i++){ std::cout << "Hello!" << std::endl; } return 0; } Introduce some syntax errors Introduce a semantic error C++ syntax requires statement to end with a semicolon (;) and grouped by curly braces { }. Removing one would lead to a syntax error. A semantic error is when I tell the computer to do the wrong thing but it still meets the correct syntax. Change "i=0" to "i=1" and see it print only 4 times rather than the desired 5.

18 18 CODE ORGANIZATION AND SEQUENCE OF EXECUTION

19 19 Sequence & Executability Let's learn a bit more about program execution by using another language named Scratch Write a Scratch program to walk forward, turn right, then walk forward again Remember computers need executable steps How far forward? Turn right by how much?

20 20 Sequence & Executability Scratch provides a "menu" of executable options You must compose a program from that "menu" Create the program shown to the right and then click the green flag to the left of the red stop sign What happens? Click the green flag again What happens?

21 21 Explicitness Computers do only what you tell them, no more, no less What additional details might we want to instruct the computer? Where to start and what direction to face? To provide some delay between steps Remember computers execute code very quickly compared to what a human can see

22 22 Sequential Execution Notice Program is executed 1 operation at a time in sequential fashion Each operation is ordered (a definite first, second, third, operation) 1 2 3

23 23 Organizing Code - Functions Notice the repetition of a common sequence of code executed multiple times Move 100 steps Wait 1 second Programming languages generally allow code to be organized into chunks that perform user-defined tasks Usually called functions, procedures, methods, subroutines, etc. "Functions" are an important way to organize your code and help avoid repetition, prevent mistakes (changing one occurrent rather than many), making the code more understandable to another human, etc.

24 24 Sequence of Execution With Functions We can define a function and then replace all its occurrences in the main program Do we execute sequentially (top-down) Not Really We execute the main program sequentially, then when we encounter a function/subroutine we jump, execute it sequentially, and then return and resume back in the main program Do we execute Sequentially?? 4a 4b a 7b

25 25 Sequence of Execution With Functions Our function "DelayedMove" is useful for the simple task we gave you to implement What might make it more useful and "general" so that we could reuse it in the future more easily? The ability to generalize how many steps to take and how long to wait might be helpful We call these "input parameters" Each time we want to use the function we can specify different values for the parameters then the operations inside the function will use whatever values we provide Example: First execution of DelayedMove steps = delay = Second execution of DelayedMove steps = delay =

26 26 C/C++ Program Format/Structure Comments Anywhere in the code C-Style => "/*" and "*/" C++ Style => "//" Compiler Directives #includes tell compiler what other library functions you plan on using 'using namespace std;' -- Just do it for now! main() function Starting point of execution for the program All code/statements in C must be inside a function Statements execute one after the next and end with a semicolon (;) Ends with a 'return 0;' statement Other functions printname() is a function that can be "called"/"invoked" from main or any other function /* Anything between slash-star and star-slash is ignored even across multiple lines of text or code */ // Anything after "//" is ignored on a line // #includes allow access to library functions #include <iostream> #include <cmath> using namespace std; void printname() { cout << "Tommy Trojan" << endl; } // Execution always starts at the main() function int main() { cout << "Hello: " << endl; printname(); printname(); return 0; } Hello: Tommy Trojan Tommy Trojan

27 27 (Optional Instructor may skip due to time constraints) PROGRAMMING LANGUAGES

28 28 Computer Abstractions Recall that all computer programs must be converted to 1's and 0's (aka machine code) Similar to translating from one spoken language to another Imagine you need to give a speech in front of a crowd that does not speak your native language. How could you do it? SW Compilers / Interpreters HW High Level Languages: Python / Java / C++ Assembly / Machine Code Logic Gates Transistors Applications OS Processor / Memory / I/O Voltage / Currents Libraries

29 29 Compiled vs. Interpreted Languages Compiled (Natively) Requires code to be converted to the native machine language of the processor in the target system before it can be run Analogy: Taking a speech and translating it to a different language ahead of time so the speaker can just read it Faster Often allows programmer closer access to the hardware Interpreted Requires an interpreter program on the target system that will interpret the program source code command by command to the native system at run-time Analogy: Speaking through an interpreter where the speaker waits while the translator interprets Better portability to different systems Often abstracts HW functionality with built-in libraries (networking, file I/O, math routines, etc.)

30 30 Best of Both Worlds? Many languages used for web and desktop apps (e.g. Java and Python) will compile their code to an intermediate form (aka bytecode) Then an interpreter can be used to execute the byte code faster than interpreting the high-level language directly New interpreters can be provided for new devices (platforms) Other languages like C/C++ compile their code directly to a form that can be executed and run on the device Machine Code for ios (ARM) ARM Proc. High-Level Language Compiler ByteCode Interpreter Machine Code for PC (x86) PC Proc.

31 31 High Level Languages

32 32 So What Do Compilers Do First, check for correct grammar (aka syntax) Second, check for appropriate meaning where it can be inferred (aka semantics) Perform the translation into appropriate output language For C/C++ this is binary (machine code)

33 33 Why C++ Because it is used widely Java, C, C++, C#, and Python are commonly the top 5 Because it is "close" to the hardware Makes it fast Makes it flexible (Near direct control of the HW) Makes it dangerous (Near direct control of the HW) In fact, many other languages are themselves written in C/C++ Because if you learn C++ you can likely learn MOST languages very quickly Because that's what we use in CS 103

34 34 A Live Demo Sort an array of integers from N-1 to 0 [9,999 9,998 9, ] => [ ,997 9,998 9,999] With a Python script (interpreted) With C++ (compiled natively) With a "built-in" Python library function that does the same task we just wrote manually (different algorithm) a = range(n) a.reverse() a.sort() // built-in sort implementation (non-interpreted) Note: Algorithms can make all the difference!

CS 103 Unit 8b Slides

CS 103 Unit 8b Slides 1 CS 103 Unit 8b Slides Algorithms Mark Redekopp ALGORITHMS 2 3 How Do You Find a Word in a Dictionary Describe an efficient method Assumptions / Guidelines Let target_word = word to lookup N pages in

More information

An Introduction to Python (TEJ3M & TEJ4M)

An Introduction to Python (TEJ3M & TEJ4M) An Introduction to Python (TEJ3M & TEJ4M) What is a Programming Language? A high-level language is a programming language that enables a programmer to write programs that are more or less independent of

More information

1.1. EE355 Unit 1. Course Overview & Review. Mark Redekopp

1.1. EE355 Unit 1. Course Overview & Review. Mark Redekopp 1.1 EE355 Unit 1 Course Overview & Review Mark Redekopp 1.2 Context Just for EE undergraduates Prerequisite: EE 150L / ITP 165 Applied mathematics Fundamentals of computer programming C/C++ and object-oriented

More information

Welcome to Python 3. Some history

Welcome to Python 3. Some history Python 3 Welcome to Python 3 Some history Python was created in the late 1980s by Guido van Rossum In December 1989 is when it was implemented Python 3 was released in December of 2008 It is not backward

More information

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING KEY CONCEPTS COMP 10 EXPLORING COMPUTER SCIENCE Lecture 2 Variables, Types, and Programs Problem Definition of task to be performed (by a computer) Algorithm A particular sequence of steps that will solve

More information

Computer Programming : C++

Computer Programming : C++ The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2003 Muath i.alnabris Computer Programming : C++ Experiment #1 Basics Contents Structure of a program

More information

CS 103 Lecture 4 Slides

CS 103 Lecture 4 Slides 1 CS 103 Lecture 4 Slides Algorithms Mark Redekopp ARRAYS 2 3 Need for Arrays If I want to keep the score of 100 players in a game I could declare a separate variable to track each one s score: int player1

More information

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements

Lecture 05 I/O statements Printf, Scanf Simple statements, Compound statements Programming, Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science and Engineering Indian Institute of Technology, Madras Lecture 05 I/O statements Printf, Scanf Simple

More information

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program? Intro to Programming & C++ Unit 1 Sections 1.1-4 and 2.1-10, 2.12-13, 2.15-17 CS 1428 Spring 2019 Jill Seaman 1.1 Why Program? Computer programmable machine designed to follow instructions Program a set

More information

6 Functions. 6.1 Focus on Software Engineering: Modular Programming TOPICS. CONCEPT: A program may be broken up into manageable functions.

6 Functions. 6.1 Focus on Software Engineering: Modular Programming TOPICS. CONCEPT: A program may be broken up into manageable functions. 6 Functions TOPICS 6.1 Focus on Software Engineering: Modular Programming 6.2 Defining and Calling Functions 6.3 Function Prototypes 6.4 Sending Data into a Function 6.5 Passing Data by Value 6.6 Focus

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay C++ Basics Data Processing Course, I. Hrivnacova, IPN Orsay The First Program Comments Function main() Input and Output Namespaces Variables Fundamental Types Operators Control constructs 1 C++ Programming

More information

CS103 Lecture 1 Slides. Introduction Mark Redekopp

CS103 Lecture 1 Slides. Introduction Mark Redekopp 1 CS103 Lecture 1 Slides Introduction Mark Redekopp 2 What is Computer Science All science is computer science It is very interdisciplinary: Math, Engineering, Medicine, Natural sciences, Art, Linguistics,

More information

Getting started with C++ (Part 2)

Getting started with C++ (Part 2) Getting started with C++ (Part 2) CS427: Elements of Software Engineering Lecture 2.2 11am, 16 Jan 2012 CS427 Getting started with C++ (Part 2) 1/22 Outline 1 Recall from last week... 2 Recall: Output

More information

DELHI PUBLIC SCHOOL TAPI

DELHI PUBLIC SCHOOL TAPI Loops Chapter-1 There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed

More information

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007 CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007 Course Web Site http://www.nps.navy.mil/cs/facultypages/squire/cs2900 All course related materials will be posted

More information

Programming with C++ as a Second Language

Programming with C++ as a Second Language Programming with C++ as a Second Language Week 2 Overview of C++ CSE/ICS 45C Patricia Lee, PhD Chapter 1 C++ Basics Copyright 2016 Pearson, Inc. All rights reserved. Learning Objectives Introduction to

More information

Programming. Computer. Program. Programming Language. Execute sequence of simple (primitive) instructions What instructions should be provided?

Programming. Computer. Program. Programming Language. Execute sequence of simple (primitive) instructions What instructions should be provided? C++ Basics Programming Computer Execute sequence of simple (primitive) instructions What instructions should be provided? Is there a minimum set? (See Turing Machine) Generic Reduce future limitations

More information

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 1 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) WHO

More information

Chapter 2 Basic Elements of C++

Chapter 2 Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion

More information

COMP 102: Computers and Computing

COMP 102: Computers and Computing COMP 102: Computers and Computing Lecture 5: What is Programming? Instructor: Kaleem Siddiqi (siddiqi@cim.mcgill.ca) Class web page: www.cim.mcgill.ca/~siddiqi/102.html Motivation The advantage of a computer

More information

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

More information

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to A PROGRAM IS A SEQUENCE of instructions that a computer can execute to perform some task. A simple enough idea, but for the computer to make any use of the instructions, they must be written in a form

More information

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab. University of Technology Laser & Optoelectronics Engineering Department C++ Lab. Fifth week Control Structures A program is usually not limited to a linear sequence of instructions. During its process

More information

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program Overview - General Data Types - Categories of Words - The Three S s - Define Before Use - End of Statement - My First Program a description of data, defining a set of valid values and operations List of

More information

CS 31 Discussion 1A, Week 1. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50

CS 31 Discussion 1A, Week 1. Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 CS 31 Discussion 1A, Week 1 Zengwen Yuan (zyuan [at] cs.ucla.edu) Humanities A65, Friday 10:00 11:50 TA Zengwen Yuan ( zyuan [at] cs.ucla.edu ) Discussion session (1A): Humanities A65 Friday 10:00 11:50

More information

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; } Ex: The difference between Compiler and Interpreter The interpreter actually carries out the computations specified in the source program. In other words, the output of a compiler is a program, whereas

More information

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm.

The sequence of steps to be performed in order to solve a problem by the computer is known as an algorithm. CHAPTER 1&2 OBJECTIVES After completing this chapter, you will be able to: Understand the basics and Advantages of an algorithm. Analysis various algorithms. Understand a flowchart. Steps involved in designing

More information

CSc 10200! Introduction to Computing. Lecture 1 Edgardo Molina Fall 2013 City College of New York

CSc 10200! Introduction to Computing. Lecture 1 Edgardo Molina Fall 2013 City College of New York CSc 10200! Introduction to Computing Lecture 1 Edgardo Molina Fall 2013 City College of New York 1 Introduction to Computing Lectures: Tuesday and Thursday s (2-2:50 pm) Location: NAC 1/202 Recitation:

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

CPS122 Lecture: From Python to Java last revised January 4, Objectives: Objectives: CPS122 Lecture: From Python to Java last revised January 4, 2017 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

More information

Module 1: Introduction to Computers, Programs, and Java

Module 1: Introduction to Computers, Programs, and Java Module 1: Introduction to Computers, Programs, and Java Module 1: Introduction to Java page 1 Objectives To review Program Design and Problem-Solving Techniques To describe the relationship between Java

More information

CS 177 Recitation. Week 1 Intro to Java

CS 177 Recitation. Week 1 Intro to Java CS 177 Recitation Week 1 Intro to Java Questions? Computers Computers can do really complex stuff. How? By manipulating data according to lists of instructions. Fundamentally, this is all that a computer

More information

Scientific Computing

Scientific Computing Scientific Computing Martin Lotz School of Mathematics The University of Manchester Lecture 1, September 22, 2014 Outline Course Overview Programming Basics The C++ Programming Language Outline Course

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

Java Programming Fundamentals - Day Instructor: Jason Yoon Website:

Java Programming Fundamentals - Day Instructor: Jason Yoon Website: Java Programming Fundamentals - Day 1 07.09.2016 Instructor: Jason Yoon Website: http://mryoon.weebly.com Quick Advice Before We Get Started Java is not the same as javascript! Don t get them confused

More information

Variables and Constants

Variables and Constants HOUR 3 Variables and Constants Programs need a way to store the data they use. Variables and constants offer various ways to work with numbers and other values. In this hour you learn: How to declare and

More information

CS103 Lecture 1 Slides. Introduction Mark Redekopp

CS103 Lecture 1 Slides. Introduction Mark Redekopp 1 CS103 Lecture 1 Slides Introduction Mark Redekopp 2 What is Computer Science All science is computer science It is very interdisciplinary: Math, Engineering, Medicine, Natural sciences, Art, Linguistics,

More information

Outline. Introduction to Programming (in C++) Introduction. First program in C++ Programming examples

Outline. Introduction to Programming (in C++) Introduction. First program in C++ Programming examples Outline Introduction to Programming (in C++) Introduction Programming examples Algorithms, programming languages and computer programs Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer

More information

Chapter 2. C++ Syntax and Semantics, and the Program Development Process. Dale/Weems 1

Chapter 2. C++ Syntax and Semantics, and the Program Development Process. Dale/Weems 1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems 1 Chapter 2 Topics Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables

More information

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals

More information

Today s Topics. What is a set?

Today s Topics. What is a set? Today s Topics Introduction to set theory What is a set? Set notation Basic set operations What is a set? Definition: A set is an unordered collection of objects Examples: Sets can contain items of mixed

More information

CSCE 120: Learning To Code

CSCE 120: Learning To Code CSCE 120: Learning To Code Manipulating Data I Introduction This module is designed to get you started working with data by understanding and using variables and data types in JavaScript. It will also

More information

Compiling C++ Programs Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3

Compiling C++ Programs Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3 Compiling C++ Programs Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3 Ziad Matni Dept. of Computer Science, UCSB Compiling Programs in C++ Input and Output Streams Simple Flow

More information

Computer Programming

Computer Programming Computer Programming Dr. Deepak B Phatak Dr. Supratik Chakraborty Department of Computer Science and Engineering Session: Structure of a Simple C++ Program Dr. Deepak B. Phatak & Dr. Supratik Chakraborty,

More information

Chapter 1. C++ Basics. Copyright 2010 Pearson Addison-Wesley. All rights reserved

Chapter 1. C++ Basics. Copyright 2010 Pearson Addison-Wesley. All rights reserved Chapter 1 C++ Basics Copyright 2010 Pearson Addison-Wesley. All rights reserved Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment

More information

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program

More information

assembler Machine Code Object Files linker Executable File

assembler Machine Code Object Files linker Executable File CSCE A211 Programming Intro What is a Programming Language Assemblers, Compilers, Interpreters A compiler translates programs in high level languages into machine language that can be executed by the computer.

More information

This watermark does not appear in the registered version - Slide 1

This watermark does not appear in the registered version -   Slide 1 Slide 1 Chapter 1 C++ Basics Slide 2 Learning Objectives Introduction to C++ Origins, Object-Oriented Programming, Terms Variables, Expressions, and Assignment Statements Console Input/Output Program Style

More information

CS101 Introduction to Programming Languages and Compilers

CS101 Introduction to Programming Languages and Compilers CS101 Introduction to Programming Languages and Compilers In this handout we ll examine different types of programming languages and take a brief look at compilers. We ll only hit the major highlights

More information

How to approach a computational problem

How to approach a computational problem How to approach a computational problem A lot of people find computer programming difficult, especially when they first get started with it. Sometimes the problems are problems specifically related to

More information

Introduction to Scientific Computing

Introduction to Scientific Computing Introduction to Scientific Computing Dr Hanno Rein Last updated: October 12, 2018 1 Computers A computer is a machine which can perform a set of calculations. The purpose of this course is to give you

More information

CSC Discrete Math I, Spring Sets

CSC Discrete Math I, Spring Sets CSC 125 - Discrete Math I, Spring 2017 Sets Sets A set is well-defined, unordered collection of objects The objects in a set are called the elements, or members, of the set A set is said to contain its

More information

The syntax and semantics of Beginning Student

The syntax and semantics of Beginning Student The syntax and semantics of Beginning Student Readings: HtDP, Intermezzo 1 (Section 8). We are covering the ideas of section 8, but not the parts of it dealing with section 6/7 material (which will come

More information

The syntax and semantics of Beginning Student

The syntax and semantics of Beginning Student The syntax and semantics of Beginning Student Readings: HtDP, Intermezzo 1 (Section 8). We are covering the ideas of section 8, but not the parts of it dealing with section 6/7 material (which will come

More information

CPS122 Lecture: From Python to Java

CPS122 Lecture: From Python to Java Objectives: CPS122 Lecture: From Python to Java last revised January 7, 2013 1. To introduce the notion of a compiled language 2. To introduce the notions of data type and a statically typed language 3.

More information

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018 C++ Basics Lecture 2 COP 3014 Spring 2018 January 8, 2018 Structure of a C++ Program Sequence of statements, typically grouped into functions. function: a subprogram. a section of a program performing

More information

Computer Components. Software{ User Programs. Operating System. Hardware

Computer Components. Software{ User Programs. Operating System. Hardware Computer Components Software{ User Programs Operating System Hardware What are Programs? Programs provide instructions for computers Similar to giving directions to a person who is trying to get from point

More information

Introduction to the C++ Programming Language

Introduction to the C++ Programming Language LESSON SET 2 Introduction to the C++ Programming Language OBJECTIVES FOR STUDENT Lesson 2A: 1. To learn the basic components of a C++ program 2. To gain a basic knowledge of how memory is used in programming

More information

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program:

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 8/19/ Review. Here s a simple C++ program: Welcome Back CSCI 262 Data Structures 2 - Review What you learned in CSCI 261 (or equivalent): Variables Types Arrays Expressions Conditionals Branches & Loops Functions Recursion Classes & Objects Streams

More information

Welcome to MCS 360. content expectations. using g++ input and output streams the namespace std. Euclid s algorithm the while and do-while statements

Welcome to MCS 360. content expectations. using g++ input and output streams the namespace std. Euclid s algorithm the while and do-while statements Welcome to MCS 360 1 About the Course content expectations 2 our first C++ program using g++ input and output streams the namespace std 3 Greatest Common Divisor Euclid s algorithm the while and do-while

More information

REVIEW. The C++ Programming Language. CS 151 Review #2

REVIEW. The C++ Programming Language. CS 151 Review #2 REVIEW The C++ Programming Language Computer programming courses generally concentrate on program design that can be applied to any number of programming languages on the market. It is imperative, however,

More information

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture 04 Programs with IO and Loop We will now discuss the module 2,

More information

Principles of Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

Principles of Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore (Refer Slide Time: 00:20) Principles of Compiler Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Lecture - 4 Lexical Analysis-Part-3 Welcome

More information

Introduction to C++ CS 1: Problem Solving & Program Design Using C++

Introduction to C++ CS 1: Problem Solving & Program Design Using C++ Introduction to C++ CS 1: Problem Solving & Program Design Using C++ Getting to Know Me and Me Getting to Know You First, a little about you Your name Have you ever worked with/used/played with any programming

More information

PIC 10A Objects/Classes

PIC 10A Objects/Classes PIC 10A Objects/Classes Ernest Ryu UCLA Mathematics Last edited: November 13, 2017 User-defined types In C++, we can define our own custom types. Object is synonymous to variable, and class is synonymous

More information

Week 0: Intro to Computers and Programming. 1.1 Why Program? 1.2 Computer Systems: Hardware and Software. Hardware Components

Week 0: Intro to Computers and Programming. 1.1 Why Program? 1.2 Computer Systems: Hardware and Software. Hardware Components Week 0: Intro to Computers and Programming Gaddis: Sections 1.1-3 and 2.1 CS 1428 Fall 2014 Jill Seaman 1.1 Why Program? Computer programmable machine designed to follow instructions Program instructions

More information

Chapter 8 Algorithms 1

Chapter 8 Algorithms 1 Chapter 8 Algorithms 1 Objectives After studying this chapter, the student should be able to: Define an algorithm and relate it to problem solving. Define three construct and describe their use in algorithms.

More information

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq CS 241 Computer Programming Introduction Teacher Assistant Hadeel Al-Ateeq 1 2 Course URL: http://241cs.wordpress.com/ Hadeel Al-Ateeq 3 Textbook HOW TO PROGRAM BY C++ DEITEL AND DEITEL, Seventh edition.

More information

Introduction to C ++

Introduction to C ++ Introduction to C ++ Thomas Branch tcb06@ic.ac.uk Imperial College Software Society October 18, 2012 1 / 48 Buy Software Soc. s Free Membership at https://www.imperialcollegeunion.org/shop/ club-society-project-products/software-products/436/

More information

Programming Lecture 3

Programming Lecture 3 Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

More information

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char Week 1 Operators, Data Types & I/O Gaddis: Chapters 1, 2, 3 CS 5301 Fall 2016 Jill Seaman Programming A program is a set of instructions that the computer follows to perform a task It must be translated

More information

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces Basic memory model Using functions Writing functions Basics Prototypes Parameters Return types Functions and memory Names and namespaces When a program runs it requires main memory (RAM) space for Program

More information

Understanding main() function Input/Output Streams

Understanding main() function Input/Output Streams Understanding main() function Input/Output Streams Structure of a program // my first program in C++ #include int main () { cout

More information

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 2: SEP. 8TH INSTRUCTOR: JIAYIN WANG 1 Notice Class Website http://www.cs.umb.edu/~jane/cs114/ Reading Assignment Chapter 1: Introduction to Java Programming

More information

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6 Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6 Ziad Matni Dept. of Computer Science, UCSB A reminder about Labs Announcements Please make sure you READ

More information

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture - 04 Introduction to Programming Language Concepts

More information

CS 103 Lecture 2 Slides

CS 103 Lecture 2 Slides 1 CS 103 Lecture 2 Slides C/C++ Basics Mark Redekopp 2 Get your VM's installed. Do's and Don'ts with your VM HW 1 Announcements Installing the 'Guest Additions' for the Linux VM Backing up files Not installing

More information

REPETITION CONTROL STRUCTURE LOGO

REPETITION CONTROL STRUCTURE LOGO CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design i About the Tutorial A compiler translates the codes written in one language to some other language without changing the meaning of the program. It is also expected that a compiler should make the target

More information

Constructing Algorithms and Pseudocoding This document was originally developed by Professor John P. Russo

Constructing Algorithms and Pseudocoding This document was originally developed by Professor John P. Russo Constructing Algorithms and Pseudocoding This document was originally developed by Professor John P. Russo Purpose: # Describe the method for constructing algorithms. # Describe an informal language for

More information

Programming Fundamentals

Programming Fundamentals Programming Fundamentals Computers are really very dumb machines -- they only do what they are told to do. Most computers perform their operations on a very primitive level. The basic operations of a computer

More information

6.096 Introduction to C++

6.096 Introduction to C++ MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. 6.096 Lecture 3 Notes

More information

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016

COMP-202: Foundations of Programming. Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016 COMP-202: Foundations of Programming Lecture 2: Java basics and our first Java program! Jackie Cheung, Winter 2016 Learn about cutting-edge research over lunch with cool profs January 18-22, 2015 11:30

More information

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 10: OCT. 6TH INSTRUCTOR: JIAYIN WANG 1 Notice Assignments Reading Assignment: Chapter 3: Introduction to Parameters and Objects The Class 10 Exercise

More information

Chapter 1 INTRODUCTION

Chapter 1 INTRODUCTION Chapter 1 INTRODUCTION A digital computer system consists of hardware and software: The hardware consists of the physical components of the system. The software is the collection of programs that a computer

More information

Identifiers. Identifiers are the words a programmer uses in a program Some identifiers are already defined. Some are made up by the programmer:

Identifiers. Identifiers are the words a programmer uses in a program Some identifiers are already defined. Some are made up by the programmer: C1 D6 Obj: cont. 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 1.9 (Short Answers) Chapter 1 Test in two class days!! Do Now: How is the

More information

Algorithms and Programming I. Lecture#12 Spring 2015

Algorithms and Programming I. Lecture#12 Spring 2015 Algorithms and Programming I Lecture#12 Spring 2015 Think Python How to Think Like a Computer Scientist By :Allen Downey Installing Python Follow the instructions on installing Python and IDLE on your

More information

A SHORT COURSE ON C++

A SHORT COURSE ON C++ Introduction to A SHORT COURSE ON School of Mathematics Semester 1 2008 Introduction to OUTLINE 1 INTRODUCTION TO 2 FLOW CONTROL AND FUNCTIONS If Else Looping Functions Cmath Library Prototyping Introduction

More information

Welcome to CS 115 (Winter 2018)

Welcome to CS 115 (Winter 2018) Welcome to CS 115 (Winter 2018) Web page (the main information source): http://www.student.cs.uwaterloo.ca/ cs115/ Course Personnel: Contact information and office hours for all staff: instructors, ISAs

More information

CSE 230 Computer Science II (Data Structure) Introduction

CSE 230 Computer Science II (Data Structure) Introduction CSE 230 Computer Science II (Data Structure) Introduction Fall 2017 Stony Brook University Instructor: Shebuti Rayana Basic Terminologies Data types Data structure Phases of S/W development Specification

More information

How to Think Like a Computer Scientist: Learning with Python 3»

How to Think Like a Computer Scientist: Learning with Python 3» How to Think Like a Computer Scientist: Learning with Python 3» previous next index 1. The way of the program The goal of this book is to teach you to think like a computer scientist. This way of thinking

More information

CS164: Midterm I. Fall 2003

CS164: Midterm I. Fall 2003 CS164: Midterm I Fall 2003 Please read all instructions (including these) carefully. Write your name, login, and circle the time of your section. Read each question carefully and think about what s being

More information

LESSON 13: LANGUAGE TRANSLATION

LESSON 13: LANGUAGE TRANSLATION LESSON 13: LANGUAGE TRANSLATION Objective Interpreters and Compilers. Language Translation Phases. Interpreters and Compilers A COMPILER is a program that translates a complete source program into machine

More information

Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language. Dr. Amal Khalifa. Lecture Contents:

Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language. Dr. Amal Khalifa. Lecture Contents: Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language Dr. Amal Khalifa Lecture Contents: Introduction to C++ Origins Object-Oriented Programming, Terms Libraries and Namespaces

More information

Informatica 3 Syntax and Semantics

Informatica 3 Syntax and Semantics Informatica 3 Syntax and Semantics Marcello Restelli 9/15/07 Laurea in Ingegneria Informatica Politecnico di Milano Introduction Introduction to the concepts of syntax and semantics Binding Variables Routines

More information

To become familiar with array manipulation, searching, and sorting.

To become familiar with array manipulation, searching, and sorting. ELECTRICAL AND COMPUTER ENGINEERING 06-88-211: COMPUTER AIDED ANALYSIS LABORATORY EXPERIMENT #2: INTRODUCTION TO ARRAYS SID: OBJECTIVE: SECTIONS: Total Mark (out of 20): To become familiar with array manipulation,

More information

Variables. Data Types.

Variables. Data Types. Variables. Data Types. The usefulness of the "Hello World" programs shown in the previous section is quite questionable. We had to write several lines of code, compile them, and then execute the resulting

More information