Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering

Size: px
Start display at page:

Download "Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering"

Transcription

1 Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering Lecture 3 Winter 2011/12 Oct 25

2 Visual C++: Problems and Solutions New section on web page (scroll down) Some typical problems we experienced with VC++ and solutions to fix them Will be extended if necessary Carsten Gutwenger: Object-oriented Programming 2

3 Loops Continued do-while-loops: Similar as while-loops, but the condition is evaluated after each iteration. The general form is: do statement; while ( condition ); statement is executed before condition is evaluated. If condition evaluates to false, the loop is terminated. statement is executed at least once! Carsten Gutwenger: Object-oriented Programming 3

4 Example: Sum up numbers until 0 is entered #include <iostream> using namespace std; int main() { int number, sum = 0; do { cin >> number; sum = sum + number; } while (number!= 0); cout << "sum = " << sum << endl; } return 0; Carsten Gutwenger: Object-oriented Programming 4

5 A typical pattern for while-loops We often use while-loops of the following form: int counter = 0; while (counter < n) { // // do something // counter = counter + 1; } Initialization Loop-condition Iteration There is a special syntax for writing such kinds of while-loops! Carsten Gutwenger: Object-oriented Programming 5

6 for-loops The general form is: Semantics: for ( init-statement; condition; iter-statement ) body-statement; 1.First init-statement is executed (only once!) 2.Then condition is evaluated: false terminate loop 3.Then body-statement is executed. 4.Then iter-statement is executed. 5.Go to step 2. Carsten Gutwenger: Object-oriented Programming 6

7 Example: Print first n square numbers int n = 10; /* for example */ for (int i = 1; i <= n; i = i + 1) cout << i * i << endl; This is equivalent to: int n = 10; /* for example */ int i = 1; while (i <= n) { cout << i * i << endl; i = i + 1; } Carsten Gutwenger: Object-oriented Programming 7

8 Transforming for-loops into while-loops for(init-stat; cond; iter-stat) { body-statement-1; body-statement-n; } { } init-stat; while( cond ) { body-statement-1; body-statement-n; iter-stat; } We will understand the block around the while-statement next time when discussing scope and lifetime of variables! Carsten Gutwenger: Object-oriented Programming 8

9 The break-statement Used to terminate a loop at some place in the body of the loop. Syntax: break; Semantics: Terminates the nearest enclosing while-, do-while-, or for-loop statement. Example: for (int i = 1; i <= 100; i = i + 1) { } int x; cin >> x; if (x == 0) break; cout << 100 / x << endl; Carsten Gutwenger: Object-oriented Programming 9

10 The continue-statement Used to terminate an iteration of a loop. Syntax: Semantics: Terminates the current iteration of the nearest enclosing while-, do-while-, or for-loop statement. Example: continue; for (int i = 1; i <= 100; i = i + 1) { } int x; cin >> x; if (x == 0) continue; cout << 100 / x << endl; Carsten Gutwenger: Object-oriented Programming 10

11 Strings Strings (texts) can be stored in variables of type std::string. std::string is part of the C++ standard library, not the C++ language itself. We have to include this additional functionality first: #include <string> String literals have to be enclosed in quotation marks " " std::string name; name = "Carsten"; Carsten Gutwenger: Object-oriented Programming 11

12 Using Strings We can use std::string almost like a built-in type: Initialization: std::string name = "Carsten" Comparing for equality with == Assignment using = Concatenation using + Example: string name = "Gutwenger"; string firstname = "Carsten"; name = firstname + " " + name; cout << "The name is " << name << endl; if(name == "Carsten Gutwenger") cout << "That's me!" << endl; Carsten Gutwenger: Object-oriented Programming 12

13 Warning Don t compare string literals! if ("abc" == "abc") cout << "Undefined if we get here!" << endl; Carsten Gutwenger: Object-oriented Programming 13

14 Special Characters Within string literals, you can use the following special characters: \n newline character \t tab stop character \" quotation mark \\ backslash character Example: "This \"string\"\ngoes over two lines" Carsten Gutwenger: Object-oriented Programming 14

15 Output formatting C++ supports various manipulators for nicely formatting output. You need to include this special functionality: #include <iomanip> Manipulators are inserted into the output stream (with the output operator <<) just as you print data. The following manipulators are useful for integers: setw(n): sets the number n of characters to be used as field width for the next insert operation. left: output is left-aligned in the output field. right: output is right-aligned in the output field. Carsten Gutwenger: Object-oriented Programming 15

16 Example: Formatting Output #include <iostream> #include <iomanip> using namespace std; int main() { int a = 7, b = 12345; cout << left; cout << setw(10) << a << "***" << endl; cout << setw(10) << b << "***" << endl; cout << right; cout << setw(10) << a << "***" << endl; cout << setw(10) << b << "***" << endl; Output: 7 *** *** 7*** 12345*** 10 characters } return 0; Carsten Gutwenger: Object-oriented Programming 16

17 The bool Data Type Variables of type bool store one of two possible values: true and false Example: bool found = true; bool isgreater = ( a > b ); // a and b are variables Operators for Boolean expressions: logical AND: && logical OR: logical NOT:! Example:!found ( a > b && a < 2*b ) Carsten Gutwenger: Object-oriented Programming 17

18 Printing bool values By default, bool values are printed as 0 or 1 (corresponding to false or true). You can change this behavior with manipulators! boolalpha: print false or true noboolalpha: print 0 or 1 Example: bool b = true; cout << b << endl; cout << boolalpha << b << endl; cout << noboolalpha << b << endl; Output: 1 true 1 Carsten Gutwenger: Object-oriented Programming 18

19 Preparations for next week Floating-point numbers (float, double) Increment and Decrement (e.g. ++, += operators) Scope and lifetime of variables C++-Vectors (std::vector) Carsten Gutwenger: Object-oriented Programming 19

THE INTEGER DATA TYPES. Laura Marik Spring 2012 C++ Course Notes (Provided by Jason Minski)

THE INTEGER DATA TYPES STORAGE OF INTEGER TYPES IN MEMORY All data types are stored in binary in memory. The type that you give a value indicates to the machine what encoding to use to store the data in

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

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

BITG 1233: Introduction to C++

BITG 1233: Introduction to C++ 1 Learning Outcomes At the end of this lecture, you should be able to: Identify basic structure of C++ program (pg 3) Describe the concepts of : Character set. (pg 11) Token

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

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

Input and Output. Data Processing Course, I. Hrivnacova, IPN Orsay

Input and Output Data Processing Course, I. Hrivnacova, IPN Orsay Output to the Screen Input from the Keyboard IO Headers Output to a File Input from a File Formatting I. Hrivnacova @ Data Processing Course

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

Chapter 1 File Extensions: Source code (cpp), Object code (obj), and Executable code (exe). Preprocessor processes directives and produces modified source Compiler takes modified source and produces object

2 nd Week Lecture Notes

2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous

LECTURE 02 INTRODUCTION TO C++

PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 02 INTRODUCTION

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol.

1- Write a single C++ statement that: A. Calculates the sum of the two integrates 11 and 12 and outputs the sum to the consol. B. Outputs to the console a floating point number f1 in scientific format

Engineering Problem Solving with C++, 3e Chapter 2 Test Bank

1. Match each of the following data types with literal constants of that data type. A data type can be used more than once. A. integer B 1.427E3 B. double D "Oct" C. character B -63.29 D. string F #Hashtag

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Computer Programming Basic Control Flow - Loops Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To learn about the three types of loops: while for do To avoid infinite

5.1. Chapter 5: The Increment and Decrement Operators. The Increment and Decrement Operators. The Increment and Decrement Operators

Chapter 5: 5.1 Looping The Increment and Decrement Operators The Increment and Decrement Operators The Increment and Decrement Operators ++ is the increment operator. It adds one to a variable. val++;

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays

Tutorial 13 Salary Survey Application: Introducing One- Dimensional Arrays Outline 13.1 Test-Driving the Salary Survey Application 13.2 Introducing Arrays 13.3 Declaring and Initializing Arrays 13.4 Constructing

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

Week 1: Introduction to C++ Gaddis: Chapter 2 (excluding 2.1, 2.11, 2.14) CS 1428 Fall 2014 Jill Seaman Literals A literal represents a constant value used in a program statement. Numbers: 0, 34, 3.14159,

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

The cin Object. cout << "Enter the length and the width of the rectangle? "; cin >> length >> width;

The cin Object Short for console input. It is used to read data typed at the keyboard. Must include the iostream library. When this instruction is executed, it waits for the user to type, it reads the

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

Numerical Computing in C and C++ Jamie Griffin. Semester A 2017 Lecture 2

Numerical Computing in C and C++ Jamie Griffin Semester A 2017 Lecture 2 Visual Studio in QM PC rooms Microsoft Visual Studio Community 2015. Bancroft Building 1.15a; Queen s W207, EB7; Engineering W128.D.

Introduction to Programming EC-105. Lecture 2

Introduction to Programming EC-105 Lecture 2 Input and Output A data stream is a sequence of data - Typically in the form of characters or numbers An input stream is data for the program to use - Typically

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

Fundamentals of Programming CS-110. Lecture 2

Fundamentals of Programming CS-110 Lecture 2 Last Lab // Example program #include using namespace std; int main() { cout

Objects and streams and files CS427: Elements of Software Engineering

Objects and streams and files CS427: Elements of Software Engineering Lecture 6.2 (C++) 10am, 13 Feb 2012 CS427 Objects and streams and files 1/18 Today s topics 1 Recall...... Dynamic Memory Allocation...

Introduction to C++ Lecture Set 2. Introduction to C++ Week 2 Dr Alex Martin 2013 Slide 1

Introduction to C++ Lecture Set 2 Introduction to C++ Week 2 Dr Alex Martin 2013 Slide 1 More Arithmetic Operators More Arithmetic Operators In the first session the basic arithmetic operators were introduced.

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

Chapter 2: Introduction to C++

Chapter 2: Introduction to C++ Copyright 2010 Pearson Education, Inc. Copyright Publishing as 2010 Pearson Pearson Addison-Wesley Education, Inc. Publishing as Pearson Addison-Wesley 2.1 Parts of a C++

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

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

! 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

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

PIC 10A Flow control. Ernest Ryu UCLA Mathematics

PIC 10A Flow control Ernest Ryu UCLA Mathematics If statement An if statement conditionally executes a block of code. # include < iostream > using namespace std ; int main () { double d1; cin >> d1; if

Week 3: File I/O and Formatting 3.7 Formatting Output

Week 3: File I/O and Formatting 3.7 Formatting Output Formatting: the way a value is printed: Gaddis: 3.7, 3.8, 5.11 CS 1428 Fall 2014 Jill Seaman spacing decimal points, fractional values, number of digits

C++ PROGRAMMING. For Industrial And Electrical Engineering Instructor: Ruba A. Salamh

C++ PROGRAMMING For Industrial And Electrical Engineering Instructor: Ruba A. Salamh CHAPTER TWO: Fundamental Data Types Chapter Goals In this chapter, you will learn how to work with numbers and text,

The American University in Cairo Department of Computer Science & Engineering CSCI &09 Dr. KHALIL Exam-I Fall 2011

The American University in Cairo Department of Computer Science & Engineering CSCI 106-07&09 Dr. KHALIL Exam-I Fall 2011 Last Name :... ID:... First Name:... Form I Section No.: EXAMINATION INSTRUCTIONS

C++ basics Getting started with, and Data Types.

C++ basics Getting started with, and Data Types pm_jat@daiict.ac.in Recap Last Lecture We talked about Variables - Variables, their binding to type, storage etc., Categorization based on storage binding

Name SECTION: 12:45 2:20. True or False (12 Points)

Name SECION: 12:45 2:20 rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables

WARM UP LESSONS BARE BASICS

WARM UP LESSONS BARE BASICS CONTENTS Common primitive data types for variables... 2 About standard input / output... 2 More on standard output in C standard... 3 Practice Exercise... 6 About Math Expressions

1) What of the following sets of values for A, B, C, and D would cause the string "one" to be printed?

Instructions: This homework assignment focuses primarily on some of the basic syntax and semantics of C++. The answers to the following questions can be determined from Chapters 6 and 7 of the lecture

CS 101 Computer Programming and utilization. Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay

CS 101 Computer Programming and utilization Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building Bombay Lecture 4, Conditional execution of instructions Friday, August

causing a set of statements (the body) to be executed repeatedly. C++ provides three control structures to support iteration (or looping).

1 causing a set of statements (the body) to be executed repeatedly. C++ provides three control structures to support iteration (or looping). Before considering specifics we define some general terms that

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

Week 2. Relational Operators. Block or compound statement. if/else. Branching & Looping. Gaddis: Chapters 4 & 5. CS 5301 Spring 2018.

Week 2 Branching & Looping Gaddis: Chapters 4 & 5 CS 5301 Spring 2018 Jill Seaman 1 Relational Operators l relational operators (result is bool): == Equal to (do not use =)!= Not equal to > Greater than

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

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

Objectives. In this chapter, you will:

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 arithmetic expressions Learn about

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

Introduction to C++ Dr M.S. Colclough, research fellows, pgtas

Introduction to C++ Dr M.S. Colclough, research fellows, pgtas 5 weeks, 2 afternoons / week. Primarily a lab project. Approx. first 5 sessions start with lecture, followed by non assessed exercises in

1 Unit 8 'for' Loops

1 Unit 8 'for' Loops 2 Control Structures We need ways of making decisions in our program To repeat code until we want it to stop To only execute certain code if a condition is true To execute one segment

Your First C++ Program. September 1, 2010

Your First C++ Program September 1, 2010 Your First C++ Program //*********************************************************** // File name: hello.cpp // Author: Bob Smith // Date: 09/01/2010 // Purpose:

CPE 112 Spring 2015 Exam III (100 pts) April 8, True or False (12 Points)

Name rue or False (12 Points) 1. (12 pts) Circle for true and F for false: F a) Local identifiers have name precedence over global identifiers of the same name. F b) Local variables retain their value

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

Introduction to C++ (Extensions to C)

Introduction to C++ (Extensions to C) C is purely procedural, with no objects, classes or inheritance. C++ is a hybrid of C with OOP! The most significant extensions to C are: much stronger type checking.

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

Name Closed notes, book and neighbor. If you have any questions ask them. Notes: Segment of code necessary C++ statements to perform the action described not a complete program Program a complete C++ program

Increment and the While. Class 15

Increment and the While Class 15 Increment and Decrement Operators Increment and Decrement Increase or decrease a value by one, respectively. the most common operation in all of programming is to increment

Chapter 2: Overview of C++

Chapter 2: Overview of C++ Problem Solving, Abstraction, and Design using C++ 6e by Frank L. Friedman and Elliot B. Koffman C++ Background Introduced by Bjarne Stroustrup of AT&T s Bell Laboratories in

Chapter Four: Loops. Slides by Evan Gallagher. C++ for Everyone by Cay Horstmann Copyright 2012 by John Wiley & Sons. All rights reserved

Chapter Four: Loops Slides by Evan Gallagher The Three Loops in C++ C++ has these three looping statements: while for do The while Loop while (condition) { statements } The condition is some kind of test

CSI33 Data Structures

Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018 Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 More on Arithmetic Expressions The following two are equivalent:! x = x + 5;

Looping. Arizona State University 1

Looping CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 5 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

Sample Code: OUTPUT Daily Highs & Lows

Name1: Name2: Class Day / Time: Due Date: Sample Code: OUTPUT Daily Highs & Lows This program will obtain from the user 3 sets of data including a date, the high temperature and a low temperature for that

CHAPTER 3 BASIC INSTRUCTION OF C++

CHAPTER 3 BASIC INSTRUCTION OF C++ MOHD HATTA BIN HJ MOHAMED ALI Computer programming (BFC 20802) Subtopics 2 Parts of a C++ Program Classes and Objects The #include Directive Variables and Literals Identifiers

C++ Programming Lecture 7 Control Structure I (Repetition) Part I

C++ Programming Lecture 7 Control Structure I (Repetition) Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department while Repetition Structure I Repetition structure Programmer

CS2141 Software Development using C/C++ C++ Basics

CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short

Why Is Repetition Needed?

Why Is Repetition Needed? Repetition allows efficient use of variables. It lets you process many values using a small number of variables. For example, to add five numbers: Inefficient way: Declare a variable

Unit 7. 'while' Loops

1 Unit 7 'while' Loops 2 Control Structures We need ways of making decisions in our program To repeat code until we want it to stop To only execute certain code if a condition is true To execute one segment

C++ Support Classes (Data and Variables)

C++ Support Classes (Data and Variables) School of Mathematics 2018 Today s lecture Topics: Computers and Programs; Syntax and Structure of a Program; Data and Variables; Aims: Understand the idea of programming

Engineering Problem Solving with C++, Etter/Ingber

Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs C++, Second Edition, J. Ingber 1 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input

CS302 - Data Structures using C++

CS302 - Data Structures using C++ Pre-Course: Variables, Basic Types, Control Structures Kostas Alexis Slides inspired by the course Modern C++, Uni Bonn: http://www.ipb.uni-bonn.de/teaching/modern-cpp/

PIC 10A. Review for Midterm I

PIC 10A Review for Midterm I Midterm I Friday, May 1, 2.00-2.50pm. Try to show up 5 min early so we can start on time. Exam will cover all material up to and including todays lecture. (Only topics that

causing a set of statements (the body) to be executed repeatedly. C++ provides three control structures to support iteration (or looping).

Iteration Iteration causing a set of statements (the body) to be executed repeatedly. 1 C++ provides three control structures to support iteration (or looping). Before considering specifics we define some

Basic program The following is a basic program in C++; Basic C++ Source Code Compiler Object Code Linker (with libraries) Executable

Basic C++ Overview C++ is a version of the older C programming language. This is a language that is used for a wide variety of applications and which has a mature base of compilers and libraries. C++ is

J. P. Cohoon and J. W. Davidson 1999 McGraw-Hill, Inc. Control Constructs. Mechanisms for deciding when and how often an action should be taken

J. P. Cohoon and J. W. Davidson 1999 McGraw-Hill, Inc. Control Constructs Mechanisms for deciding when and how often an action should be taken Ch 4 / Foil 2 Boolean Algebra Logical expressions have the

Lab # 02. Basic Elements of C++ _ Part1

Lab # 02 Basic Elements of C++ _ Part1 Lab Objectives: After performing this lab, the students should be able to: Become familiar with the basic components of a C++ program, including functions, special

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

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

READ THIS NOW! Do not start the test until instructed to do so!

READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties. Failure to adhere to these directions will not constitute an excuse or defense. Print your name in the space

CSCI 123 Introduction to Programming Concepts in C++

CSCI 123 Introduction to Programming Concepts in C++ Brad Rippe C++ Basics C++ layout Include directive #include using namespace std; int main() { } statement1; statement; return 0; Every program

do { statements } while (condition);

Topic 4 1. The while loop 2. Problem solving: hand-tracing 3. The for loop 4. The do loop 5. Processing input 6. Problem solving: storyboards 7. Common loop algorithms 8. Nested loops 9. Problem solving:

Input And Output of C++

Input And Output of C++ Input And Output of C++ Seperating Lines of Output New lines in output Recall: "\n" "newline" A second method: object endl Examples: cout

CSC Web Programming. Introduction to JavaScript

CSC 242 - Web Programming Introduction to JavaScript JavaScript JavaScript is a client-side scripting language the code is executed by the web browser JavaScript is an embedded language it relies on its

EP578 Computing for Physicists

EP578 Computing for Physicists Topic 3 Selection & Loops Department of Engineering Physics University of Gaziantep Course web page wwwgantepedutr/~bingul/ep578 Oct 2011 Sayfa 1 1 Introduction This lecture

CMPS 221 Sample Final

Name: 1 CMPS 221 Sample Final 1. What is the purpose of having the parameter const int a[] as opposed to int a[] in a function declaration and definition? 2. What is the difference between cin.getline(str,

CS242 COMPUTER PROGRAMMING

CS242 COMPUTER PROGRAMMING I.Safa a Alawneh Variables Outline 2 Data Type C++ Built-in Data Types o o o o bool Data Type char Data Type int Data Type Floating-Point Data Types Variable Declaration Initializing

CSc Introduc/on to Compu/ng. Lecture 8 Edgardo Molina Fall 2011 City College of New York

CSc 10200 Introduc/on to Compu/ng Lecture 8 Edgardo Molina Fall 2011 City College of New York 18 The Null Statement Null statement Semicolon with nothing preceding it ; Do-nothing statement required for

Week 2: Console I/O and Operators Arithmetic Operators. Integer Division. Arithmetic Operators. Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.

Week 2: Console I/O and Operators Gaddis: Chapter 3 (2.14,3.1-6,3.9-10,5.1) CS 1428 Fall 2014 Jill Seaman 1 2.14 Arithmetic Operators An operator is a symbol that tells the computer to perform specific

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

Types, Values, Variables & Assignment. EECS 211 Winter 2018

Types, Values, Variables & Assignment EECS 211 Winter 2018 2 Road map Strings and string I/O Integers and integer I/O Types and objects * Type safety * Not as in object orientation we ll get to that much

CS 151 Review #3. // More than one variable can be defined // in a statement. Multiple variables are // separated by a comma.

REVIEW cout Statement The cout statement invokes an output stream, which is a sequence of characters to be displayed to the screen. cout

Chapter 2 C++ Fundamentals

Chapter 2 C++ Fundamentals 3rd Edition Computing Fundamentals with C++ Rick Mercer Franklin, Beedle & Associates Goals Reuse existing code in your programs with #include Obtain input data from the user

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++ 2017 Spring Exam 1 Monday, February 13, 2017 Total - 100 Points B Instructions: Total of 11 pages, including this cover and the last page. Before starting the exam,

CSCE 206: Structured Programming in C++

CSCE 206: Structured Programming in C++ 2017 Spring Exam 1 Monday, February 13, 2017 Total - 100 Points A Instructions: Total of 11 pages, including this cover and the last page. Before starting the exam,

Introduction to Programming

Introduction to Programming Summer Term 2015 Dr. Adrian Kacso, Univ. Siegen adriana.dkacsoa@duni-siegena.de Tel.: 0271/740-3966, Office: H-B 8406 State: May 6, 2015 Betriebssysteme / verteilte Systeme

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi and Cyrill Stachniss

Modern C++ for Computer Vision and Image Processing Igor Bogoslavskyi and Cyrill Stachniss Outline Intro to C++ Variables and basic types Built-in types Strings Vector and array Control structures If statement

CS31 Discussion 1E. Jie(Jay) Wang Week3 Oct.12

CS31 Discussion 1E Jie(Jay) Wang Week3 Oct.12 Outline Problems from Project 1 Review of lecture String, char, stream If-else statements Switch statements loops Programming challenge Problems from Project

READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties. Do not start the test until instructed to do so!

READ THIS NOW! Failure to read and follow the instructions below may result in severe penalties. Print your name in the space provided below. Print your name and ID number on the Opscan form; be sure to

ME240 Computation for Mechanical Engineering. Lecture 4. C++ Data Types

ME240 Computation for Mechanical Engineering Lecture 4 C++ Data Types Introduction In this lecture we will learn some fundamental elements of C++: Introduction Data Types Identifiers Variables Constants