1 CS 1430: Programming in C++ Turn in your Quiz1-1.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
CSE 425: Semantic Analysis Semantic Analysis Allows rigorous specification of a program’s meaning –Lets (parts of) programming languages be proven correct.
Javascript Essentials How do I write it??  Start Homesite  Between the start and end BODY tags type: 
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Introduction to Computers and Programming - Class 2 1 Introduction to Computers and Programming Class 2 Introduction to C Professor Avi Rosenfeld.
CS 1 with Robots Variables, Data Types & Math Institute for Personal Robots in Education (IPRE)‏
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
1 Expressions, Operators Expressions Operators and Precedence Reading for this class: L&L, 2.4.
INTEGERS.
CS1430: Programming in C++ Section 2 Instructor: Qi Yang 213 Ullrich
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1.
Variables, Assignment & Math Storing and naming data.
Variables and Arithmetic. From last class More drawing functions: strokeWeight(n); // higher the n value broader the stroke fill(k) ; // single parameter.
1 CS 1430: Programming in C++. 2 Literal Values Literal values of int Literal values of float
Operators in Python. Arithmetic operators Some operators in Python will look familiar (+, -, *, /) Others are new to you (%, //, **) All of these do work.
7-1 Chapter 7.  Basic Arithmetic Verbs  Options Available with Arithmetic Verbs  COMPUTE Statement  Signed Numbers in Arithmetic Operations  Intrinsic.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
1 CS 1430: Programming in C++. 2 IF Statement if (cond) statement //Next statement if (cond) { statement1 statement2 … } //Next statement.
Arithmetic Operations. Review function statement input/output comment #include data type variable identifier constant declaration.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics.
CS 1 with Robots Variables, Data Types & Math Institute for Personal Robots in Education (IPRE)‏ Sec 9-7 Web Design.
CS Class 03 Topics  Sequence statements Input Output Assignment  Expressions Read pages Read pages 40 – 49 for next time.
1 CS1430: Programming in C++ Section 2 Instructor: Qi Yang 213 Ullrich
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Arithmetic Expressions in C++. CSCE 1062 Outline Data declaration {section 2.3} Arithmetic operators in C++ {section 2.6} Mixed data type arithmetic in.
This will all add up in the end. Assignment operator =Simple Assignment operator Arithmetic Operators +Additive operator – Subtraction operator * Multiplication.
Division. Just as multiplication can be expressed as a series of additions, division can be seen as a series of subtractions. 21 ÷ 7 asks how many times.
Doing math In java.
1 Week 5 l Primitive Data types l Assignment l Expressions l Documentation & Style Primitive Types, Assignments, and Expressions.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
C++ for Engineers and Scientists Second Edition
1 CS 1430: Programming in C++. 2 Input: Input ends with -1 Sentinel-Controlled Loop Input: Input begins with.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Ch 3.1 Add and Subtract Signed Numbers Vocabulary Op posites :2 numbers the same distance from 0 but in opposite directions
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
Dr. Sajib Datta Jan 21,  Declare a variable ◦ int height; [note that no value is still assigned]  Assign a variable a value ◦ height =
1 2. Program Construction in Java. 01 Java basics.
Introduction to Programming
Interesting Integers – Part Dos
Chapter 2 Introduction to C++ Programming
Negative Numbers.
Arithmetic operations & assignment statement
Revision Lecture
Assignment statement and Arithmetic operation 2
Arithmetic Operator Operation Example + addition x + y
CS 1430: Programming in C++ Turn in your Quiz1-2 No time to cover HiC.
Lecture 3 Expressions Richard Gesick.
Introduction to C++ Programming
COMPUTER 2430 Object Oriented Programming and Data Structures I
Introduction to Java, and DrJava part 1
Variables and Arithmetic
Introduction to Programming
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
THE COMPUTE STATEMENT Purpose: performs mathematical calculations
Introduction to Java, and DrJava
Warm-up September 15, 2016 Change to a fraction and simplify: 75% 137%
Data Types and Expressions
Introduction to Programming
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
Arithmetic Operators Topics Arithmetic Operators Operator Precedence
Unit 3: Variables in Java
Introduction to Java, and DrJava part 1
Data Types and Expressions
Data Types and Expressions
Presentation transcript:

1 CS 1430: Programming in C++ Turn in your Quiz1-1

My Home Page URL Go to UWP home page Add “/~yangq” or Search for Qi Yang 2

Installing VS 2012 on Your PC about Deamspark (in Junk folder?) Help section on the web site Go to ITS Help Desk if still issues 3

4 Lab0 Due time: 5 PM, September 3 Grace time: 5 PM, September 8

5 Instructions Coping files Starting a New Project (project folder is created) 9. Adding an Existing CPP file to your project (copy file to the folder created at step 8)...

Lab0 Submit to the Grader Go to My Home Page then to the Grader 6

7 Add Two Numbers In Math S = x + y Or x + y = S

8 Add Two Numbers In C++ Sum = num1 + num2; // This is a comment // Semicolon: Statement terminator // Use meaningful names Sum = num1 + num2;

9 Assignment Operator: = num1 + num2 = Sum; // Valid in C++? // No // Assignment statement MUST // be from right to left Sum = num1 + num2; // Correct! // Not equal

10 Are the two statements the same? Sum = Num1 + Num2; Sum = num1 + num2; // NO! // C++ is case sensitive!

11 Arithmetic Operators Addition: + to compute Sum Subtraction: - to compute Difference Multiplication: * to compute Product Division: / to compute Quotient You MUST use operators to compute in C++!

12 Arithmetic Operators What is ** in C++? result = x ** y; // Not good! What is ^ in C++? result = x ^ y; // Not good! S = x (y + z); //Is it good in C++? //Missing operator! S = x * (y + z); // Good!

13 Programming Style S = x * (y + z); // Good! S = x*(y+z); // What’s the difference? // Is it good in C++? // Yes // Is it good in CS1430 at UWP? // No! // Style! S=x * (y + z); // Not Good! S = x * (y + z); // Good!

14 Semantics, Syntax, and Style total = total + 2; Semantics Increase total by 2 Assignment (right to left) Not equal Syntax Statement terminator Case sensitive Style one space before and after any operator meaningful name

15 Precedence Rules From high to low: ( ) *, / +, -

16 Examples x = * 2; // result: x = (8 - 4) * 2; // result: y = 8 / 4 * 2; // result: y = 8 / (4 * 2); // result:

17 More Examples z = 8 / 4 ^ 2; // No! z = 8 / 4 ** 4; // NO! z = 8 / 4 * 4 // Result: ? X = 5(3 – 7); //Result: ? z = 5 / (2 * 5); // Result: 0.5 or 0?

18 Integer Division vs. Float Division In Math 5 is almost always the same as 5.0 In C++ 5 is almost never the same as 5.0 Why? Store value in computer as bits, bytes. 5 is stored as an integer 5.0 is stored as a float number

19 Integer Division We can only get integers! Long Division! 7 / 5 Quotient: 1 Remainder: 2 5 / 7 Quotient: 0 Remainder: 5

20 Float Division We get float result! Long Division! 7.0 / 5.0 Quotient: / 5.0 (Same) 7.0 / 5 (Same) 5.0 / 7 Quotient: …

21 Quotient (Division) Operator: / Expression 7 / 5 5 / 7 14 / 5 5 / / / 143 Result

22 Remainder (Modular) Operator: % Expression 7 % 5 5 % 7 14 % 5 5 % % % 143 Result

23 Exercises Expression Result 12 % 20 * 3 (12 % 20) * 3 12 * 3 20 % 12 * 3 12 / 20 * 3 20 / 12 * 3 20 / 12 % 3 20 % 12 % 3

24 Why Integer Division? Get $143 from ATM Number of $50 bills: / 50 Amount left after $50 bills: % 50 Number of $10 bills: 4 43 / 10 Amount left after $10 bills: 3 43 % 10 Number of $1 bills: 3

25 Summary Statement Terminator Assignment Operator total = total + num1; // from right to left Arithmetic Operators and Precedence Rules () /, %, * -, + Semantics, Syntax, and Style

26 Quiz point Due beginning of class Wednesday

Visual Studio Demo 27