Introduction to Programming

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

Download "Introduction to Programming"

Transcription

1 Introduction to Programming SS 2012 Adrian Kacso, Univ. Siegen Tel.: 0271/ , Office: H-B 8406 Stand: April 25, 2012 Betriebssysteme / verteilte Systeme Introduction to Programming (1) i Introduction to Programming SS Statements Betriebssysteme / verteilte Systeme Introduction to Programming (1) 53

2 3 Statements... Contents Expressions Operators Input and output if statement Exception handling Betriebssysteme / verteilte Systeme Introduction to Programming (1) 54 3 Statements... Statements Variables are the program s data Statements specify what to do with the data Different kinds of statements: each expression is a statement always terminated with a ; e.g. assignment: x = a + b; compound statement: { list-of-statements empty statement: (white space and/or ; ) A program executes main() s compound statement, from the begining to the end Betriebssysteme / verteilte Systeme Introduction to Programming (1) 55

3 3.1 Expressions Expressions Anything that returns a value is an expression in C++ An operator is a symbol that causes the program to perform an operation (e.g., + for the summation) The assignment operator = changes the value of the left operand to the value of the expression on the right side Example: x = a + b; Note: in C++, an assignment again is an expression Example: x = (y = a) + b; (bad programming style!) Betriebssysteme / verteilte Systeme Introduction to Programming (1) Expressions... l-values and r-values l-value: anything that can be used on the left side of an assignment i.e. everything that represents a storage that can be altered e.g. a variable r-value: anything that can be used on the right side of an assignment i.e. everything that has / returns a value e.g. an expression (all l-values are also r-values) Example: 35 = x is not correct, 35 is not an l-value Betriebssysteme / verteilte Systeme Introduction to Programming (1) 57

4 3.1 Expressions... Mathematical operators On floats: + - * / On integers: + - * / % (plus some more...) / is the integer division: 21 / 4 5 % is the modulo operation: 21 % 4 1 Betriebssysteme / verteilte Systeme Introduction to Programming (1) Expressions... Combined assignment and arithmetic Common case of an assignment: myage = myage + 2; Short form: myage += 2; Also defined: -= *= /= %= Beware: if the meaning of the combined operators is not obvious, then you better write it explicitly! Betriebssysteme / verteilte Systeme Introduction to Programming (1) 59

5 3.1 Expressions... Increment and decrement c = c + 1 is the same as c++ language name! c = c - 1 is the same as c-- ++ and -- are operators with a side effect Beware: prefix and postfix operators: Prefix: ++c returns the incremented value Postfix: c++ returns the old (not yet incremented) value Examples: x = 5; a = x++; afterwards, a is 5, and x is 6 x = 5; a = ++x; afterwards, a is 6, and x is 6 Betriebssysteme / verteilte Systeme Introduction to Programming (1) Expressions... Precedence Defines the order in which operators are evaluated * / % have higher precedence ( priority ) then + - arithmetic operators with the same precedence go from left to right assignment operators go from right to left! parentheses ( ) override precedence Examples: x = * 9; x = (5 + 3) - (8 * 9); x = y = z = 0; x = (y = (z = 0)); Betriebssysteme / verteilte Systeme Introduction to Programming (1) 61

6 3.1 Expressions... Precedence Use precendence only for * / % + - (common sense) 2. Forget about the rest of precendence rules and use parentheses! Betriebssysteme / verteilte Systeme Introduction to Programming (1) Expressions... Bit operations Reminder: in a computer, all data (like, e.g., numbers) is stored in a binary form e.g., 291 = C++ defines some operators in integers, which directly work on the bit representation ~ & ^ : bitwise NOT, AND, OR, and XOR << >> : left shift, right shift Examples: 1 2 equals 3, 11 & ~1 equals 10 1 << 4 equals 16, 31 >> 1 equals 15 Betriebssysteme / verteilte Systeme Introduction to Programming (1) 63

7 3.1 Expressions... Use of bit operations Setting / resetting a bit (e.g., in a control register of a hardware device) Examples: x = 128; sets bit 7 in x x &= ~16; resets bit 4 in x Extracting bit-fields e.g.: assume that bits of a value x contain an (unsigned) 4-bit number y = (x >> 5) & 15; stores the value of this field into y Fast division and multiplication x << 2 is the same as x * 4 x >> 1 is the same as x / 2, if x is positive Betriebssysteme / verteilte Systeme Introduction to Programming (1) Expressions... Relational operators name op example result example result equals == 100 == 50 false 100 == 100 true not equals!= 100!= 50 true 100!= 100 false greater than > 100 > 50 true 100 > 100 false greater or equal >= 100 >= 50 true 100 >= 100 true less than < 100 < 50 false 100 < 100 false less or equal <= 100 <= 50 false 100 <= 100 true Betriebssysteme / verteilte Systeme Introduction to Programming (1) 65

8 3.2 Input and Output Writing to the terminal window You can print the value of one or more expressions: cout << expression ; cout << expression 1 << expression 2 ;... Printing a line feed: cout << endl; Example: cout << 5 << 7 << "Hello" << endl; cout << " " << = << " " << ; cout << " and PI = " << << endl; This code will print: 57Hello = 21 and PI = Betriebssysteme / verteilte Systeme Introduction to Programming (1) Input and Output... Reading from the terminal window You can read a value from the terminal into a variable: cin >> variable ; The statement reads the maximum number of characters appropriate for the varible s type usually, input is delimited by the return-key (new-line) if no legal characters could be read, the variable is not assigned ( 10) Example: int i, j; char c; double d; cin >> i; cin >> j; cin >> c; cin >> d; When the user types , the result will be i = 30; j = -421; c =. ; d = 5.2; Betriebssysteme / verteilte Systeme Introduction to Programming (1) 67

9 3.2 Input and Output... Using input and output in a program You have to include the file with the declarations of the variables cin and cout: #include <iostream> The names cin and cout live in a namespace called std, thus, you should declare using namespace std; Betriebssysteme / verteilte Systeme Introduction to Programming (1) The if Statement The if statement Normally, statements are executed in the order they appear in the program (top to bottom). Sometimes, statements shall only be executed if some condition holds: if ( expression ) // If condition is true, statement; // execute the statement Example: if ( new_value < minimum ) minimum = new_value; Note that statement; can be replaced by a compound statement Betriebssysteme / verteilte Systeme Introduction to Programming (1) 69

10 3.3 The if Statement... The else clause Often, some statement shall be excuted if a condition holds, and some other code, if not Example: if ( a < b ) minimum = a; if ( b < a ) minimum = b; // What is wrong here? Betriebssysteme / verteilte Systeme Introduction to Programming (1) The if Statement... The else clause... Often, some statement shall be excuted if a condition holds, and some other code, if not: if ( expression ) // If the condition is true, statement 1 ; // execute statement 1, else // if not, statement 2 ; // execute statement 2. Example: if ( a < b ) minimum = a; else minimum = b; // also if a == b! Betriebssysteme / verteilte Systeme Introduction to Programming (1) 71

11 3.3 The if Statement... Expressions used for if (sorry for that!) Every numerical value is allowed : 0 means false everything else (usually 1) means true (That is a heritage from the C language... ) However: only use meaningful (i.e., Boolean) expressions! For example, use if ( minimum!= 0 )... rather than if ( minimum )... Betriebssysteme / verteilte Systeme Introduction to Programming (1) The if Statement... Nested if statements What does this program print to cout? int main() { bool a = true, b = false; if ( a ) if ( b ) cout << "a and b\n"; else cout << "not a\n"; return 0; Always use { and for if and else clauses! Betriebssysteme / verteilte Systeme Introduction to Programming (1) 73

12 3.3 The if Statement... Nested if statements... The corrected program: int main() { bool a = true, b = false; if ( a ) { if ( b ) { cout << "a and b\n"; else { cout << "not a\n"; return 0; Betriebssysteme / verteilte Systeme Introduction to Programming (1) The if Statement... More complex conditions Logical Operators: Examples: Operator Symbol Usage and && expression1 && expression2 or expression1 expression2 not!!expression if ( (x == 5) && (y == 5) )... if ( (x == 5) (y == 5) )... if (!(x == 5) )... same as if ( x!= 5 )... Betriebssysteme / verteilte Systeme Introduction to Programming (1) 75

13 3.4 Summary Statements Variables are the program s data Statements specify what to do with the data Different kinds of statements: each expression is a statement always terminated with a ; e.g. assignment: x = a + b; compound statement: { list-of-statements empty statement: { or just a ; A program executes main() s compound statement, from the begining to the end Betriebssysteme / verteilte Systeme Introduction to Programming (1) Summary... Expressions Anything that returns a value is an expression in C++ An operator is a symbol that causes the program to perform an operation (e.g., + for the summation) The assignment operator = changes the value of the left operand to the value of the expression on the right side Examples: 3 x = a + b * (c - 34) % 2 myage += 2 c d x (1 << 7) Betriebssysteme / verteilte Systeme Introduction to Programming (1) 77

14 3.4 Summary... Reminder: if Statement int main() { bool a = true, b = false; if ( a ) { if ( b ) { cout << "a and b\n"; else { cout << "not a\n"; return 0; Betriebssysteme / verteilte Systeme Introduction to Programming (1) Summary... What we have so far Variables: data types and names Statements: operations on data (e.g., if) cout and cin The main function Now: functions in detail Betriebssysteme / verteilte Systeme Introduction to Programming (1) 79

Introduction to Programming

Introduction to Programming Introduction to Programming SS 2012 Adrian Kacso, Univ. Siegen adriana.dkacsoa@duni-siegena.de Tel.: 0271/740-3966, Office: H-B 8406 Stand: April 25, 2012 Betriebssysteme / verteilte Systeme Introduction

More information

Introduction to Programming

Introduction to Programming Introduction to Programming SS 2012 Adrian Kacso, Univ. Siegen adriana.dkacsoa@duni-siegena.de Tel.: 0271/740-3966, Office: H-B 8406 Stand: April 12, 2012 Betriebssysteme / verteilte Systeme Introduction

More information

A First Book of C++ Chapter 2 Data Types, Declarations, and Displays

A First Book of C++ Chapter 2 Data Types, Declarations, and Displays A First Book of C++ Chapter 2 Data Types, Declarations, and Displays Objectives In this chapter, you will learn about: Data Types Arithmetic Operators Variables and Declarations Common Programming Errors

More information

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

Chapter 4 Operators & Arithmetic

Chapter 4 Operators & Arithmetic Chapter 4 Operators & Arithmetic 4-1 Arithmetic in C++ Arithmetic expressions can be made up of constants, variables, operators and parentheses. The arithmetic operators in C++ are as follows + (addition)

More information

Adjusted/Modified by Nicole Tobias. Chapter 2: Basic Elements of C++

Adjusted/Modified by Nicole Tobias. Chapter 2: Basic Elements of C++ Adjusted/Modified by Nicole Tobias 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

More information

6.096 Lab 1. Due: 7 January 12:30:00. September 20, 2011

6.096 Lab 1. Due: 7 January 12:30:00. September 20, 2011 6.096 Lab 1 Due: 7 January 1:30:00 September 0, 011 1 Additional Material 1.1 Constants A constant is an expressions with a fixed value. Kinds of constants: Literals: used to express particular values

More information

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority) Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

More information

Chapter 8. Arithmetic in C++

Chapter 8. Arithmetic in C++ Christian Jacob Chapter 8 Arithmetic in C++ 8.1 The C++ Vocabulary 8.2 Variables and Types 8.2.1 Data Objects 8.2.2 Variables 8.2.3 Declaration of Variables 8.3 Elementary C++ Data Types 8.3.1 Integers

More information

Introduction to Programming

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

More information

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 2: Basic Elements of C++

C++ Programming: From Problem Analysis to Program Design, Fifth Edition. Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 2: Basic Elements of C++ Objectives In this chapter, you will: Become familiar with the basic components of a C++ program,

More information

Borland C++ Compiler: Operators

Borland C++ Compiler: Operators Introduction Borland C++ Compiler: Operators An operator is a symbol that specifies which operation to perform in a statement or expression. An operand is one of the inputs of an operator. For example,

More information

Chapter 2: Problem Solving Using C++

Chapter 2: Problem Solving Using C++ Chapter 2: Problem Solving Using C++ 1 Objectives In this chapter, you will learn about: Modular programs Programming style Data types Arithmetic operations Variables and declaration statements Common

More information

Part IA Computing Course Tutorial Guide to C++ Programming

Part IA Computing Course Tutorial Guide to C++ Programming Part IA Computing Course Tutorial Guide to C++ Programming Roberto Cipolla Department of Engineering University of Cambridge September 1, 2004 This document provides an introduction to computing and the

More information

Tutorial-3a: First steps with C++ programming

Tutorial-3a: First steps with C++ programming HTTP://WWW.HEP.LU.SE/COURSES/MNXB01 Introduction to Programming and Computing for Scientists (2015 HT) Tutorial-3a: First steps with C++ programming Programming for Scientists Tutorial 3a 1 / 17 Quick

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Lecture 2 Notes: Flow of Control

Lecture 2 Notes: Flow of Control 6.096 Introduction to C++ January, 2011 Massachusetts Institute of Technology John Marrero Lecture 2 Notes: Flow of Control 1 Motivation Normally, a program executes statements from first to last. The

More information

C++ Language Tutorial

C++ Language Tutorial cplusplus.com C++ Language Tutorial Written by: Juan Soulié Last revision: June, 2007 Available online at: http://www.cplusplus.com/doc/tutorial/ The online version is constantly revised and may contain

More information

Comp151. Definitions & Declarations

Comp151. Definitions & Declarations Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const

More information

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

More information

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void 1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of

More information

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures

The C++ Language. Loops. ! Recall that a loop is another of the four basic programming language structures The C++ Language Loops Loops! Recall that a loop is another of the four basic programming language structures Repeat statements until some condition is false. Condition False True Statement1 2 1 Loops

More information

6.087 Lecture 2 January 12, 2010

6.087 Lecture 2 January 12, 2010 6.087 Lecture 2 January 12, 2010 Review Variables and data types Operators Epilogue 1 Review: C Programming language C is a fast, small,general-purpose,platform independent programming language. C is used

More information

C++ Basics. C++ Basics: Names: Identifiers. Names: Identifiers. Display 2.1 A C++ Program (1 of 2) Display 2.1 A C++ Program (2 of 2)

C++ Basics. C++ Basics: Names: Identifiers. Names: Identifiers. Display 2.1 A C++ Program (1 of 2) Display 2.1 A C++ Program (2 of 2) C++ Basics C++ Basics: 2.1 Variables and Assignments Variables and Assignments Input and Output Data Types and Expressions Simple Flow of Control Program Style A C++ variable can hold a number or other

More information

Which of the following is the correct operator to compare two variables? A. := B. = C. equal D. ==

Which of the following is the correct operator to compare two variables? A. := B. = C. equal D. == Group 1 Question 1. What is the correct value to return to the operating system upon the successful completion of a program? A. -1 B. 1 C. 0 D. Programs do not return a value. Question 2. What is the only

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

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

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC Introduction to Programming (in C++) Loops Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC Example Assume the following specification: Input: read a number N > 0 Output:

More information

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification: Example Introduction to Programming (in C++) Loops Assume the following specification: Input: read a number N > 0 Output: write the sequence 1 2 3 N (one number per line) Jordi Cortadella, Ricard Gavaldà,

More information

Chapter One Introduction to Programming

Chapter One Introduction to Programming Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of

More information

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be...

What is a Loop? Pretest Loops in C++ Types of Loop Testing. Count-controlled loops. Loops can be... What is a Loop? CSC Intermediate Programming Looping A loop is a repetition control structure It causes a single statement or a group of statements to be executed repeatedly It uses a condition to control

More information

Primitive Data Types Summer 2010 Margaret Reid-Miller

Primitive Data Types Summer 2010 Margaret Reid-Miller Primitive Data Types 15-110 Summer 2010 Margaret Reid-Miller Data Types Data stored in memory is a string of bits (0 or 1). What does 1000010 mean? 66? 'B'? 9.2E-44? How the computer interprets the string

More information

Python to C/C++ Fall 2011

Python to C/C++ Fall 2011 Python to C/C++ Fall 2011 1. Main Program Python: Program code is indented after colon : def main(): body of program C/C++: Have more setup overhead. C: Both require #include directives to access libraries

More information

While Loop. 6. Iteration

While Loop. 6. Iteration While Loop 1 Loop - a control structure that causes a set of statements to be executed repeatedly, (reiterated). While statement - most versatile type of loop in C++ false while boolean expression true

More information

Control Structure. Pseudocode: Input number If number is even Then Print even Else print odd. Flowchart: Begin. End. Print Odd. number even?

Control Structure. Pseudocode: Input number If number is even Then Print even Else print odd. Flowchart: Begin. End. Print Odd. number even? Control Structure Normally, a program is executed in a sequential manner.however, in many cases, a program has to choose among alternative statements C++ provides constructs that enable the programmer

More information

Branching. We ll continue to look at the basics of writing C++ programs including. Overview

Branching. We ll continue to look at the basics of writing C++ programs including. Overview Branching Overview We ll continue to look at the basics of writing C++ programs including Boolean Expressions (need to know this before we can using branching and looping!) Branching J.S. Bradbury CSCI

More information

Conditions & Boolean Expressions

Conditions & Boolean Expressions Conditions & Boolean Expressions 1 In C++, in order to ask a question, a program makes an assertion which is evaluated to either true (nonzero) or false (zero) by the computer at run time. Example: In

More information

Lecture 1 Notes: Introduction

Lecture 1 Notes: Introduction Introduction to C++ January 4, 2011 Massachusetts Institute of Technology 6.096 Lecture 1 Notes: Introduction 1 Compiled Languages and C++ 1.1 Why Use a Language Like C++? At its core, a computer is just

More information

CS101 Computer programming and utilization

CS101 Computer programming and utilization CS101 Computer programming and utilization Dr Deepak B Phatak Subrao Nilekani Chair Professor Department of CSE, Kanwal Rekhi Building IIT Bombay Lecture 3, Basic features of C++ Tuesday, 2 August 2011

More information

MS Visual C++ Introduction. Quick Introduction. A1 Visual C++

MS Visual C++ Introduction. Quick Introduction. A1 Visual C++ MS Visual C++ Introduction 1 Quick Introduction The following pages provide a quick tutorial on using Microsoft Visual C++ 6.0 to produce a small project. There should be no major differences if you are

More information

Final Exam Review. CS 1428 Fall Jill Seaman. Final Exam

Final Exam Review. CS 1428 Fall Jill Seaman. Final Exam Final Exam Review CS 1428 Fall 2011 Jill Seaman 1 Final Exam Friday, December 9, 11:00am to 1:30pm Derr 241 (here) Closed book, closed notes, clean desk Comprehensive (covers entire course) 25% of your

More information

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions Phys4051: C Lecture 2 & 3 Functions (Review) Comment Statements Variables & Operators Branching Instructions Comment Statements! Method 1: /* */! Method 2: // /* Single Line */ //Single Line /* This comment

More information

2.2: Bitwise Logical Operations

2.2: Bitwise Logical Operations 2.2: Bitwise Logical Operations Topics: Introduction: logical operations in C/C++ logical operations in MIPS In 256 lecture, we looked at bitwise operations in C/C++ and MIPS. We ll look at some simple

More information

Punctuation in C. Identifiers and Expressions. Identifiers. Variables. Keywords. Identifier Examples

Punctuation in C. Identifiers and Expressions. Identifiers. Variables. Keywords. Identifier Examples Identifiers and Expressions CSE 130: Introduction to C Programming Spring 2005 Punctuation in C Statements are terminated with a ; Groups of statements are enclosed by curly braces: { and } Commas separate

More information

Each statement is ended by a semi-colon (;). The formatting is free.

Each statement is ended by a semi-colon (;). The formatting is free. Example 1 cout x; double err, tol=1e-12, x1; int it, maxit=100; it = 0; err = tol + 1; while( err > tol && it < maxit ) x1 = x - (x-cos(x))/(1+sin(x)); err = fabs(

More information

C++ program structure Variable Declarations

C++ program structure Variable Declarations C++ program structure A C++ program consists of Declarations of global types, variables, and functions. The scope of globally defined types, variables, and functions is limited to the file in which they

More information

Example of a Java program

Example of a Java program Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);

More information

E91 Embedded System. Intro

E91 Embedded System. Intro E91 Embedded System Intro Why embedded systems? Big bang-for-the-buck buck by adding some intelligence to systems. Embedded Systems are ubiquitous. Embedded Systems more common as prices drop, and power

More information

Boolean Variables and Expressions

Boolean Variables and Expressions Boolean Variables and Expressions 1 Recall Standard C++ supports a simple data type specialized for representing logical values. bool type variables can have either of two values: or The identifiers and

More information

Introduction to C++ Programming

Introduction to C++ Programming 2 Introduction to C++ Programming OBJECTIVES In this chapter you will learn: To write simple computer programs in C++. To write simple input and output statements. To use fundamental types. Basic computer

More information

Chapter 5. Selection 5-1

Chapter 5. Selection 5-1 Chapter 5 Selection 5-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow

More information

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language Simple C++ Programs Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs Program Structure Constants and Variables C++ Operators Standard Input and Output Basic Functions from

More information

Member Functions of the istream Class

Member Functions of the istream Class Member Functions of the istream Class The extraction operator is of limited use because it always uses whitespace to delimit its reads of the input stream. It cannot be used to read those whitespace characters,

More information

Computers process data under the control of sets of instructions called computer programs.

Computers process data under the control of sets of instructions called computer programs. Introduction Computer is a device capable of performing computations and making logical decisions at speeds millions and even billions of times faster than human beings. Computers process data under the

More information

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example Operator Overloading Lecture 8 Operator Overloading C++ feature that allows implementer-defined classes to specify class-specific function for operators Benefits allows classes to provide natural semantics

More information

Chapter 4 Intro to Programming in C++

Chapter 4 Intro to Programming in C++ Chapter 4 Intro to Programming in C++ 4-1 Computer Programming Earlier we defined an algorithm to be a step by step process for solving a problem. Computer programming is the process of implementing the

More information

Selection: if Statement

Selection: if Statement : if Statement The simplest selection structure in C++ is the if statement. Syntactically: 1 if The Boolean expression must be enclosed in parentheses, and

More information

Programming Fundamental. Instructor Name: Lecture-2

Programming Fundamental. Instructor Name: Lecture-2 Programming Fundamental Instructor Name: Lecture-2 Today s Lecture What is Programming? First C++ Program Programming Errors Variables in C++ Primitive Data Types in C++ Operators in C++ Operators Precedence

More information

Problem Solving With C++ Ninth Edition

Problem Solving With C++ Ninth Edition CISC 1600/1610 Computer Science I Programming in C++ Professor Daniel Leeds dleeds@fordham.edu JMH 328A Introduction to programming with C++ Learn Fundamental programming concepts Key techniques Basic

More information

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements

9 Control Statements. 9.1 Introduction. 9.2 Objectives. 9.3 Statements 9 Control Statements 9.1 Introduction The normal flow of execution in a high level language is sequential, i.e., each statement is executed in the order of its appearance in the program. However, depending

More information

1. The First Visual C++ Program

1. The First Visual C++ Program 1. The First Visual C++ Program Application and name it as HelloWorld, and unselect the Create directory for solution. Press [OK] button to confirm. 2. Select Application Setting in the Win32 Application

More information

Introduction to C++ Programming

Introduction to C++ Programming cpphtp5_02.fm Page 36 Wednesday, December 15, 2004 11:11 AM 2 Introduction to C++ Programming OBJECTIVES In this chapter you will learn: To write simple computer programs in C++. To write simple input

More information

Chapter 8 Selection 8-1

Chapter 8 Selection 8-1 Chapter 8 Selection 8-1 Selection (Decision) The second control logic structure is selection: Selection Choosing between two or more alternative actions. Selection statements alter the sequential flow

More information

Dept. of CSE, IIT KGP

Dept. of CSE, IIT KGP Programming in C: Basics CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Types of variable We must declare the

More information

Moving from C++ to VBA

Moving from C++ to VBA Introduction College of Engineering and Computer Science Mechanical Engineering Department Mechanical Engineering 309 Numerical Analysis of Engineering Systems Fall 2014 Number: 15237 Instructor: Larry

More information

Object Oriented Software Design

Object Oriented Software Design Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

The programmers guide to C++

The programmers guide to C++ The programmers guide to C++ Adrian P. Robson Northumbria University April 1996 Preprint for Ann, Alice and John Copyright 1997, 2011 by Adrian P. Robson Issue 2.1 - Pre-print draft with post-print errata

More information

EE 231 Lab 6. Arithmetic Logic Unit

EE 231 Lab 6. Arithmetic Logic Unit EE 231 Lab 6 Arithmetic Logic Unit The heart of every computer is an Arithmetic Logic Unit (ALU). This is the part of the computer which performs arithmetic operations on numbers, e.g. addition, subtraction,

More information

The Fundamentals of C++

The Fundamentals of C++ The Fundamentals of C++ Basic programming elements and concepts JPC and JWD 2002 McGraw-Hill, Inc. Program Organization Program statement Definition Declaration Action Executable unit Named set of program

More information

Module I Basic elements in C++

Module I Basic elements in C++ Module I Basic elements in C++ Objectives In this topic, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic

More information

Introduction to Programming (in C++) Subprograms: procedures and functions

Introduction to Programming (in C++) Subprograms: procedures and functions Introduction to Programming (in C++) Subprograms: procedures and functions Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC Subprograms Programming languages, in particular

More information

PIC 10A. Lecture 7: Graphics II and intro to the if statement

PIC 10A. Lecture 7: Graphics II and intro to the if statement PIC 10A Lecture 7: Graphics II and intro to the if statement Setting up a coordinate system By default the viewing window has a coordinate system already set up for you 10-10 10-10 The origin is in the

More information

Syllabus OBJECT ORIENTED PROGRAMMING C++

Syllabus OBJECT ORIENTED PROGRAMMING C++ 1 Syllabus OBJECT ORIENTED PROGRAMMING C++ 1. Introduction : What is object oriented programming? Why do we need objectoriented. Programming characteristics of object-oriented languages. C and C++. 2.

More information

Basics of I/O Streams and File I/O

Basics of I/O Streams and File I/O Basics of This is like a cheat sheet for file I/O in C++. It summarizes the steps you must take to do basic I/O to and from files, with only a tiny bit of explanation. It is not a replacement for reading

More information

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything

More information

GETTING STARTED WITH C++ C++ BASICS - 1 -

GETTING STARTED WITH C++ C++ BASICS - 1 - - 1 - GETTING STARTED WITH C++ Programming is a core activity in the process of performing tasks or solving problems with the aid of a computer. An idealised picture is: PROBLEM COMPUTER SOLUTION Unfortunately

More information

Engineering Problem Solving with C++, Etter/Ingber

Engineering Problem Solving with C++, Etter/Ingber Engineering Problem Solving with C++, Etter/Ingber Chapter 3 Control Structures 1 Control structures Algorithm Development Conditional Expressions Selection Statements Repetition Statements Structuring

More information

Key concepts. C++ character set. Tokens. Keywords Identifiers Literals Punctuators Operators. Integrated Development Environment (IDE)

Key concepts. C++ character set. Tokens. Keywords Identifiers Literals Punctuators Operators. Integrated Development Environment (IDE) 5 1 Key concepts C++ character set Tokens o o o o o Keywords Identifiers Literals Punctuators Operators Integrated Development Environment (IDE) o o Turbo C++ IDE Geany IDE C++ (pronounced "C plus plus")

More information

Chapter 3 Operators and Control Flow

Chapter 3 Operators and Control Flow Chapter 3 Operators and Control Flow I n this chapter, you will learn about operators, control flow statements, and the C# preprocessor. Operators provide syntax for performing different calculations or

More information

Programming Language: Syntax. Introduction to C Language Overview, variables, Operators, Statements

Programming Language: Syntax. Introduction to C Language Overview, variables, Operators, Statements Programming Language: Syntax Introduction to C Language Overview, variables, Operators, Statements Based on slides McGraw-Hill Additional material 2004/2005 Lewis/Martin Modified by Diana Palsetia Syntax

More information

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system. http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral

More information

Common Syntax and Semantic Errors

Common Syntax and Semantic Errors C H A P T E R 2 Common Syntax and Semantic Errors 2.1 CHAPTER OBJECTIVES To understand the fundamental characteristics of syntax and semantic errors To be able to identify specific common syntax and semantic

More information

Programmer-defined Functions

Programmer-defined Functions Programmer-defined Functions Development of simple functions using value and reference parameters JPC and JWD 2002 McGraw-Hill, Inc. Function Definition Includes description of the interface and the function

More information

Boolean Expressions 1. In C++, the number 0 (zero) is considered to be false, all other numbers are true.

Boolean Expressions 1. In C++, the number 0 (zero) is considered to be false, all other numbers are true. Boolean Expressions Boolean Expressions Sometimes a programmer would like one statement, or group of statements to execute only if certain conditions are true. There may be a different statement, or group

More information

School of Informatics, University of Edinburgh

School of Informatics, University of Edinburgh CS1Ah Lecture Note 5 Java Expressions Many Java statements can contain expressions, which are program phrases that tell how to compute a data value. Expressions can involve arithmetic calculation and method

More information

C++ Tutorial. Part I : Procedural Programming

C++ Tutorial. Part I : Procedural Programming C++ Tutorial Part I : Procedural Programming C. David Sherrill School of Chemistry and Biochemistry School of Computational Science and Engineering Georgia Institute of Technology Purpose To provide rapid

More information

[Page 70 (continued)] a. are used to document a program and improve its readability. [Page 71]

[Page 70 (continued)] a. are used to document a program and improve its readability. [Page 71] [Page 70 (continued)] Exercises 2.7 Discuss the meaning of each of the following objects: a. std::cin b. std::cout 2.8 Fill in the blanks in each of the following: a. are used to document a program and

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

The if Statement and Practice Problems

The if Statement and Practice Problems The if Statement and Practice Problems The Simple if Statement Use To specify the conditions under which a statement or group of statements should be executed. Form if (boolean-expression) statement; where

More information

Introduction to Programming Block Tutorial C/C++

Introduction to Programming Block Tutorial C/C++ Michael Bader Master s Program Computational Science and Engineering C/C++ Tutorial Overview From Maple to C Variables, Operators, Statements Functions: declaration, definition, parameters Arrays and Pointers

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved. 1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays

More information

Introduction to Programming (in C++) Data types and visibility. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. Computer Science, UPC

Introduction to Programming (in C++) Data types and visibility. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. Computer Science, UPC Introduction to Programming (in C++) Data types and visibility Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. Computer Science, UPC Outline Data types Type conversion Visibility Introduction to

More information

Appendix K Introduction to Microsoft Visual C++ 6.0

Appendix K Introduction to Microsoft Visual C++ 6.0 Appendix K Introduction to Microsoft Visual C++ 6.0 This appendix serves as a quick reference for performing the following operations using the Microsoft Visual C++ integrated development environment (IDE):

More information

switch Multiple-Selection Statement

switch Multiple-Selection Statement switch Multiple-Selection Statement (This feature is rarely useful, although it s perfect for programming the iterative song The Twelve Days of Christmas!) If no match occurs, the default case is executed,

More information

C programming. Intro to syntax & basic operations

C programming. Intro to syntax & basic operations C programming Intro to syntax & basic operations Example 1: simple calculation with I/O Program, line by line Line 1: preprocessor directive; used to incorporate code from existing library not actually

More information

()A Crash Course in Programming with C++ and the Ubuntu O.S. June 8, / 47

()A Crash Course in Programming with C++ and the Ubuntu O.S. June 8, / 47 A Crash Course in Programming with C++ and the Ubuntu O.S. Dr. Daniel A. Ray MCS Dept UVa-Wise June 8, 2010 ()A Crash Course in Programming with C++ and the Ubuntu O.S. June 8, 2010 1 / 47 Outline What

More information

FORM 1 (Please put your name, section # (10am- 001/2pm-002, and form # on the scantron!!!!) CS 161 Exam I:

FORM 1 (Please put your name, section # (10am- 001/2pm-002, and form # on the scantron!!!!) CS 161 Exam I: FORM 1 (Please put your name, section # (10am- 001/2pm-002, and form # on the scantron!!!!) CS 161 Exam I: True (A)/False(B) (2 pts each): 1. The following statement is legal: cout >> Hello, my name is

More information

The cplusplus.com tutorial Complete C++ language tutorial

The cplusplus.com tutorial Complete C++ language tutorial C++ language tutorial The cplusplus.com tutorial Complete C++ language tutorial 1.4 (August 2003) Introduction Instructions for use. 1. Basics of C++. Structure of a C++ program. Variables. Data types.

More information