2. Second Step for Learning C++ Programming • Data Type • Char • Float

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick The Programming Process rUse an editor to create a program file (source file). l contains the text of.
Advertisements

C++ Basics Variables, Identifiers, Assignments, Input/Output.
Structure of a C program
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
CS 192 Lecture 3 Winter 2003 December 5, 2003 Dr. Shafay Shamail.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Data representation and Data Types Variables.
COMPUTER PROGRAMMING. Data Types “Hello world” program Does it do a useful work? Writing several lines of code. Compiling the program. Executing the program.
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Fundamentals of C and C++ Programming. EEL 3801 – Lotzi Bölöni Sub-Topics  Basic Program Structure  Variables - Types and Declarations  Basic Program.
ㅎㅎ logical operator if if else switch while do while for Third step for Learning C++ Programming Repetition Control Structures.
COMPUTER PROGRAMMING. variable What is variable? a portion of memory to store a determined value. Each variable needs an identifier that distinguishes.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics.
1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.Semantic © In this session we will.
Variables and Data Types.  Variable: Portion of memory for storing a determined value.  Could be numerical, could be character or sequence of characters.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
Types of C Variables:  The following are some types of C variables on the basis of constants values it has. For example: ○ An integer variable can hold.
Gator Engineering 1 Chapter 2 C Fundamentals (Continued) Copyright © 2008 W. W. Norton & Company. All rights reserved.
C++ Intro SarMag Trimester 31 Intro to C++ Language Scalar Variables, Operators and Control Structures.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
C++ Basics Programming. COMP104 Lecture 5 / Slide 2 Introduction to C++ l C is a programming language developed in the 1970s with the UNIX operating system.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
Introduction to C Programming I Subject: T0016 – ALGORITHM AND PROGRAMMING Year: 2013.
Numbers in ‘C’ Two general categories: Integers Floats
C++ Lesson 1.
Asst.Prof.Dr. Tayfun ÖZGÜR
Variables, Identifiers, Assignments, Input/Output
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Data types Data types Basic types
Chap. 2. Types, Operators, and Expressions
LESSON 3 IO, Variables and Operators
C Short Overview Lembit Jürimägi.
Computing with C# and the .NET Framework
Introduction to C Programming Language
Introduction to C Programming
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
פרטים נוספים בסילבוס של הקורס
Variables in C Topics Naming Variables Declaring Variables
Basics of ‘C’.
Chapter 1: Computer Systems
פרטים נוספים בסילבוס של הקורס
Introduction to C Programming
Govt. Polytechnic,Dhangar
Variables, Identifiers, Assignments, Input/Output
CSC215 Lecture Flow Control.
Variables in C Topics Naming Variables Declaring Variables
CSC215 Lecture Control Flow.
Variables in C Declaring , Naming, and Using Variables.
Chapter 2: Introduction to C++.
WEEK-2.
Programming Language C Language.
Module 2 Variables, Data Types and Arithmetic
Variables in C Topics Naming Variables Declaring Variables
C Language B. DHIVYA 17PCA140 II MCA.
Variables in C Topics Naming Variables Declaring Variables
CSC215 Lecture Control Flow.
Variables in C Topics Naming Variables Declaring Variables
INTRODUCTION TO C.
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

2. Second Step for Learning C++ Programming • Data Type • Char • Float • Double • #define • Comments

[Practice 01 Hello World]

[Explain 01 Hello World]

[Practice 02 Basic C++ Programming]

[Explain 02 Basic C++ Programming] a Preprocessor directive function header start of function body make definitions visible message insert a new line more output terminate main() end of function body

[Practice 03 comments]

[Practice 04 #define]

[Explain 04 #define]

Const You can add the const modifier to the declaration of a variable to tell the compiler that the value cannot be changed: const double factor = 5.0/9.0; const double offset = 32.0; celcius = (fahr - offset)*factor; 09/2014

What if you try to change a const? The compiler will complain if your code tries to modify a const variable: const foo = 100; … foo = 21; Error: l-value specifies const object 09/2014

Const Why use const? 1. const tells the compiler that a variable should never be changed. 2. Typesafe (partial) replacement for #define in C++ 3. May be used for increasing code quality 09/2014

Mathematical expressions have numeric values when evaluated. Math Expressions Mathematical expressions have numeric values when evaluated. Some examples: 1+2 (fahr - 32)*(5/9) 1*(2*(3*(4*5))) 09/2014

[Practice 05 Math Operator Rules]

[Explain 05 Math Operator Rules]

[Practice 06 Addition of integers]

[Explain 06 Addition of integers]

a single byte, capable of holding one character Basic Data Types in C++ char  a single byte, capable of holding one character int an integer, typically reflecting the natural size of integer on the host machine float single precision floating-point double double precision floating-point bool a boolean value (true or false) 09/2014

Keyword auto enum restrict unsigned break extern return void case float short volatile char for signed while const goto sizeof _bool continue if static _Complex default inline struct _Imaginary do int switch double long typedef else register union

Simple Variables Name in C++ Ο int poodle; //valid Ο int Poodle; //valid and distinct from poodle Ο int POODLE; //valid and even more distinct Χ Int terrier; //invalid – has to be int, not Int Ο int my_stars3; //valid Ο int _Mystars3; //valid – starts with underscore Χ int 4ever; //invalid because starts with a digit Χ int double; //invalid – double is a c++ keyword Ο int begin; //valid – begin is a Pascal keyword Ο int __fools; //valid – starts with two underscores Ο int the_very_best_variable_i_can_be_version_112; //valid Χ int apple-4; //invalid – no hyphens allowed

[Practice 07 Data Type]

[Explain 07 Data Type]

ASCII CODE

[Practice 08 char]

[Explain 08 char]

[Practice 09 float]

[Explain 09 float]

Repetition Control Structures 3. Third step for Learning C++ Programming ㅎㅎ logical operator if if else switch while do while for Repetition Control Structures

&& Operator (logical AND opterator) && is a boolean operator, so the value of an expression is true or false. ( cond1 && cond2 ) is true only if both cond1 and cond2 are true. 09/2014

|| Operator (logical OR operator) || is a boolean operator, so the value of an expression is true or false. ( cond1 || cond2 ) is true if either of cond1 or cond2 is true. 09/2014

The ! operator (logical NOT operator) The ! operator is a unary boolean operator unary means it has only 1 operand. ! negates it's operand. ! means "not". (! condition) is true only when condition is false 09/2014

[ Practice 01 logical operator ]

[ Explain 01 logical operator ]

if (condition ) action; if structure The if control structure allows us to state that an action (sequence of statements) should happen only when some condition is true: if (condition ) action; 09/2014

[ Practice 02 if ]

[ Explain 02 if ]

if else structure The if else control structure allows you to specify an alternative action: if ( condition ) action if true else action if false 09/2014

[ Practice 03 if else ]

[ Explain 03 if else ]

switch statement Syntax switch (expression) { case const-expr : statements; break; case const-expr : statements; break; … default statements; break; } 09/2014

[ Practice 04 switch ]

[ Explain 04 switch ] 0 ≦ code ≦ 4

while Control Structure The while control structure supports repetition - the same statement (or compound statement) is repeated until the condition is false. while (condition) do something; the inside is called the "body of the loop" 09/2014

[ Practice 05 while ]

[ Explain 05 while ]

do while The do while control structure also provides repetition, this time the condition is at the bottom of the loop. the body is always executed at least once do somestuff ; while ( condition ); 09/2014

[ Practice 06 do while ]

[ Explain 06 do while ]

You can write any for loop as a while (and any while as a for). for loops The for control structure is often used for loops that involve counting. You can write any for loop as a while (and any while as a for). for (initialization; condition; update) do something; 09/2014

[ Practice 01]