C++ Modern and Lucid C++ for Professional Programmers

Similar documents
Chapter 1 Getting Started

C++ Modern and Lucid C++ for Professional Programmers

Fall 2017 CISC124 9/16/2017

C-Programming. CSC209: Software Tools and Systems Programming. Paul Vrbik. University of Toronto Mississauga

CE221 Programming in C++ Part 1 Introduction

Modern and Lucid C++ Advanced for Professional Programmers. Part 1 C Plus Plus Recap. Department I - C Plus Plus

Computer Science II Lecture 1 Introduction and Background

MODERN AND LUCID C++ ADVANCED

University of Technology. Laser & Optoelectronics Engineering Department. C++ Lab.

Motivation was to facilitate development of systems software, especially OS development.

CS 376b Computer Vision

5/3/2006. Today! HelloWorld in BlueJ. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont. HelloWorld in BlueJ, Cont.

Motivation was to facilitate development of systems software, especially OS development.

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

C++ Modern and Lucid C++ for Professional Programmers

Fast Introduction to Object Oriented Programming and C++

Array. Prepared By - Rifat Shahriyar

CS2141 Software Development using C/C++ C++ Basics

Lecture 2, September 4

Control Flow. COMS W1007 Introduction to Computer Science. Christopher Conway 3 June 2003

Lecture Set 4: More About Methods and More About Operators

Modern and Lucid C++ for Professional Programmers. Week 15 Exam Preparation. Department I - C Plus Plus

Variables. Data Types.

Modern and Lucid C++ Advanced for Professional Programmers. Part 3 Move Semantics. Department I - C Plus Plus Advanced

1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

Introduction to Programming Using Java (98-388)

Pointers (continued), arrays and strings

C++ for Python Programmers

QUIZ. What is wrong with this code that uses default arguments?

Getting started with Java

Programming Language Concepts: Lecture 2

Modern and Lucid C++ Advanced for Professional Programmers. Part 12 Advanced Library Design. Department I - C Plus Plus Advanced

6.096 Introduction to C++ January (IAP) 2009

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

Pointers (continued), arrays and strings

Basic Types, Variables, Literals, Constants

CSCI-1200 Data Structures Spring 2018 Lecture 14 Associative Containers (Maps), Part 1 (and Problem Solving Too)

Variables and Constants

COMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette

Lecture Set 4: More About Methods and More About Operators

CS 11 java track: lecture 1

PROGRAMMING FUNDAMENTALS

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

These are notes for the third lecture; if statements and loops.

Lecture 2. COMP1406/1006 (the Java course) Fall M. Jason Hinek Carleton University

III. Classes (Chap. 3)

Outline. 1 About the course

Type Conversion. and. Statements

Introduction to Programming (Java) 2/12

Programming. Syntax and Semantics

CS242 COMPUTER PROGRAMMING

Numbers. John Perry. Spring 2017

Homework 5. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

An overview of Java, Data types and variables

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Slide 1 CS 170 Java Programming 1 The Switch Duration: 00:00:46 Advance mode: Auto

Computational Physics Operating systems

Two Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

EMBEDDED SYSTEMS PROGRAMMING Language Basics

COMP 250 Winter 2011 Reading: Java background January 5, 2011

And Even More and More C++ Fundamentals of Computer Science

COP 3330 Final Exam Review

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5

3. Java - Language Constructs I

Multimedia-Programmierung Übung 3

Computer Science II (20082) Week 1: Review and Inheritance

PIC 10A Objects/Classes

Expressions & Flow Control

Software and Programming 1

A brief introduction to C programming for Java programmers

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

Getting started with Java

Materials covered in this lecture are: A. Completing Ch. 2 Objectives: Example of 6 steps (RCMACT) for solving a problem.

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

C++1z: Concepts-Lite !!! !!! !!!! Advanced Developer Conference C slides:

C++ Basics. Brian A. Malloy. References Data Expressions Control Structures Functions. Slide 1 of 24. Go Back. Full Screen. Quit.

COMP-202: Foundations of Programming

Visual C# Instructor s Manual Table of Contents

Looping and Counting. Lecture 3 Hartmut Kaiser hkaiser/fall_2012/csc1254.html

Values and Variables 1 / 30

Introduction to Java

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

Pace University. Fundamental Concepts of CS121 1

Looping and Counting. Lecture 3. Hartmut Kaiser hkaiser/fall_2011/csc1254.html

CS 261 Fall C Introduction. Variables, Memory Model, Pointers, and Debugging. Mike Lam, Professor

ME240 Computation for Mechanical Engineering. Lecture 4. C++ Data Types

Java Bytecode (binary file)

C Introduction. Comparison w/ Java, Memory Model, and Pointers

QUIZ. 1. Explain the meaning of the angle brackets in the declaration of v below:

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

Program Fundamentals

Outline. Introduction. Arrays declarations and initialization. Const variables. Character arrays. Static arrays. Examples.

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

Getting started with C++ (Part 2)

Agenda CS121/IS223. Reminder. Object Declaration, Creation, Assignment. What is Going On? Variables in Java

Modern and Lucid C++ Advanced for Professional Programmers. Part 7 Compile-Time Computation. Department I - C Plus Plus

Cours de C++ Introduction

AIMS Embedded Systems Programming MT 2017

Transcription:

Informatik C++ Modern and Lucid C++ for Professional Programmers Part 1 Self-study for Introduction to C++ Prof. Peter Sommerlad Director IFS Institute for Software Rapperswil, HS 2017 Thomas Corbat

Additional self-study slides

A first Class - Type Definition class and struct keywords are equivalent struct means public: class means private: visibility does not need to be specified for each element Implementation names memberfunction with class name Object instantiated and member function called 3

Watch out: Semicolon after }; in class definitions Don't forget the semicolon! If you omit the semicolon after a class definition you will get very strange error messages, often far away from where you forgot the semicolon You can try that deliberately, but it will happen anyway! Just remember this! You've been warned 4

Tests for Classes in a Library C++ Library Project CUTE Library Test Project 5

Why C++? Someone on a mailing list Sept. 2013: Microsoft are trying their damnedest to destroy the desktop Windows environment in favour of the "Windows Store" environment (which they evidently see as a moneyspinner as it allows them to commoditize software in the same way as music, video, books, etc.). Net isn't part of that Windows store culture, and I don't see it surviving the upheaval in the long term... C++ (or, at least, Microsoft's chosen subset of it) *is* part of that culture, and I see it as being on the resurgence in the Microsoft world. 6

Why C++ (again) Can be portable across platforms more than with Java and.net but requires care to actually be portable Highly efficient, if applied right can be more efficient than C with a fraction of source code real estate Powerful systems programming tool unfortunately no standard C++11 UI frameworks available 7

C++ is Powerful more powerful concepts than Java, even if it looks similar high-level abstraction capabilities values, functions, operators types, classes, objects generic types and functions with templates compile-time programming (C++ advanced) ability to apply these concepts can result in less code to write: more efficient development But learning C++ requires hard work 8

C++ vs. Java Many similarities in syntax: if(cond){}else{} for(i = 0; i < last, ++i){} for(auto const x:vec){} while(true){} do{}while(false); Type variable; // for defining a variable visibility and scoping rules But they are not the same semantic and rules are different 9

C++ vs. Java: Types and Values All types in C++ describe values references have to be designated explicitly type construction defaults lead to value types user-defined types can work like built-in types: wrt. syntax and performance All user-defined types in Java are objects except: int, char, short, long, boolean, double, float, byte 10

C++ vs. Java: Built-in types Java defines definitive ranges for int, long, etc. and 2bit complement representation no "unsigned" numbers C++ provides a sequence of range inclusion, but no definitive bit count for its integers for hardware diversity char <= short <= int <= long <= long long float <= double <= long double C++ provides unsigned integral types (0.. 2 n-1 ) C++ measures sizes in number of char sizeof(char) == 1, but a char might not be an octet of bits 11

C++ vs. Java: Conversion and Types C++ converts automatically between types if one-step conversion possible, unless prohibited some pitfalls exist for careless programmer almost all casts demonstrate a design problem Java type conversion only happens for objects along their class hierarchy casting required up the hierarchy or for explicit conversion of built-in types 12

C++ vs. Java: true and false C++ represents truth values as type bool bool is an integer type: 5 + true == 6 + false In conditions all values that can be converted to a number or bool can act as truth values, only zero is considered false if (42) doit(); else never_happens(); do { only_once(); } while(0); while(std::cin) { std::cin>>x; std::cout<<x*x;} 13

C++ vs. Java: code organization Java provides computation in Methods always part of a class C++ provides computation in functions some may be a class member return_type function(parameter) {... } #include <iostream> #include <string> int main(){ std::string message; message = "Hello World"; std::cout << message << std::endl; } C++ public class HelloWorld { public static void main(string[] args) { String message = new String(); message = "Hello"; System.out.println(message); } } 14

A note on the self-study material aka my "Lucid C++" book I will provide about a chapter for each week for you to read and prepare. The book is a work in progress. While the chapters for the first half of the semester are quite complete and mature, you should expect some rough edges when we reach mid- November. Any feedback you can give me (except for simple typos, which will be rid later) is really appreciated, e.g., if something is too hard to understand, errors in examples or reasoning. 15