PROGRAMMING LANGUAGE C++ lecture2 أ. منى الزهراني.

Slides:



Advertisements
Similar presentations
This Time Whitespace and Input/Output revisited The Programming cycle Boolean Operators The “if” control structure LAB –Write a program that takes an integer.
Advertisements

Lecture 2 Introduction to C Programming
Introduction to C Programming
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
 C++ programming facilitates a disciplined approach to program design. ◦ If you learn the correct way, you will be spared a lot of work and frustration.
Introduction to C Programming
 2003 Prentice Hall, Inc. All rights reserved. 1 Chapter 1 – Introduction to Computers and C++ Programming Outline 1.6 Machine Languages, Assembly Languages,
Introduction Kingdom of Saudi Arabia Shaqra University
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline History of C and C++ C++ Standard Library Object Technology Basics.
Three types of computer languages
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
 2003 Prentice Hall, Inc. All rights reserved Computer Organization Six logical units of computer 1.Input unit “Receiving” section Obtains information.
 2003 Prentice Hall, Inc. All rights reserved. 1 Machine Languages, Assembly Languages, and High-level Languages Three types of computer languages 1.Machine.
Introduction to C Programming
C++ Programming Language Day 1. What this course covers Day 1 – Structure of C++ program – Basic data types – Standard input, output streams – Selection.
Chapter 01: Introduction to Computer Programming
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
ECE 264 Object-Oriented Software Development Instructor: Dr. Honggang Wang Fall 2012 Lecture 3: Requirements Specification, C++ Basics.
History of C and C++ C++ evolved from C ANSI C C++ “spruces up” C
Completing the Basic (L06)
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 1 February 8, 2005.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Week 1 Algorithmization and Programming Languages.
INTRODUCTION Kingdom of Saudi Arabia Princess Nora bint Abdul Rahman University College of Computer Since and Information System CS240.
Lecture #6 OPERATORS AND ITS TYPES By Shahid Naseem (Lecturer)
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Announcements Starting next week class 6-8 on Thursday Homework 1 on the web  Due January 29 – next class meeting  Homework policy No late assignments.
Arithmetic OperatorOperationExample +additionx + y -subtractionx - y *multiplicationx * y /divisionx / y Mathematical FormulaC Expressions b 2 – 4acb *
1 EECS230 Course Introduction and a First Program Ying Wu Electrical Engineering and Computer Science Northwestern University
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
CHAPTER 1.2 INTRODUCTION TO C++ PROGRAMMING Dr. Shady Yehia Elmashad.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
1 Structure of Simple C++ Program Chapter 1 09/09/13.
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example:
Chapter 02 (Part II) Introduction to C++ Programming.
 2003 Prentice Hall, Inc. All rights reserved Introduction Software –Instructions to command computer to perform actions and make decisions Hardware.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Lecture2.
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1: Introduction to computers and C++ Programming
Introduction to C++ Programming
Chapter 2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Introduction to C Language
Chapter 2 - Introduction to C Programming
Programming Fundamental
Beginning C++ Programming
Chapter 2 - Introduction to C Programming
Arithmetic Operator Operation Example + addition x + y
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
1.13 The Key Software Trend: Object Technology
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
Distributive Property
Programs written in C and C++ can run on many different computers
Capitolo 1 – Introduction C++ Programming
Chapter 2 - Introduction to C Programming
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Presentation transcript:

PROGRAMMING LANGUAGE C++ lecture2 أ. منى الزهراني

A Simple Program: Printing a Line of Text أ. منى الزهراني 1 // Fig // Printing a line with multiple statements. 3 #include 4 5 // function main begins program execution 6 int main() 7 { 8 std::cout << "Welcome "; 9 std::cout << "to C++!\n"; return 0; // indicate that program ended successfully } // end function main Multiple stream insertion statements produce one line of output. Welcome to C++!

أ. منى الزهراني

Printing multiple lines with a single statement أ. منى الزهراني 1 // Fig // Printing multiple lines with a single statement 3 #include 4 5 // function main begins program execution 6 int main() 7 { 8 std::cout << "Welcome\nto\n\nC++!\n"; 9 10 return 0; // indicate that program ended successfully } // end function main Welcome to C++! Using newline characters to print on multiple lines.

Compound Assignments: أ. منى الزهراني A common operation in programming is to apply an operator to a variable, and then store the result in the same variable. For example, the following assignment doubles the value of j: j = j * 2; This can be rewritten as: j *= 2; And the other operator as the previous one: +=, -=, /=, %=

أ. منى الزهراني a = 5 ; b = 3 a += 2; b += 1; a = ……….., b = ………… ________________________ x = 5 ; y = 3 x *= 2; y *= 3; X = ……….., y = ………… Examples:

أ. منى الزهراني Examples: a = 1; // a = 1 b = ++a; // a = 2, b = 2 c = a++; // a = 3, c = 2 a = 5; b = 3; n = ++a + b--; a = , b = , n = a = 5; b = 3; n = ++a * ++b; a = , b = , n = n = a++ * b++; a = , b = , n = a = 5; b = 3; n = a++ * --b; a = , b = , n =

أ. منى الزهراني a = 1; // a = 1 a = 2, b = 2 b = ++a; // a = 2, b = 2 a = 3, c = 2 c = a++; // a = 3, c = 2 a = 5; b = 3; a = 6, b = 2, n = 9 n = ++a + b--; // a = 6, b = 2, n = 9 a = 5; b = 3; a = 6, b = 4, n = 24 n = ++a * ++b; // a = 6, b = 4, n = 24 a = 6, b = 4, n = 15 n = a++ * b++; // a = 6, b = 4, n = 15 a = 5; b = 3; a = 6, b = 2, n = 10 n = a++ * --b; // a = 6, b = 2, n = 10 Examples:

Converting mathematical expression to sentences in the C++ language: أ. منى الزهراني

Converting mathematical expression to sentences in the C++ language: أ. منى الزهراني

Example 1: If you have the following sentences: Int A=2, B=2, C=3, R; Find the value of R? (1) R= 2B – 4AC (2) R= B+A+(CBA)/6 (3) R= C%A+BC/A (4) R= 17% (C+A) B+6

أ. منى الزهراني Solution (1) R= 2*B – 4*A*C = 2*2 – 4*2*3 =4- 24 = -20 (2) R= B+A+ (C*B*A)/6 = /6 = = 6

أ. منى الزهراني Solution (3) R= C%A+B*C/A = 3%2+2*3/2 1+6/2 = 5+6/2 1+3 =5+3 4 = = 8 (4) R= 17% (C+A) *B+6 = 17% (3+2)*2+6 = 17% 5*2+6 2*2+6 =4* = =14

أ. منى الزهراني Example 2: If you have the following sentences: Int A=3, B=8, R? Find the value of R? (1) R= (A>=0) + (A!=B) (2) R= (A+5B) <= (30/A)

أ. منى الزهراني Solution (1) R= (3>=0) + (3!=8) = 1+1 = 2 (2) R= (3+5*8)<= (30/3) = (3+40) <= 10 = 43<=10 = 0