C++ For Science and Engineering Lecture 2

Similar documents
C++ For Science and Engineering Lecture 15

C++ For Science and Engineering Lecture 12

Intro to Programming & C Why Program? 1.2 Computer Systems: Hardware and Software. Why Learn to Program?

Your First C++ Program. September 1, 2010

Programmazione. Prof. Marco Bertini

Unit 10. Linux Operating System

Exercise 1.1 Hello world

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

Object-oriented Programming for Automation & Robotics Carsten Gutwenger LS 11 Algorithm Engineering

Getting started with C++ (Part 2)

Unit 13. Linux Operating System Debugging Programs

Lecture 7. Log into Linux New documents posted to course webpage

LECTURE 02 INTRODUCTION TO C++

Lab # 02. Basic Elements of C++ _ Part1

CSE 374 Programming Concepts & Tools. Hal Perkins Spring 2010

My First Command-Line Program

Basic memory model Using functions Writing functions. Basics Prototypes Parameters Return types Functions and memory Names and namespaces

Introduction to Programming using C++

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Modern C++ for Computer Vision and Image Processing. Igor Bogoslavskyi and Cyrill Stachniss

Chapter 1 Introduction to Computers and C++ Programming

CE221 Programming in C++ Part 1 Introduction

Numerical Algorithms for Physics. Andrea Mignone Physics Department, University of Torino AA

pointers + memory double x; string a; int x; main overhead int y; main overhead

Deadline. Purpose. How to submit. Important notes. CS Homework 9. CS Homework 9 p :59 pm on Friday, April 7, 2017

VARIABLES & ASSIGNMENTS

Welcome to MCS 360. content expectations. using g++ input and output streams the namespace std. Euclid s algorithm the while and do-while statements

You should see something like this, called the prompt :

EP241 Computer Programming

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

Compiling with Multiple Files The Importance of Debugging CS 16: Solving Problems with Computers I Lecture #7

Chapter 1 INTRODUCTION

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

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

Object Oriented Design

y

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

Course "Data Processing" Name: Master-1: Nuclear Energy Session /2018 Examen - Part A Page 1

BITG 1113: Function (Part 2) LECTURE 5

CS Homework 10 p. 1. CS Homework 10

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

Introduction to Lab Sessions

Lecture on pointers, references, and arrays and vectors

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 19 Introduction to C++

4. Structure of a C++ program

CS 241 Computer Programming. Introduction. Teacher Assistant. Hadeel Al-Ateeq

Unit 7. 'while' Loops

CS11 Introduction to C++ Fall Lecture 1

Compiling C/C++ programs

PIC 10A Objects/Classes

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Chapter 1 An Introduction to C++, Unix, SSH and Komodo Edit

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

CS246-Assign01 V1.1: Winter 2013

Chapter 2: Introduction to C++

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

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

Chapter 1 Introduction to Computers and Programming

CSE 303: Concepts and Tools for Software Development

Introduction to C++ Programming Pearson Education, Inc. All rights reserved.

The Edit-Compile-Run Cycle. EECS 211 Winter 2017

Operator overloading

Study Guide for Test 2

CS101 Linux Shell Handout

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

Object Oriented Design

download instant at Introduction to C++

Introduction to Programming

Spring CS Homework 12 p. 1. CS Homework 12

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

Computer Programming : C++

Chapter 2: Basic Elements of C++

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

CS 2400 Laboratory Assignment #1: Exercises in Compilation and the UNIX Programming Environment (100 pts.)

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

Starting to Program in C++ (Basics & I/O)

Scientific Computing

Introduction to C++ (Extensions to C)

Streams. Ali Malik

Tutorial-2a: First steps with C++ programming

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Fast Introduction to Object Oriented Programming and C++

UEE1302 (1102) F10: Introduction to Computers and Programming

Chapter 1: Why Program? Computers and Programming. Why Program?

Objectives. In this chapter, you will:

Intermediate Programming Programming-Tools and Sorting-Algorithms Exercise Sheet Deadline on 13th of November 2009

Week 0: Intro to Computers and Programming. 1.1 Why Program? 1.2 Computer Systems: Hardware and Software. Hardware Components

Tutorial 1: Unix Basics

Lecture 14: more class, C++ streams

W3101: Programming Languages C++ Ramana Isukapalli

Introduction to C ++

More Examples Using Functions and Command-Line Arguments in C++ CS 16: Solving Problems with Computers I Lecture #6

assembler Machine Code Object Files linker Executable File

EE 355 Lab 4 - Party Like A Char Star

Sample Final Exam. 1) (24 points) Show what is printed by the following segments of code (assume all appropriate header files, etc.

CSC111 Computer Science II

CIS220 In Class/Lab 1: Due Sunday night at midnight. Submit all files through Canvas (25 pts)

Introduction to C++ Programming. Adhi Harmoko S, M.Komp

Welcome Back. CSCI 262 Data Structures. Hello, Let s Review. Hello, Let s Review. How to Review 1/9/ Review. Here s a simple C++ program:

Programming Studio #1 ECE 190

Transcription:

C++ For Science and Engineering Lecture 2 John Chrispell Tulane University Wednesday August 25, 2010

Basic Linux Commands Command ls pwd cd What it does. lists the files in the current directory prints the working directory if no argument is given you are changed to working in your home directory chaged working in the path directory Copies old.file to new file cd path cp file copied.file rm file removes file mkdir name makes a directory called name John Chrispell, Wednesday August 25, 2010 slide 2/12

Basic Linux Commands On the command line an * is a generic place holder of unspecified length. John Chrispell, Wednesday August 25, 2010 slide 3/12

Basic Linux Commands On the command line an * is a generic place holder of unspecified length. A? is a generic place holder of length one. John Chrispell, Wednesday August 25, 2010 slide 3/12

Basic Linux Commands On the command line an * is a generic place holder of unspecified length. A? is a generic place holder of length one. The symbol. means this working directory. Achieves absoloutly nothing! Example cd./ John Chrispell, Wednesday August 25, 2010 slide 3/12

Basic Linux Commands On the command line an * is a generic place holder of unspecified length. A? is a generic place holder of length one. The symbol. means this working directory. Achieves absoloutly nothing! Example cd./ The symbol.. means back one directory. moves up one directory. Example cd.. John Chrispell, Wednesday August 25, 2010 slide 3/12

Basic Linux Commands You can look up what commands do by using the man command: Example: man ls tells you what ls does and how to use it. John Chrispell, Wednesday August 25, 2010 slide 4/12

Basic Linux Commands You can look up what commands do by using the man command: Example: man ls tells you what ls does and how to use it. The < tab > is also very useful. John Chrispell, Wednesday August 25, 2010 slide 4/12

The main() function Recall the simple program from last class. John Chrispell, Wednesday August 25, 2010 slide 5/12

Parts of a Program Every program has a main function. John Chrispell, Wednesday August 25, 2010 slide 6/12

Parts of a Program Every program has a main function. The main function is called main(). John Chrispell, Wednesday August 25, 2010 slide 6/12

Parts of a Program Every program has a main function. The main function is called main(). In the example given it is of integer type or int John Chrispell, Wednesday August 25, 2010 slide 6/12

Parts of a Program Every program has a main function. The main function is called main(). In the example given it is of integer type or int Note the return statement at the bottom. John Chrispell, Wednesday August 25, 2010 slide 6/12

Parts of a Program Every program has a main function. The main function is called main(). In the example given it is of integer type or int Note the return statement at the bottom. Spelling and capitalization counts! John Chrispell, Wednesday August 25, 2010 slide 6/12

Comments in your code! You do not only write code for yourself. Be nice to yourself and anyone reading your code. This means code should be well commented. It also means that your code should be well blocked (4 space indenting is a good rule). You never know when you are going to have to come back to something your have written again in the future. I have to grade it. code // comment c++ style code /* comment c style */ John Chrispell, Wednesday August 25, 2010 slide 7/12

The iostream file John Chrispell, Wednesday August 25, 2010 slide 8/12

The iostream file The #include < iostream > allows the program to have input and out put streams. John Chrispell, Wednesday August 25, 2010 slide 8/12

The iostream file The #include < iostream > allows the program to have input and out put streams. The include statment is replaced by the file iostream durring preprocessing when the code is compiled. John Chrispell, Wednesday August 25, 2010 slide 8/12

The iostream file The #include < iostream > allows the program to have input and out put streams. The include statment is replaced by the file iostream durring preprocessing when the code is compiled. In moderm C++ the header files do not have the.h extension that you may be used to in C or FORTRAN. John Chrispell, Wednesday August 25, 2010 slide 8/12

Namespaces John Chrispell, Wednesday August 25, 2010 slide 9/12

Namespaces The is called using a directive. using namespace std; John Chrispell, Wednesday August 25, 2010 slide 9/12

Namespaces The is called using a directive. using namespace std; It allows for vendors or programmers use more than one function with the same name. John Chrispell, Wednesday August 25, 2010 slide 9/12

Namespaces The is called using a directive. using namespace std; It allows for vendors or programmers use more than one function with the same name. In the sample program the cout function lives in the std namespace. John Chrispell, Wednesday August 25, 2010 slide 9/12

Namespaces The is called using a directive. using namespace std; It allows for vendors or programmers use more than one function with the same name. In the sample program the cout function lives in the std namespace. We could have used code that looked like: std::cout << This is my first c++ program. ; if we had omitted the using namespace statement; John Chrispell, Wednesday August 25, 2010 slide 9/12

cout itself John Chrispell, Wednesday August 25, 2010 slide 10/12

cout itself In the line std::cout << This is my first c++ program. ; cout - is an object (a particular instance of a class). << - is the insertion operator This is my first c++ program. - is a string. John Chrispell, Wednesday August 25, 2010 slide 10/12

cout itself In the line std::cout << This is my first c++ program. ; cout - is an object (a particular instance of a class). << - is the insertion operator This is my first c++ program. - is a string. We don t know anything about the object cout we just know how to use it. John Chrispell, Wednesday August 25, 2010 slide 10/12

cout itself In the line std::cout << This is my first c++ program. ; cout - is an object (a particular instance of a class). << - is the insertion operator This is my first c++ program. - is a string. We don t know anything about the object cout we just know how to use it. If you know C then << looks just like the bitwise left-shift operator. This is an example of operator overloading. John Chrispell, Wednesday August 25, 2010 slide 10/12

endl endl is the end line manipulator (as it has special meaning to cout). John Chrispell, Wednesday August 25, 2010 slide 11/12

endl endl is the end line manipulator (as it has special meaning to cout). We may also use the new line character \n in a string: cout << \n ; // starts a new line cout << endl; // starts a new line C++ programmers would argue that endl is easier to type. John Chrispell, Wednesday August 25, 2010 slide 11/12

White Space Spacing in the code helps make it readable. C++ allows statments to be spread over multiple lines. You can t have spacing in some places! Demo. John Chrispell, Wednesday August 25, 2010 slide 12/12