Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous.

Slides:



Advertisements
Similar presentations
1 9/13/06CS150 Introduction to Computer Science 1 Type Casting.
Advertisements

If Statements & Relational Operators Programming.
Lecture 071 CS 192 Lecture 7 Winter 2003 December 15-16, 2003 Dr. Shafay Shamail.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
1 9/15/06CS150 Introduction to Computer Science 1 Combined Assignments, Relational Operators, and the If Statement.
Friday, December 08, 2006 “Experience is something you don't get until just after you need it.” - Olivier.
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
1 9/17/07CS150 Introduction to Computer Science 1 Type Casting.
1 9/20/06CS150 Introduction to Computer Science 1 Review: Exam 1.
CS150 Introduction to Computer Science 1
If Statements. COMP104 If / Slide 2 Three Program Structures * Sequence - executable statements which the computer processes in the given order * Choice.
1 9/25/06CS150 Introduction to Computer Science 1 Nested Ifs, Logical Operators, exit() Page 194.
How Create a C++ Program. #include using namespace std; void main() { cout
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
Thursday, December 14, 2006 “Would you tell me, please, which way I ought to go from here?” “That depends a good deal on where you want to get to,” said.
The If/Else Statement, Boolean Flags, and Menus Page 180
Quiz 1 Exam 1 Next Week. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) cout
CHAPTER 2 BASIC ELEMENTS OF C++. In this chapter, you will:  Become familiar with the basic components of a C++ program, including functions, special.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
CS 192 Lecture 3 Winter 2003 December 5, 2003 Dr. Shafay Shamail.
Chapter 3 COMPLETING THE BASICS Programming Fundamentals with C++1.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
Basic Notions Review what is a variable? value? address? memory location? what is an identifier? variable name? keyword? what is a legal identifier? what.
Selection Structures (if & switch statements) (CS1123)
Palindromes revisited Here's a simpler program for checking palindromes: int nums[100]; int i = 0, a; cin >> a; while(a > 0) { nums[i++] = a; cin >> a;
Windows Programming, C.-S. Shieh, KUAS EC, Chapter 3 Operators and Expressions.
CSE1222: Lecture 3The Ohio State University1. Assignment Operations  The C++ assignment operator is: =  Examples: x = 3 * 5; y = x – 7; y = y + 4; Do.
C++ Programming: Basic Elements of C++.
CPS120: Introduction to Computer Science Operations Lecture 9.
Perform Calculations and Control Flow Telerik Software Academy Learning & Development Team.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 2 Elementary Programming.
Computer Science 1620 boolean. Types so far: Integer char, short, int, long Floating Point float, double, long double String sequence of chars.
1 Compound Assignment C++ has a large set of operators for applying an operation to an object and then storing the result back into the object Examples.
Chapter 7 Selection Dept of Computer Engineering Khon Kaen University.
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
Control Structures (B) Topics to cover here: Sequencing in C++ language.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Selection Control Structures (L08) * Selection Criteria * if Statements * The if-else Statement Selection Control Structure Dr. Ming Zhang.
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Simple Data Types Chapter Constants Revisited t Three reasons to use constants –Constant is recognizable –Compiler prevents changes in value.
Programming Fundamentals with C++1 Chapter 3 COMPLETING THE BASICS.
If Statements Programming. COMP104 Lecture 7 / Slide 2 Review: Rules for Division l C++ treats integers different than doubles. 100 is an int. l 100.0,
CMPSC 121- Spring 2015 Lecture 6 January 23, 2015.
LESSON 3 Operators. Operators  Symbol that tells the computer to perform certain mathematical or logical manipulations.
Lecture 7 Computer Programming -1-. Conditional Statements 1- if Statement. 2- if ….. else Statement. 3- switch.
Simple Data Types Chapter Constants Revisited t Three reasons to use constants –Constant is recognizable –Compiler prevents changes in value.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Unary, Binary, logical Operations, Explicit type conversion Lecture 6 Instructor: Haya Sammaneh.
Operators A binary operator combines two values to get one result: x OP y where OP is any binary operators such as +, -, *, /, ==, !=, >, &&, or even =.
CSE202: Lecture 5The Ohio State University1 Selection Structures.
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
Lecture 3.1 Operators and Expressions Structured Programming Instructor: Prof. K. T. Tsang 1.
Variables and Types. Primitive Built-in Type Type Meaning Minimum Size bool boolean NA char character 8 bits wchar_t wide character 16 bits char16_t Unicode.
1 09/10/04CS150 Introduction to Computer Science 1 What Actions Do We Have Part 2.
Section 3 Review Mr. Crone.
A mechanism for deciding whether an action should be taken
Operators and Expressions
Conversions of the type of the value of an expression
Intro to Programming Week # 4 Control Structure Lecture # 8
Basic Notions Review what is a variable? value? address? memory location? what is an identifier? variable name? keyword? what is legal identifier? what.
אבני היסוד של תוכנית ב- C++
אבני היסוד של תוכנית ב- C++
Summary Two basic concepts: variables and assignments Basic types:
CS150 Introduction to Computer Science 1
C++ Programming Lecture 3 C++ Basics – Part I
Arithmetic Operations
ENERGY 211 / CME 211 Lecture 5 October 1, 2008.
Operator King Saud University
Presentation transcript:

Tuesday, December 12, 2006 “Press any key to continue or any other key to quit.” - Anonymous

What is wrong here? int myvar.d; int data-1; int %value;

What is wrong here? int a=3; b=a;

What is wrong here? int a,b; a++; b++;

What is wrong here? cin>>a+b; cin>>10;

What is wrong here? int a=2; b=3;

What is wrong here? int a=2, b=3; a+b=5;

What is wrong here? int a=2, b=3, c=6, d; d = b–4ac;

What is wrong here? int a=2, b=3; cout<<a<<" "<<b<<endl; double a; cout<<a<<" "<<b<<endl;

What is wrong here? char a=h;

§Indentation and colors

§Initialize with constant or expression int a, b=3; a = b*53+7;

int a=70, b=80; How to print 70 80?

double amount; cout<<“Enter the balance in dollars:$”; cin>>amount;

int x=5, y=5; y=++x; cout<<x<<" "<<y<<endl; y=x--; cout<<x<<" "<<y<<endl;

int x=5, y=5; y=++x; cout<<x<<" "<<y<<endl; // prints 6 6 y=x--; cout<<x<<" "<<y<<endl; // prints 5 6

int x=5, y=5; cout << x++ << endl; cout << ++y << endl; cout << x << ‘,’ << y;

int x=5, y=5; cout << x++ << endl; //prints 5 cout << ++y << endl; //prints 6 cout << x << ‘,’ << y; //prints 6,6

The following code causes conversions (in this example, integral promotions): long lnum1=2345, lnum2=3456; int inum=45; // inum promoted to type long prior to assignment. lnum1 = inum; // inum promoted to type long prior to multiplication. lnum2 = inum * lnum2;

float fVal=3.0, fVal2=4.5; double dVal=9.768; int iVal=6; fVal2 = iVal * fVal; // iVal converted to float; // result of multiplication is float. dVal = iVal + dVal; // iVal converted to double; // result of addition is double.

What is wrong here? double total_price ; int feet; cin>>feet; //There are 5280 feet in a mile total_price = 5000*(feet/5280); //suppose user enters feet

int y; char c='3'; y = 5 + c; cout<<y<<endl; output?

Character Data l Each character corresponds to a binary code l Most commonly use binary codes are ASCII (American Standard Code for Information Interchange) CharacterASCII CodeInteger Equivalent % A a b c

int y; char c='3'; y = 5 + c; cout<<y<<endl; output 56 CharacterASCII CodeInteger Equivalent

char ck='3'; int i=ck; cout <<i<<endl;

§Casts can be used cout<<(float)5/3<<endl; cout<<(float)3/6<<endl; Casts are considered operators – same precedence as unary operators

char ck='3'; cout <<(int) ck<<endl; ________________________________ char ck='3'; int i=ck; cout <<i<<endl;

Be careful with casts! e.g. Don’t cast a double into float

//Compiler will give warnings. Try this out! #include int main(){ int i, j; i=23.867; j= ; cout<<i<<" "<<j<<endl; return 0; }

//Compiler will give warnings Try this out! #include int main(){ int i, j, k; i=23.867; j= ; cout<<i<<" "<<j<<endl; return 0; }

cout<<"This is called \"fund raising\""; cout<<"\"\\"; cout<<"one"<<"\t"<<"two";

§Concept of true and false §true is any value other than zero §false is zero

bool b=true; cout<<b<<endl; b=false; cout<<b<<endl; //zero is false and non-zero is true b=35; cout<<b<<endl; b=-45; cout<<b<<endl; b=0; cout<<b<<endl;

bool b=true; cout<<b<<endl; //prints 1 b=false; cout<<b<<endl; //prints 0 //zero is false and non-zero is true b=35; cout<<b<<endl; //prints 1 b=-45; cout<<b<<endl; //prints 1 b=0; cout<<b<<endl; //prints 0