Module 2 - Part 1 Variables, Assignment, and Data Types

Slides:



Advertisements
Similar presentations
This Time Whitespace and Input/Output revisited The Programming cycle Boolean Operators The “if” control structure LAB –Write a program that takes an integer.
Advertisements

CSC 1051 – Algorithms and Data Structures I
Basic Syntax: Data & Expressions
What Data Do We Have? Sections 2.2, 2.5 August 29, 2008.
1 9/1/06CS150 Introduction to Computer Science 1 What Data Do We Have? CS 150 Introduction to Computer Science I.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
Lab session 3 and 4 Topics to be covered Escape sequences Escape sequences Variables /identifiers Variables /identifiers Constants Constants assignment.
1 Character Strings and Variables Character Strings Variables, Initialization, and Assignment Reading for this class: L&L,
© 2004 Pearson Addison-Wesley. All rights reserved1-1 Intermediate Java Programming Lory Al Moakar.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Program Statements Primitive Data Types and Strings.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-WesleyCopyright © 2011 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.
Lecture 3: The parts of a C++ program Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
CSC1201: Programming Language 2 Lecture 1 Level 2 Course Nouf Aljaffan (C) CSC 1201 Course at KSU1.
Chapter 2 Data and Expressions Part One. © 2004 Pearson Addison-Wesley. All rights reserved2-2/29 Data and Expressions Let's explore some other fundamental.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
C++ Basics Tutorial 5 Constants. Topics Covered Literal Constants Defined Constants Declared Constants.
Chapter 2 topics Concept # on Java Subset Required for AP Exam print and println10. Testing of output is restricted to System.out.print and System.out.println.
Chapter 2 Data and Expressions Java Software Solutions Foundations of Program Design 1.
Chapter 2: Data and Expressions String and String Concatenation Escape Sequences Variables Primitive Date Types Expressions Interactive Programs.
Today’s Lecture  Literal  Constant  Precedence rules  More assignment rules  Program Style.
Data and Expressions Let's explore some other fundamental programming concepts Chapter 2 focuses on: –character strings –primitive data –the declaration.
1 Data and Expressions Chapter 2 In PowerPoint, click on the speaker icon then the “play” button to hear audio narration.
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
Chapter 2 1.What is the difference between print / println 2.What are String Literals 3.What are the Escape Characters for backslash, double quotataions,
Objective Write simple computer program in C++ Use simple Output statements Become familiar with fundamental data types.
1 Structure of Simple C++ Program Chapter 1 09/09/13.
C++ Basics Lecture 2.
Variables, Identifiers, Assignments, Input/Output
C++ Programming: Presentation 1
Web Programming Chapter 1 : Introduction to Java Programming
Intermediate Java Programming
Topic Pre-processor cout To output a message.
CHAPTER 2 PART #1 C++ PROGRAM STRUCTURE
What Actions Do We Have Part 1
Chapter 2 Data and Expressions
Chapter 2 part #1 C++ Program Structure
Beginning C++ Programming
CSC 1051 – Data Structures and Algorithms I
Introduction to C++ October 2, 2017.
Chapter 2 Data and Expressions
Escape Sequences What if we wanted to print the quote character?
Data and Expressions Part One
Chapter 2 – Getting Started
C++ fundamentals Lecture 1, Chapter 2 – pp /22/2018 Y K Choi.
Screen output // Definition and use of variables
Chapter 2 Create a Chapter 2 Workspace Create a Project called Notes
Module 2 - Part 1 Variables, Assignment, and Data Types
Module 2 Variables, Assignment, and Data Types
Module 2 - Part 1 Variables, Assignment, and Data Types
What Actions Do We Have Part 1
(Dreaded) Quiz 2 Next Monday.
CS31 Discussion 1D Winter19: week 4
Programming Strings.
CSC 1051 – Data Structures and Algorithms I
Chapter 1 c++ structure C++ Input / Output
CSE Module 1 A Programming Primer
Module 2 - Part 1 Variables, Assignment, and Data Types
Java Programming Presented by Dr. K. SATISH KUMAR,
Programming Fundamental-1
CSE Module 1 A Programming Primer
Odds and Ends.
Presentation transcript:

Module 2 - Part 1 Variables, Assignment, and Data Types C++ 11/20/2019 CSE 1321 Module 2

Printing strings in C++ (review) cout << “Whatever you are, be a good one.” << endl; cout is called a “stream” It’s in something called “std”, (using namespace std) It represents the console/screen data stream The << are things that we’re pushing into the stream 11/20/2019 CSE 1321 Module 2 2

Pseudocode CLASS CountDown BEGIN METHOD Main() BEGIN s1 ← "Three... " s2 ← "Two... " s3 ← "One... " s4 ← "Zero... " PRINT(s1 + s2 + s3 + s4 + "Liftoff!") PRINTLINE() PRINT("Houston, we have a problem.") END Main END CountDown Output: Three... Two... One... Zero... Liftoff! Houston, we have a problem. Ps 11/20/2019 CSE 1321 Module 2 3

In C++ #include <iostream> #include <string> using namespace std; int main() { string s1 = "Three..."; string s2 = "Two..."; string s3 = "One..."; string s4 = "Zero..."; cout << s1 << s2 << s3 << s4 << " Liftoff!" << endl; cout << "Houston, we have a problem." << endl; } Output: Three... Two... One... Zero... Liftoff! Houston, we have a problem. 11/20/2019 CSE 1321 Module 2 4

Escape Sequences Printing and escape sequence prints a special character in an output string. Common escape sequences: \b backspace. (e.g “B\bsecz\bret” prints what?) \t tab \n newline \r carriage return \” double quote \’ single quote \\ backslash \a alert (which only sometimes works – try it!) 11/20/2019 CSE 1321 Module 2 5

In C++ #include <iostream> using namespace std; int main() { cout << "Roses are red,\n\tViolets are blue,\n" << "Sugar is sweet,\n\tBut I have \"commitment issues\",\n\t" << "So I'd rather just be friends\n\tAt this point in our " << "relationship." << endl; } Output: Roses are red, Violets are blue, Sugar is sweet, But I have "commitment issues", So I'd rather just be friends At this point in our relationship. 11/20/2019 CSE 1321 Module 2 6

Ps Pseudocode // Prints the number of keys on a piano. CLASS PianoKeys BEGIN METHOD Main() BEGIN keys ← 88 PRINT("A piano has " + keys + " keys.") END Main END PianoKeys Output: A piano has 88 keys. Ps 11/20/2019 CSE 1321 Module 2 7

In C++ #include <iostream> using namespace std; int main() { int keys = 88; cout << "A piano has " << keys << " keys." << endl; } Output: A piano has 88 keys. 11/20/2019 CSE 1321 Module 2 8

Pseudocode // Print the number of sides of several geometric shapes. CLASS Geometry BEGIN METHOD Main() sides ← 7 PRINT("A heptagon has " + sides + " sides.") sides ← 10 PRINT("A decagon has " + sides + " sides.") sides ← 12 PRINT("A dodecagon has " + sides + " sides.") END Main END Geometry Output: A heptagon has 7 sides. A decagon has 10 sides. A dodecagon has 12 sides. Ps 11/20/2019 CSE 1321 Module 2 9

In C++ // Print the number of sides of several geometric shapes. #include <iostream> using namespace std; int main() { int sides = 7; // declare and initialize cout << "A heptagon has " << sides << " sides." << endl; sides = 10; // assignment statement cout << "A decagon has " << sides << " sides." << endl; sides = 12; // assignment statement cout << "A dodecagon has " << sides << " sides." << endl; } 11/20/2019 CSE 1321 Module 2 10