# include using namespace std; int Square ( int ); int Cube ( int ); int main () { cout<<“The square of 27 is “<< Square(27) << endl; cout<<“The cube of.

Slides:



Advertisements
Similar presentations
1 C++ Syntax and Semantics The Development Process.
Advertisements

C++ Basics Variables, Identifiers, Assignments, Input/Output.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Dale/Weems/Headington
1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
Announcements Quiz 1 Next Week. int : Integer Range of Typically -32,768 to 32,767 (machine and compiler dependent) float : Real Number (i.e., integer.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
Chapter 2 Data Types, Declarations, and Displays
Chapter 2: Introduction to C++.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Basic Elements of C++ Chapter 2.
CIS Computer Programming Logic
Chapter 2 Overview of C Part I J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei University.
C Tokens Identifiers Keywords Constants Operators Special symbols.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
1 C++ Syntax and Semantics, and the Program Development Process.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems.
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
CHAPTER 7 DATA INPUT OUTPUT Prepared by: Lec. Ghader R. Kurdi.
Course Title: Object Oriented Programming with C++ instructor ADEEL ANJUM Chapter No: 03 Conditional statement 1 BY ADEEL ANJUM (MSc-cs, CCNA,WEB DEVELOPER)
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems.
Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Syntax and Semantics, and the Program Development Process ROBERT REAVES.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
Chapter 2: Introduction to C++. Language Elements Keywords Programmer-defined symbols (identifiers) Operators Punctuation Syntax Lines and Statements.
CHAPTER 2 C++ SYNTAX & SEMANTICS #include using namespace std; int main() { cout
Constants, Variables and Data types in C The C character Set A character denotes any alphabet, digit or special symbol used to represent information.
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
Lecture 5 Computer programming -1-. Input \ Output statement 1- Input (cin) : Use to input data from keyboard. Example : cin >> age; 2- Output (cout):
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
1 CSC 1111 Introduction to Computing using C++ C++ Basics (Part 1)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Introduction to C++
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 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
C++ First Steps.
Chapter Topics The Basics of a C++ Program Data Types
Chapter 1.2 Introduction to C++ Programming
BASIC ELEMENTS OF A COMPUTER PROGRAM
Documentation Need to have documentation in all programs
Chapter 2 Topics Programs Composed of Several Functions
Basic Elements of C++.
Basic Elements of C++ Chapter 2.
Introduction to the C Language
2.1 Parts of a C++ Program.
CS150 Introduction to Computer Science 1
C++ Data Types Data Type
Variables, Identifiers, Assignments, Input/Output
Variables T.Najah Al_Subaie Kingdom of Saudi Arabia
Chapter 2: Introduction to C++.
Variables and Constants
Presentation transcript:

# include using namespace std; int Square ( int ); int Cube ( int ); int main () { cout<<“The square of 27 is “<< Square(27) << endl; cout<<“The cube of 27 is “ << Cube(27) << endl; return 0; }

SYNTAX – defines exactly what combination of letters, numbers and symbols can be used SEMANTICS – a set of rules that determines the meaning of instructions METALANGUAGE – a language that is used to write the syntax rules for another language OLDEST METALANGUAGE – BNF (Backus-Naur Form) SYNTAX TEMPLATE – a generic example of the c++ construct

IDENTIFIERS Identifier – A name associated with a function or data object and used to refer to that function or data object Rules – a) must start with a letter or an underscore b) identifiers that begin with underscore have special meaning Invalid IdentifierExplanation 40HoursIdentifiers cannot begin with a digit Get DataBlanks are not allowed Box-22hyphen is a math symbol Cost_in_$($) special symbols are not allowed intreserved word

Valid IdentifierHow it is used MAX_HOURSMaximum normal work hours OVERTIMEOvertime pay rate factor payRateAn employee’s hourly pay rate hoursnumber of hours an employee worked wagesemployee’s weekly wages empNumAn employee’s identification number CalcPaya function for computing an employee’s wages

C++ IS CASE SENSATIVE EmpNum is not the same as empnum Emp Num is not the same as EmpNum empNum is not the same as EmpNum

DATA TYPES TWO CATEGORIES OF DATA TYPES 1)STANDARD OR BUILT IN – use often so C++ has them predefined intfloatchar 2)Programmer or user defined data types – see chapter 10.

HOW DATA IS STORED IN MEMORY 1)Memory is divided into CELLS 2)Each CELL has a unique address 3)This address is a binary number 4)We use identifiers to name cells 5)The compiler translates the identifier into the address in memory Cell Cell Cell EmpNumEmpPayEmpAddress

Char char – consists of one alphanumeric character – a letter, digit or special symbol char is enclosed is a singe quote ‘8’ ‘8’ ≠ 8 ‘8’ is an alphanumeric – cannot be used in mathematical equations 8 is a numeric – can be used in mathematical equations ‘ ‘ is a blank char it consists of a ‘ press the space bar ‘ ‘A’ < ‘B’ due to a predefined collating sequence but we cannot do math on chars

String String – a sequence of characters – word, name, sentence Strings are enclosed in double quotes. “I am happy” Strings must be typed on one line – don’t split. “I am Happy” will give you an error. “” is the empty string or null string – no space between double quotes

DATA OBJECTS CONSTANTS – a name of a memory location whose contents are not allowed to change VARIABLES – a name of a memory location whose contents can change A const char EMPCODEint EmpNum

DECLARATION Declaration – a statement that associates an identifier with a data object, a function or a data type so that the programmer can refer to the item by name int EmpNum; int EmpPay; const char EMPCODE = ‘A’; int Square( int);

int EmpNumint EmpPaystring EmpAddress Variables – a location in memory, referenced by an identifier, that contains a data value that can be changed Declaring a variable – specify data type and name; int EmpNum; int EmpPay; string EmpAddress; OR int EmpNum, EmpPay; string EmpAddress;

‘A’ const char EMPCODE Constants – a location in memory, referenced by an identifier, that contains a data value that CANNOT be changed Declaring a constant – specify constant, data type, name and data value const char EMPCODE = ‘A’;

LITERAL VS CONSTANT LITERAL – any constant value written in a program cout<<“I am a c++ programmer”; NAMED CONSTANT const char EMPCODE = LITERAL VALUE;