CS212: Object Oriented Analysis and Design Lecture 2: Introduction to C++

Slides:



Advertisements
Similar presentations
Copyright © 2002 Pearson Education, Inc. Slide 1.
Advertisements

Chapter 1 C++ Basics. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 1-2 Learning Objectives Introduction to C++ Origins, Object-Oriented.
Programming Languages and Paradigms The C Programming Language.
Chapter 8 Scope, Lifetime and More on Functions. Definitions Scope –The region of program code where it is legal to reference (use) an identifier Three.
Lecture 2 Introduction to C Programming
True or false A variable of type char can hold the value 301. ( F )
Structure of a C program
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
Chapter 2: Introduction to C++.
Overview scope - determines when an identifier can be referenced in a program storage class - determines the period of time during which that identifier.
Introduction To C++ Programming 1.0 Basic C++ Program Structure 2.0 Program Control 3.0 Array And Structures 4.0 Function 5.0 Pointer 6.0 Secure Programming.
Basic Elements of C++ Chapter 2.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Outline Variables 1.
CSC 125 Introduction to C++ Programming Chapter 2 Introduction to C++
© 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.
1 Chapter 9 Scope, Lifetime, and More on Functions.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Program A computer program (also software, or just a program) is a sequence of instructions written in a sequence to perform a specified task with a computer.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
1 C++ Syntax and Semantics, and the Program Development Process.
Week 1 Algorithmization and Programming Languages.
18. DECLARATIONS.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
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.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Week 6: Functions - Part 2 BJ Furman 01OCT2012. The Plan for Today Comments on midterm exam (next week in lab!) Review of functions Scope of identifiers.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
Slides created by: Professor Ian G. Harris Hello World #include main() { printf(“Hello, world.\n”); }  #include is a compiler directive to include (concatenate)
C++ Programming Lecture 3 C++ Basics – Part I The Hashemite University Computer Engineering Department (Adapted from the textbook slides)
Chapter 2. Variable and Data type
 constant represented by a name, just like a variable, but whose value cannot be changed  The const keyword precedes the type, name, and initialization.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Chapter 2 Creating a C++ Program. Elements of a C++ Program Four basic ways of structuring a program Four basic ways of structuring a program 1.Sequencing.
1 A more complex example Write a program that sums a sequence of integers and displays the result. Assume that the first integer read specifies the number.
1 Chapter 8 Scope, Lifetime, and More on Functions CS185/09 - Introduction to Programming Caldwell College.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
C++ Lesson 1.
Chapter 1.2 Introduction to C++ Programming
LESSON 06.
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
The Machine Model Memory
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
Variables A variable is a placeholder for a value. It is a named memory location where that value is stored. Use the name of a variable to access or update.
Basic Elements of C++.
Instructor: Ioannis A. Vetsikas
Basic Elements of C++ Chapter 2.
Advanced Programming Basics
Introduction to Programming
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
Introduction to Abstract Data Types
Govt. Polytechnic,Dhangar
Seoul National University
Chapter 2: Introduction to C++.
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Engineering Problem Solving with C++ An Object Based Approach
C++ Programming Basics
Programming Languages and Paradigms
C Language B. DHIVYA 17PCA140 II MCA.
Seoul National University
INTRODUCTION TO C.
Presentation transcript:

CS212: Object Oriented Analysis and Design Lecture 2: Introduction to C++

Recap of Lecture 1 Introduction to CS212 Logistics and evaluation pattern Thursday – 1 PM - B14CS001 to B14SS017 Friday – 1 PM - UG to UG pillars of OOAD Unified process and UML

Welcome to CS212 #include using namespace std; // main() is where program execution begins. int main() { cout << “Welcome to CS212 !!"; // prints Hello World return 0; } #include using namespace std; // main() is where program execution begins. int main() { // prints Hello World cout << “Welcome to CS212 !!"; return 0; }

Semicolons & Blocks in C++ In C++, the semicolon is a statement terminator. x = y; y = y+1; add(x, y); x = y; y = y+1; add(x, y); { cout << "Hello World"; // prints Hello World return 0; }

C++ Identifiers and Keywords Identifier is a name used to identify a user-defined item Does not allow punctuation characters such $, and % within identifiers. Is CityName and cityName same? Keywords are reserved set of words in C++

Comments in C++ C++ supports single-line and multi-line comments. /* This is a comment */ /* C++ comments can also * span multiple lines */ // I am a single line comment /** C++ Supports *// Nesting of comments */

C++ Data Types TypeKeyword Booleanbool Characterchar Integerint Floating pointfloat Double floating pointdouble Valuelessvoid Wide characterwchar_t

typedef and Enumerated Types Create a new name for an existing type Each enumerator is a constant whose type is the enumeration. typedef int feet; feet distance; enum enum-name { list of names } var-list;

Enum example enum Animal { ANIMAL_CAT = -3, ANIMAL_DOG, ANIMAL_PIG, ANIMAL_HORSE = 5, ANIMAL_GIRAFFE = 5, ANIMAL_CHICKEN }; Best practice: Don’t assign specific values to your enumerators. Rule: Don’t assign the same value to two enumerators in the same enumeration.

Variable Definition in C++ A variable definition specifies a data type, and contains a list of one or more variables of that type as follows: int i, j, k; char c, ch; float f, salary; double d; int d = 3, f = 5; // definition and initializing d and f. byte z = 22; // definition and initializes z. char x = 'x'; // the variable x has the value 'x'.

Declaration vs. Definition // function declaration int func(); int main() { // function call int i = func(); } // function definition int func() { return 0; }

Lvalues and Rvalues lvalue : Expressions that refer to a memory location rvalue : Refers to a data value that is stored at some address in memory. int g = 20; 10 = 20;10 = x;

Variable Scope in C++ A scope is a region of the program Broadly speaking there are three places, where variables can be declared: Variable Scope Local Formal Param. Global

The #define Preprocessor Preprocessor directives are lines included in the code of programs preceded by a hash sign (#) These lines are not program statements but directives for the preprocessor.

C++ Modifier Types Modifier is used to alter the meaning of the base type signed unsigned long short

Type Qualifiers in C++ QualifierMeaning constObjects of type const cannot be changed by your program during execution volatileThe modifier volatile tells the compiler that a variable's value may be changed in ways not explicitly specified by the program. restrictA pointer qualified by restrict is initially the only means by which the object it points to can be accessed. Only C99 adds a new type qualifier called restrict.

The static Storage Class The static storage class instructs the compiler to keep a local variable in existence During the life-time of the program instead of creating and destroying it each time it comes into and goes out of scope. The static modifier may also be applied to global variables. When this is done, it causes that variable's scope to be restricted to the file in which it is declared.

Extern storage class The extern storage class is used to give a reference of a global variable that is visible to ALL the program files. When you have multiple files and you define a global variable or function, which will be used in other files also.

Operators in C++ Arithmetic Operators Relational Operators Logical Operators Bitwise Operators Assignment Operators Misc Operators

Operators Precedence in C++ Operator precedence determines the grouping of terms in an expression. This affects how an expression is evaluated. Certain operators have higher precedence than others Associativity

C++ Loop Types Execute a block of code several number of times: sequentially Condition Conditional code If condition is true If condition is false

Loop control statements Break Continue Infinite loop

C++ decision making statements Condition Conditional code If condition is true If condition is false

Thank you Next Lecture: C++ Continues with Class Identification