Today’s Lecture  Literal  Constant  Precedence rules  More assignment rules  Program Style.

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.
Introduction to C++ September 12, Today’s Agenda Quick Review Check your programs from yesterday Another Simple Program: Adding Two Numbers Rules.
Dale/Weems/Headington
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
1 Lecture-4 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems/Headington.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
A simple C++ program /* * This program prints the phrase "Hello world!" * on the screen */ #include using namespace std; int main () { cout
Correction of the Handout #include //Preprocessor using namespace std; int main (){ ………….. return 0; } A namespace is a named group of definitions. When.
CSC 200 Lecture 2 Matt Kayala 1/25/06. Lecture Objectives More detailed intro to C++ Variables, Expressions, and Assignment Statements Console Input/Output.
Chapter 2: Introduction to C++.
Basic Elements of C++ Chapter 2.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Data representation and Data Types Variables.
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Slides by Evan Gallagher Fundamental Data Types 09/09/13.
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
Introduction to C++ Programming Introduction to C++ l C is a programming language developed in the 1970's alongside the UNIX operating system. l C provides.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
Basic Notions Review what is a variable? value? address? memory location? what is an identifier? variable name? keyword? what is a legal identifier? what.
Introduction to C++ // Program description #include directives int main() { constant declarations variable declarations executable statements return.
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.
Basic Elements of C++ Chapter 1.
Lecture 3: The parts of a C++ program Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Chapter 1 C++ Basics Copyright © 2012 Pearson Addison-Wesley. All rights reserved.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
THE BASICS OF A C++ PROGRAM EDP 4 / MATH 23 TTH 5:45 – 7:15.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Slide 1. Slide 2 Chapter 1 C++ Basics Slide 3 Learning Objectives  Introduction to C++  Origins, Object-Oriented Programming, Terms  Variables, Expressions,
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.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
CHAPTER 2 C++ SYNTAX & SEMANTICS #include using namespace std; int main() { cout
Programming Fundamentals. Summary of previous lectures Programming Language Phases of C++ Environment Variables and Data Types.
1 What is a Named Constant? A named constant is a location in memory that we can refer to by an identifier, and in which a data value that cannot be changed.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
12/14/2016CS150 Introduction to Computer Science 1 Announcements  Website is up!   All lecture slides, assignments,
Chapter 1 C++ Basics Copyright © 2016 Pearson, Inc. All rights reserved.
Objects Variables and Constants. Our Scuba Problem #include // cin, cout, > using namespace std; int main() { const double FEET_PER_ATM = 33.0, LBS_PER_SQ_IN_PER_ATM.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types.
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 Structure of Simple C++ Program Chapter 1 09/09/13.
COMP 2710 Software Construction C++ Basics 2 and Exercises Dr. Xiao Qin Auburn University These slides.
Week 1-2 In this class, you will learn about: Program Structure, Actions and Data Types Data Type: Variables Output and Input action: function cout > Assignment.
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Bill Tucker Austin Community College COSC 1315
FAQ: Exit Vi Using :q Can NOT exit with “:q” if you have not use “:w” to write changes.
Chapter 1 C++ Basics Copyright © 2016 Pearson, Inc. All rights reserved.
Chapter Topics The Basics of a C++ Program Data Types
Chapter 2 Introduction to C++ Programming
Bill Tucker Austin Community College COSC 1315
Documentation Need to have documentation in all programs
Basic Elements of C++.
Lecture 2-3 C++ Basic Constructs
Basic Elements of C++ Chapter 2.
Chapter 2 – Getting Started
Basic Notions Review what is a variable? value? address? memory location? what is an identifier? variable name? keyword? what is legal identifier? what.
2.1 Parts of a C++ Program.
Introduction to C++ Programming
CS150 Introduction to Computer Science 1
Chapter 2: Introduction to C++.
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
Introduction to Programming - 1
Chapter 1 c++ structure C++ Input / Output
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Presentation transcript:

Today’s Lecture  Literal  Constant  Precedence rules  More assignment rules  Program Style

C++ Variables  C++ Identifiers  Keywords/reserved words  Variables  Program name  Case-sensitivity and validity of identifiers  Variables  A memory location to store data for a program  Must declare all data before use in program

Literal Data  Literals  Examples:  2// Literal constant int  5.75// Literal constant double  "Z"// Literal constant char  "Hello World"// Literal constant string  Cannot change values during execution

Escape Sequences  "Extend" character set  Backslash, \ preceding a character  Instructs compiler: a special "escape character" is coming  For example: “\n” means new cline

Constants  Naming your constants  Literal constants are "OK", but provide little meaning  e.g., seeing 24 in a program, tells nothing about what it represents  Use named constants instead  Meaningful name to represent data const int NUMBER_OF_STUDENTS = 24;

Precedence Rules  There may be many operators in one expression, which one do you execute first?  Examples int x; x = * 7 – 8  Rules  Level1: ()  Level 2: *, /, %  Level 3: +, -  Level 4: =

Shorthand Operators: Two Options  Post-Increment intVar++  Uses current value of variable, THEN increments it  Pre-Increment ++intVar  Increments variable first, THEN uses new value  No difference if "alone" in statement: intVar++; and ++intVar;  identical result

Post-Increment in Action  Post-Increment in Expressions: int n = 2, Value; Value = 2 * (n++); cout << Value << endl; cout << n << endl;  This code segment produces the output: 4 3  Since post-increment was used

Pre-Increment in Action  Now using Pre-increment: int n = 2, Value; Value = 2 * (++n); cout << Value << endl; cout << n << endl;  This code segment produces the output: 6 3  Because pre-increment was used

Program Style  Comments, two methods:  // Two slashes indicate entire line is to be ignored  /*Delimiters indicates everything between is ignored*/  Identifier naming  MEANINGFUL NAMES!