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.

Slides:



Advertisements
Similar presentations
1 Demo Reading Assignments Important terms & concepts Fundamental Data Types Identifier Naming Arithmetic Operations Sample Programs CSE Lecture.
Advertisements

CS 1400 Chapter 2 sections 1, 2, 4 – 6, 8,
Chapter 2: Basic Elements of C++
If You Missed Last Week Go to Click on Syllabus, review lecture 01 notes, course schedule Contact your TA ( on website) Schedule.
A simple C++ program /* * This program prints the phrase "Hello world!" * on the screen */ #include using namespace std; int main () { cout
1 9/08/06CS150 Introduction to Computer Science 1 Arithmetic Operators.
1 CS 105 Lecture 3 Constants & Expressions Wed, Jan 26, 2011, 4:15 pm.
The Fundamentals of C++ Basic programming elements and concepts JPC and JWD © 2002 McGraw-Hill, Inc.
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
Chapter 2: Introduction to C++.
Chapter 2: Basic Elements of C++
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.
CHAPTER 2 BASIC ELEMENTS OF C++. In this chapter, you will:  Become familiar with the basic components of a C++ program, including functions, special.
By Dr. Awad Khalil Computer Science & Engineering Department
Welcome to IIT and cs115!. CS Secs. 001 Jon Hanrath SB
Welcome to IIT and cs115!.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
The Fundamentals of C++ Chapter 2: Basic programming elements and concepts JPC and JWD © 2002 McGraw-Hill, Inc. Modified by S. Sudarshan.
Week 1 Algorithmization and Programming Languages.
C++ Programming: Basic Elements of C++.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Chapter 2 Overview of C++. 2 Overview  2.1 Language Elements  2.2 Reserved Words & Identifiers  2.3 Data Types & Declarations  2.4 Input/Output 
Introduction to C++ Basic Elements of C++. C++ Programming: From Problem Analysis to Program Design, Fourth Edition2 The Basics of a C++ Program Function:
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++
Welcome to IIT and cs105! 1. CS Sec. 02 Summer 2015 George Koutsogiannakis – office: 214 SB Best way to communicate.
Simple C++ Programs Program Structure Constants and Variables
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.
Data Types Declarations Expressions Data storage C++ Basics.
CHAPTER 2 C++ SYNTAX & SEMANTICS #include using namespace std; int main() { cout
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
1 Comments Allow prose or commentary to be included in program Importance Programs are read far more often than they are written Programs need to be understood.
Recap……Last Time [Variables, Data Types and Constants]
Announcements Quiz 1 Next Monday. int : Integer Range of Typically –2,147,483,648 to 2,147,483,647 (machine and compiler dependent) float : Real Number.
CS Jan 2007 Chapter 2 sections 1, 2, 4 – 6, 8,
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
2/4/2016Engineering Problem Solving with C++, Second Edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 2 Simple C++ Programs.
Chapter 3 – Variables and Arithmetic Operations. First Program – volume of a box /************************************************************/ /* Program.
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
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.
Welcome to IIT and cs105!. CS 105 Jon Hanrath – SB112B Office Hours: –TBD
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
Today Variable declaration Mathematical Operators Input and Output Lab
C++ First Steps.
Chapter 2: Basic Elements of C++
TK1913 C++ Programming Basic Elements of C++.
Chapter Topics The Basics of a C++ Program Data Types
Computer Programming BCT 1113
BASIC ELEMENTS OF A COMPUTER PROGRAM
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++.
Introduction to C++ October 2, 2017.
Basic Elements of C++ Chapter 2.
2.1 Parts of a C++ Program.
Introduction to C++ Programming
Welcome to IIT and cs115!.
Introduction to C++ Programming
CS150 Introduction to Computer Science 1
elementary programming
Chapter 2: Introduction to C++.
Engineering Problem Solving with C++ An Object Based Approach
Engineering Problem Solving with C++ An Object Based Approach
The Fundamentals of C++
Presentation transcript:

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 part, decimal part, and exponent part) Range of Typically 10e-38 to 10e38 double : Larger Real Number (10e-308 to 10e308) char : Character Built-In (or Primitive) Data Types for Variables

Can Use Letters: Remember That C++ is Case Sensitive (e.g., NumWidgets Is Not the Same as numwidgets ) Can Use Digits 0-9, and Underscore Cannot Start with a Digit Cannot Contain Spaces or Other Characters Typically Maximum of 32 Characters Cannot Use C++ Keywords Naming Variables in C++: Identifiers

Should Use a Meaningful, Descriptive Name so that Variable’s Use Is Easily Understood: Examples: counter, second, minute, length, width Be Consistent with Case; Usually Lower Case with Upper Case for Second Part of Variable Name Examples: averageRainfall, totalStudentGrades, maxBuildingHeight, minPackageWeight; Naming Variables (Cont)

Constant: An Identifier that Is Initialized to a Value that Cannot Change Usually Declared at Top of Program using Keyword const Standard Naming of Constants Is to Use All Upper Case Letter with or without Underscore between Words All Constants Must Be Initialized Syntax: const int MAXHT = 100; Named Constants

Easier to Understand Easier to Modify Example: Compare using Number 5000 in Program versus Constant MAXHT Advantages of Constants

const int MAXHT = 100; main() {... currentHeight > MAXHT... bridgeHeight == MAXHT... bridgeHeight + newAddition >= MAXHT... // used MAXHT 223 times in this program } Named Constants

Constants Whose values Are Already Known: Characters (Specified Inside Single Quotes): ‘A’, ‘a’, ’5’, ’ ‘, ’\n’ (newline), ’\0’ (NULL Character) Integers: 10, 1345, -34 Float or Double: 2.3, , 10.6e6 String (Specified Inside Double Quotes): “HELLO”, “What a great deal.”, “5” Literal Constants (Values)

Also Known as I/O Output Stream: cout << variable; Input Stream: cin >> variable; New Line: endl All C++ Statements End in Semicolon ( ; ) Input and Output

#include using namespace std; int main() { int numEntered; cout << “Please enter an integer:”; cin >> numEntered; cout << “Thanks, you entered: “ << numEntered << “.” << endl; } Input and Output Example

Standard Template Library (STL): Library of C++ Functions Used Worldwide String Type NOT Built-in in C++ String Type Defined in STL To Use STL Strings: #include using namespace std; string lastName; Characters and Strings

Declaration: string yourName; Assigning a Value to a String: yourName = “A. Goose”; String Constants (Values) Must Be Enclosed in Double Quotes STL Strings

#include using namespace std; int main() { string lastName; cout << “Enter your last name: “; cin >> lastName; cout << “Your last name is: “ << lastName << endl; return(0); } Input String Example

Expressions Expression: A Sequence of One or More Identifiers and Operators that Evaluates to a Value Operator: A Symbol Expressing a Way to Modify a Value or Values (e.g., + for Addition) Operand: A Value Being Modified by an Operator Example Expressions: 5 currentHeight currentHeight + 10

Arithmetic Expressions Standard Arithmetic Operations Can Be Performed: Addition, Subtraction, Multiplication, Division Standard Arithmetic Operators Can Be Used for These Operations: +, -, *, / Others: % - “Modulo (Mod)” – Remainder after Integer Division -- Decrement (Subtract 1) ++ Increment (Add 1)

Order of Operations Precedence: Level of Importance of Operations Multiplicative Operators Have Higher Precedence than Additive Operators: *, /, % Higher +, - Lower Associativity: Order of Operation for Equal Level Precedence Most Operators Have Left-to-Right Associativity Use Parentheses to Force Differing Precedence of Operations

Know for the Quiz All Terms (Underlined Items) Variable Declaration, Initialization, and Assignment Constant Declaration Expressions Operators Input (cin) and Output (cout) Everything in Labs through Lab 2