Introduction to C++ Programming Language

Slides:



Advertisements
Similar presentations
C++ Statements represent the lowest-level building blocks of a program and it may be like:. A simple statement is a computation terminated by a semicolon.
Advertisements

Computer Science 2 Data Structures V section 2 Recitation 1.
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
True or false A variable of type char can hold the value 301. ( F )
Computer Science 1620 Loops.
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Computer Science 1620 Accumulators. Recall the solution to our financial program: #include using namespace std; int main() { double balance = ;
1 CS150 Introduction to Computer Science 1 Arithmetic Operators.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
Expressions An expression is a sequence of operands and operators that reduces to a single value expression operator operand An operator is a language-specific.
C++ Operators CS242 COMPUTER PROGRAMMING T.Banan Al-Hadlaq.
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
COMPUTER PROGRAMMING. Functions What is a function? A function is a group of statements that is executed when it is called from some point of the program.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to list and describe the six expression categories ❏ To understand.
Chapter 0 Getting Started. Objectives Understand the basic structure of a C++ program including: – Comments – Preprocessor instructions – Main function.
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
1 09/27/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
1 10/3/05CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
STRUCTURED PROGRAMMING C++ Operators. Content 2  C++ operators  Assignment operators  Arithmetic operators  Increment and decrement operators  Decision.
Computer Programming Basics Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea.
LECTURE # 6 : STRUCTURED PROGRAMMING C++ OPERATORS By Mr. Ali Edan.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
1 Structure of Simple C++ Program Chapter 1 09/09/13.
1 8/30/06CS150 Introduction to Computer Science 1 Your First C++ Program.
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
Introduction to C++ Programming Language Assistant Professor Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University,
Chapter Topics The Basics of a C++ Program Data Types
Topic Pre-processor cout To output a message.
Chapter 1: Introduction to computers and C++ Programming
What Actions Do We Have Part 1
Chapter 2: Introduction to C++
Completing the Problem-Solving Process
Introduction to C++ Programming Language
Computing Fundamentals
Intro to Programming Week # 6 Repetition Structure Lecture # 10
Chapter 2 part #1 C++ Program Structure
Basic Elements of C++.
Chapter 2 Assignment and Interactive Input
Object-Oriented Programming
Arithmetic & other operations
Basic Elements of C++ Chapter 2.
Pointer Data Type and Pointer Variables
Structure of a C Program
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
2.1 Parts of a C++ Program.
CS150 Introduction to Computer Science 1
Introduction to C++ Programming Language
Computing Fundamentals
Introduction to C++ Programming Language
Alternate Version of STARTING OUT WITH C++ 4th Edition
CS150 Introduction to Computer Science 1
CS150 Introduction to Computer Science 1
Chapter 2: Introduction to C++.
Programs written in C and C++ can run on many different computers
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Life is Full of Alternatives
Arithmetic Operations
Life is Full of Alternatives
Capitolo 1 – Introduction C++ Programming
Chapter 4: Expression and Operator
Computer Programming Basics
Pointer Data Type and Pointer Variables
Pointer Data Type and Pointer Variables
Introduction to C Programming
Expressions An Expression is a sequence of operands and operators that reduces to a single value. An operator is a language-specific syntactical token.
Presentation transcript:

Introduction to C++ Programming Language Jeon, Seokhee Assistant Professor Department of Computer Engineering, Kyung Hee University, Korea

About The Lecture Note This lecture note is intended to be used by students in “Introduction to C++ Programming Language” course at the Kyung Hee University. Originally made by Professor Sungwon Lee for the same course, but slightly modified by me. The slides are mainly based on the class textbook, “Computer Science : A Structured Approach Using C++, 2nd Edition”

CH.3 EXPRESSIONS, OPERATORS, STATEMENTS

Expressions 2 + 5 Operand Expression Operator A sequence of operands and operators that reduces to a single value Example: Operand 2 + 5 Expression Operator

C++ Expression Format Just look, and don’t remember! We will see specific examples.

Primary Expressions Three types of primary expressions

Binary Expressions

Binary Expression -- Multiplicative Expressions 10 * 12 20 / 4 5 % 2 ??? Modulus Operator (%) (나머지 연산) 5 % 2  1 5 % 3  2 6 % 3  0

Binary Expression -- Additive Expressions -- Sample Codes 3 + 5, 4 – 6

Assignment expressions The assignment expression has a value and a result. The value of the total expression is the value of the expression on the right of the assignment operator (=). The result places the expression value in the operator on the left of the assignment operator. The left operand in an assignment expression must be a single variable.

Simple Assignment Consists of simple algebraic expressions Examples

Compound Assignment Shorthand notation for a simple assignment Examples

Sample Code for Assignment Expression

Postfix Expressions Remember! (a++) is (a = a + 1)

5) Unary expressions Remember! (++a) is (a = a + 1)

Example code reading (Program 3-4) #include <iostream> #include <iomanip> using namespace std; int main () { int a = 4; cout << "value of a : " << setw(2) << a << endl; cout << "value of ++a : " << setw(2) << ++a << endl; cout << "new value of a: " << setw(2) << a << endl; return 0; } // main value of a : 4 value of ++a : 5 new value of a: 5

Operator Precedence Which operator will be evaluated first? Each operator has one of 18 precedence levels Look at the cover page of the book

Operator Precedence Examples 2 + 3 * 4 ( 2 + ( 3 * 4) ) -b++ ( -( b++ ) )

Operator Associativity Determine the evaluation order of the operators having the same precedence Left associativity vs. Right associativity

Operator Associativity Examples Left associativity Right associativity

Statements A block of instructions Types of statements

Expression Statements Examples a = 2; a = b = 3; a = 4 + 5; a = b + (45 / c) + 22; a++; * An expression statement is terminated with a semicolon (;). The semicolon is a terminator, and it tells the compiler that the statement is finished.

Compound Statements A block of multiple statements