CSI33 Data Structures

Similar documents
C-LANGUAGE CURRICULAM

! A program is a set of instructions that the. ! It must be translated. ! Variable: portion of memory that stores a value. char

CS313D: ADVANCED PROGRAMMING LANGUAGE

UNIT- 3 Introduction to C++

Structured Programming Using C++ Lecture 2 : Introduction to the C++ Language. Dr. Amal Khalifa. Lecture Contents:

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Basic Elements of COMPUTER PROGRAMMING. Special symbols include: Word symbols. Objectives. Programming. Symbols. Symbols.

Introduction to Bioinformatics

Module 2 - Part 2 DATA TYPES AND EXPRESSIONS 1/15/19 CSE 1321 MODULE 2 1

Introduction to Programming Using Java (98-388)

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

CSCI 1061U Programming Workshop 2. C++ Basics

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Example of Objective Test Questions for Test 4

Programming with C++ as a Second Language

Chapter 1. C++ Basics. Copyright 2010 Pearson Addison-Wesley. All rights reserved

Reserved Words and Identifiers

Computer Programming : C++

This watermark does not appear in the registered version - Slide 1

Chapter 2. Outline. Simple C++ Programs

1007 Imperative Programming Part II

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

8. Functions (II) Control Structures: Arguments passed by value and by reference int x=5, y=3, z; z = addition ( x, y );

Numbers. John Perry. Spring 2017

CSC Web Programming. Introduction to JavaScript

Chapter 2: Overview of C++

Introduction to Computers and C++ Programming p. 1 Computer Systems p. 2 Hardware p. 2 Software p. 7 High-Level Languages p. 8 Compilers p.

CS201- Introduction to Programming Current Quizzes

C++ for Python Programmers

Chapter 2 Basic Elements of C++

Logical Operators and if/else statement. If Statement. If/Else (4.3)

calling a function - function-name(argument list); y = square ( z ); include parentheses even if parameter list is empty!

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

Pace University. Fundamental Concepts of CS121 1

B.V. Patel Institute of Business Management, Computer & Information Technology, Uka Tarsadia University

C++ Support Classes (Data and Variables)

ECE 122 Engineering Problem Solving with Java

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

2 nd Week Lecture Notes

switch case Logic Syntax Basics Functionality Rules Nested switch switch case Comp Sci 1570 Introduction to C++

Basics of Java Programming

SOFT 161. Class Meeting 1.6

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.


Key Differences Between Python and Java

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

Lecture 2 Tao Wang 1

Chapter 2: Using Data

CHAPTER 1 Introduction to Computers and Programming CHAPTER 2 Introduction to C++ ( Hexadecimal 0xF4 and Octal literals 031) cout Object

3. Java - Language Constructs I

Java Notes. 10th ICSE. Saravanan Ganesh

Full file at

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Chapter 2: Using Data

CSCE 110 PROGRAMMING FUNDAMENTALS

Homework #3 CS2255 Fall 2012

o Counter and sentinel controlled loops o Formatting output o Type casting o Top-down, stepwise refinement

ENGR 101 Engineering Design Workshop

CSI33 Data Structures

CS242 COMPUTER PROGRAMMING

Information Science 1

Visual C# Instructor s Manual Table of Contents

The SPL Programming Language Reference Manual

Computer Skills (2) for Science and Engineering Students

Language Reference Manual

Chapter 7. Additional Control Structures

Exercise: Using Numbers

Java Primer 1: Types, Classes and Operators

Absolute C++ Walter Savitch

c++ keywords: ( all lowercase ) Note: cin and cout are NOT keywords.

C++ PROGRAMMING SKILLS Part 4: Arrays

Variables and literals

Information Science 1

Lecture 3 Tao Wang 1

Engineering Problem Solving with C++, Etter/Ingber

Java Fall 2018 Margaret Reid-Miller

1 Lexical Considerations

Declaration and Memory

Flow Control. CSC215 Lecture

A First Program - Greeting.cpp

Boolean Algebra Boolean Algebra

CS110: PROGRAMMING LANGUAGE I

1.3b Type Conversion

SFU CMPT Topic: Control Statements

CSEN 202 Introduction to Computer Programming

PRG PROGRAMMING ESSENTIALS. Lecture 2 Program flow, Conditionals, Loops

PIC 10A Pointers, Arrays, and Dynamic Memory Allocation. Ernest Ryu UCLA Mathematics

GridLang: Grid Based Game Development Language Language Reference Manual. Programming Language and Translators - Spring 2017 Prof.

Kingdom of Saudi Arabia Princes Nora bint Abdul Rahman University College of Computer Since and Information System CS240 BRANCHING STATEMENTS

Week 2. Relational Operators. Block or compound statement. if/else. Branching & Looping. Gaddis: Chapters 4 & 5. CS 5301 Spring 2018.

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Chapter 2. C++ Basics

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Transcription:

Outline Department of Mathematics and Computer Science Bronx Community College October 24, 2018

Outline Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence Type Conversions

Outline 1 Chapter 8: A C++ Introduction For Python Programmers Expressions and Operator Precedence Type Conversions

Local Variables Must be declared giving their datatypes, so values are guaranteed to fit in the memory locations reserved by the compiler. May optionally be initialized when declared. Local variables declared in a function (not formal parameters) are called automatic variables. They are given memory locations without putting values in those locations. So automatic variables must be initialized before use (to get predictable value). The memory for a variable holds an actual value, not a reference (as in Python). Exception: References (pointer variables) are specially denoted by *, the dereference operation.

Expressions Expressions Just as in any programming language, expressions have values. The simplest expressions are constants or variable names. Just as in any programming language, expressions are constructed by connecting smaller sub-expressions with operator symbols. These values are calculated by performing the operations, with the highest precedence operation first. Expressions can also be formed by making function calls which return values.

Expressions Operators Are Similar To Those In Python Exceptions: && for and. for or. increment operators: x++ or ++x for x += 1 decrement operators: x-- or --x for x -= 1

Expressions Operator Precedence The order of operations in C++ follows the same standard rules as Python: (a+b*c) means multiply b times c, then add a.

if statement Indentation is meaningless Since C++ ignores indentation, multiple statements in an if statement must be enclosed in braces to form a block.

if statement C++ Has No elif Multiple conditional branches in C++ require nested if statements.

Data Types Implicit Conversion Like Python, C++ automatically converts ints to floats or doubles when adding an integer to a float value.

Data Types Explicit Conversion C++ also performs explicit conversion with the static cast keyword.

Loops for Loops Over Different Values of a Single Variable In Python, a for loop must use a pre-existing sequence of values, like the list returned by the function range. In C++, a variable changes its value by incrementing or decrementing its value for each iteration of the loop.

Loops while Loops While loops in C++ are exactly like those in Python. They test for a boolean value to be true before they begin each iteration of the loop. When it is false, the loop is exited.

Loops do-while Loops Do-while loops in C++ are different than while loops in Python. They only test for the boolean value to be true at the end of each loop iteration. This means that a loop is guaranteed to execute at least once.

Single-Dimension Not As Safe as Python Lists No range checking is performed when an index is used. Can initialize values when declaring an array.

Multi-Dimensional of Any number of dimensions is supported. Consecutive addresses are easily found (fast random access via a formula).

of Characters Using of Characters is Risky char c[20]; cout << "enter your first name: "; // this code is a security risk // a buffer overflow occurs if the user enters // more than 19 characters cin >> c; cout << "Hello " << c << endl;

of Characters C Strings char arrays with terminating zero in last position. Literal string values (in quotes) are zero-terminated strings in C++. Convenient library functions for concatenation (strcat) etc. #include <string.h> for library functions

of Characters Better to use the C++ string class. #include <string> An object s capacity increases automatically. Convenient member functions for concatenation and other operations. Easy to initialize a C++ string from a char array. Rule-of-thumb: For text input/output (cin, cout), always use the string class!