Programsystemkonstruktion med C++: Övning 1. Karl Palmskog Translated by: Siavash Soleimanifard. September 2011

Size: px
Start display at page:

Download "Programsystemkonstruktion med C++: Övning 1. Karl Palmskog Translated by: Siavash Soleimanifard. September 2011"

Transcription

1 Programsystemkonstruktion med C++: Övning 1 Karl Palmskog palmskog@kth.se Translated by: Siavash Soleimanifard September 2011

2 Programuppbyggnad Klassens uppbyggnad A C++ class consists of a declaration and definition Declaration, usually in.h (.hh) and the definition in.cpp (.cc) private is the default for functions and variables in classes Global functions and variables is OK main is a global function Macro (starts with #) is driven by the preprocessor before compilation

3 Programuppbyggnad Example of declaration: inventory item.h #i f n d e f INVENTORY ITEM H #d e f i n e INVENTORY ITEM H #i n c l u d e <c s t d d e f > c l a s s I n v e n t o r y I t e m { p r i v a t e : double c o s t ; s i z e t u n i t s ; p u b l i c : s t a t i c const double DEF COST = 1 0 ; s t a t i c const s i z e t DEF UNITS = ; I n v e n t o r y I t e m ( ) : c o s t (DEF COST ), u n i t s ( DEF UNITS ) { I n v e n t o r y I t e m ( double c, s i z e t u ) ; I n v e n t o r y I t e m ( ) { double v a l u e ( ) const ; void removeunits ( s i z e t u ) ; ; #e n d i f

4 Programuppbyggnad Exampel of definition: inventory item.cpp #i n c l u d e i n v e n t o r y i t e m. h I n v e n t o r y I t e m : : I n v e n t o r y I t e m ( double c, s i z e t u ) { c o s t = c < 0? 0 : c ; u n i t s = u ; double I n v e n t o r y I t e m : : v a l u e ( ) const { r e t u r n c o s t u n i t s ; void I n v e n t o r y I t e m : : removeunits ( s i z e t u ) { i f ( u > u n i t s ) { u n i t s = 0 ; e l s e { u n i t s = u ;

5 Programuppbyggnad Exempel på användning av klassdeklaration: main.cpp #i n c l u d e i n v e n t o r y i t e m. h #i n c l u d e <i o s t r e a m > using namespace s t d ; i n t main ( ) { I n v e n t o r y I t e m d e f a u l t I t e m ; cout << d e f a u l t I t e m. v a l u e ( ) << e n d l ; I n v e n t o r y I t e m customitem ( 2 0, ) ; cout << customitem. v a l u e ( ) << e n d l ; customitem. removeunits ( 5 0 ) ; cout << customitem. v a l u e ( ) << e n d l ; customitem. removeunits ( ) ; cout << customitem. v a l u e ( ) << e n d l ; r e t u r n 0 ;

6 Kompilering och körning av program Examples of compilation and execution of programs Compilation with g++ directly to the program and run: $ g++ o i i main. cpp i n v e n t o r y i t e m. cpp $. / i i Equivalent to the object files compiled separately: $ g++ c i n v e n t o r y i t e m. cpp $ g++ c main. cpp $ g++ o i i main. o i n v e n t o r y i t e m. o With the warnings, debug symbols and optimization: $ g++ o i i d e b u g Wall g O1 main. cpp i n v e n t o r y i t e m. cpp

7 Kompilering och körning av program The program s path to the execution Källkod (.c,.cpp,.h,...) Bibliotekskod (.so,.a,.dll,...) Startkod Kompilator Objektkod (.o) Länkare Exekverbar kod (.exe,...)

8 Kompilering och körning av program Depending Handling If we change the main.cpp it suffices to recompile If we change the inventory item.cpp/h, we might compile on both inventory item.cpp and main.cpp Hard to keep track of dependencies Always recompile everything is slow interesting error about everything that needs to compile does not recompile A solution: use the tool make

9 Kompilering och körning av program A simple Makefile i i : main. o i n v e n t o r y i t e m. o g++ o i i main. o i n v e n t o r y i t e m. o main. o : main. cpp i n v e n t o r y i t e m. h g++ c main. cpp i n v e n t o r y i t e m. o : i n v e n t o r y i t e m. cpp i n v e n t o r y i t e m. h g++ c i n v e n t o r y i t e m. cpp c l e a n : rm f main. o i n v e n t o r y i t e m. o i i

10 Kompilering och körning av program A more advanced Makefile CC = g++ FLAGS = g I / l i b s OBJ = main. o i n v e n t o r y i t e m. o SRC = main. cpp i n v e n t o r y i t e m. cpp PROG = i i $ (PROG) : $ (OBJ) $ (CC) $ (FLAGS) o $ (PROG) $ (OBJ) %.o : %.cpp $ (CC) $ (FLAGS) c $. cpp c l e a n : rm f. o $ (PROG) depend : $ (SRC) makedepend $ ( FLAGS) $ˆ

11 Språkfunktionalitet Preprocessor Directives #include merge files before compiling #ifndef... #define... #endif ensures that a file included only once // may be u s e f u l #d e f i n e MAX // dangerous #d e f i n e SQR1(A) A A // l e s s dangerous #d e f i n e SQR2(A) (A) (A)

12 Språkfunktionalitet Function main function main is special can not be called anything else argc is the number of arguments incl. program name argv is an array of C-strings using the arguments given to program argv[0] is the program name (e.g., /usr/bin/zip or zip) main is a global function and not part of any class main no need to be declared

13 Språkfunktionalitet Pointers void f o o ( I n v e n t o r y I t e m i t ) { i n t ptr, i ; // p t r i s p t r to i n t, i i s i n t i n t x, y ; // x i s p t r to i n t, y i s i n t p t r = &i ; // p t r now h o l d s a d d r e s s o f i ( e. g. 0 x b f f f f f 2 4 ) p t r = 5 ; // a s s i g n 5 to i x = p t r ; // x now a l s o p o i n t s to i cout << x << e n d l ; // would p r i n t 5 ( i t ). removeunits ( 1 0 ) ; i t >removeunits ( 1 0 ) ; p t r = new i n t ; // p t r now h o l d s adr o f i n t on heap p t r = &y ;

14 Språkfunktionalitet Pointers void f o o ( I n v e n t o r y I t e m i t ) { i n t ptr, i ; // p t r i s p t r to i n t, i i s i n t i n t x, y ; // x i s p t r to i n t, y i s i n t p t r = &i ; // p t r now h o l d s a d d r e s s o f i ( e. g. 0 x b f f f f f 2 4 ) p t r = 5 ; // a s s i g n 5 to i x = p t r ; // x now a l s o p o i n t s to i cout << x << e n d l ; // would p r i n t 5 ( i t ). removeunits ( 1 0 ) ; i t >removeunits ( 1 0 ) ; p t r = new i n t ; // p t r now h o l d s adr o f i n t on heap p t r = &y ; // no way to a c c e s s memory anymore

15 Språkfunktionalitet Pointers and Arrays void f o o ( f l o a t f ) { char a r r a y [ ] ; // a r r a y o f 4711 u n i n i t i a l i z e d c h a r s i n t a r y [ ] = { 1, 2, 5 ; // a r r a y o f 3 i n i t i a l i z e d i n t s // same as c o n s t c h a r s t r [ ] = { h, e, j, 0 ; char s t r [ ] = h e j ; char p t r = 0 ; // c h a r p o i n t e r to n o t h i n g const f l o a t f P t r ; // memory p o i n t e d to i s r e a d o n l y f l o a t const f c P t r=f ; // p o i n t e r f i s r e a d o n l y p t r = a r r a y ; // same as p t r = &a r r a y [ 0 ] ; p t r [ 4 ] = x ; // s e t f i f t h element o f a r r a y to x ( p t r + 4) = y ; // same t h i n g, but to y p t r = new char [ ] ; // d y n a m i c a l l y a l l o c a t e d a r r a y

16 Språkfunktionalitet Referencing alias for an object as a pointer whose address can not be changed must refer to an object (not NULL) void iswap ( i n t &i1, i n t &i 2 ) { i n t tmp = i 1 ; i 1 = i 2 ; i 2 = tmp ; void main ( ) { i n t i = 5 ; i n t &i R e f = i ; i n t i P t r = &i ; i R e f ++; // i, i R e f and i P t r i s now 6

17 FAQs Common mistakes void f o o ( i n t p ) { d e l e t e p ; i n t bar ( ) { i n t x = 1 ; r e t u r n &x ; void fun ( ) { i n t p1, p2 ; i n t p3 = new i n t [ 2 ] ; i n t p4 = new i n t [ 2 ] ; p3 = p4 ; f o o ( p3 ) ; i n t x = p4 [ 1 ] ;

18 FAQs Common mistakes void f o o ( i n t p ) { d e l e t e p ; i n t bar ( ) { i n t x = 1 ; r e t u r n &x ; // oops! void fun ( ) { i n t p1, p2 ; // p2 i s normal i n t not p o i n t e r i n t p3 = new i n t [ 2 ] ; i n t p4 = new i n t [ 2 ] ; p3 = p4 ; // MEMORY LEAK! f o o ( p3 ) ; // d e s t r u c t i o n o f p3 ( and p4 ) i n t x = p4 [ 1 ] ; // e r r o r ( s e g f a u l t i f LUCKY)

19 FAQs Common errors at compile calls to functions whose header was not included with the include, to use the cout must be such as to have #include<iostream> calls to functions in the namespace std without having declared using namespace std, call to cout must then be written std:: court all object files are not compiled on the code updating use of C-compiler gcc instead of g++ functions used are not declared as public (private is the default) class declaration does not end with a semicolon

20 Testning Testing testing is the process of testing some of the executions of a system for a given criteria. unit testing is the process to test the smallest components of a system (functions and classes) in an isolated environment. Some reasons for testing: evidence that the code does what it should allows restructuring with the same functionality faster localization of introduced bugs Test early. Test often. Test automatic.

21 Testning Testramverket cxxtest test framework for C++ which only requires a compiler and Python tests are written in a separate file, executable code generated by scripting test is organized into test suites (test suites) in the test functions are claims with macros such as TS ASSERT and TS ASSERT EQUALS for more information on the cxxtest

22 Testning Exampel on unit testing: inventory item test.cpp #i n c l u d e <c x x t e s t / T e s t S u i t e. h> #i n c l u d e i n v e n t o r y i t e m. h c l a s s I n v e n t o r y I t e m T e s t : p u b l i c CxxTest : : T e s t S u i t e { p u b l i c : void t e s t d e f a u l t c o s t a n d u n i t s ( void ) { I n v e n t o r y I t e m i t ; TS ASSERT EQUALS( i t. v a l u e ( ), I n v e n t o r y I t e m : : DEF COST I n v e n t o r y I t e m : : DEF UNITS ) ; void t e s t n e g a t i v e c o s t ( void ) { I n v e n t o r y I t e m i t ( 10, ) ; TS ASSERT EQUALS( i t. v a l u e ( ), 0 ) ; ;

23 Testning Makefile for cxxtest CC = g++ FLAGS = g OBJ = i n v e n t o r y i t e m. o PROG = t e s t r u n n e r t e s t r u n n e r. o $ (PROG) : $ (OBJ) $ (CC) $ (FLAGS) o $ (PROG) $ (OBJ) %.o : %.cpp $ (CC) $ (FLAGS) c $. cpp t e s t r u n n e r. cpp : i n v e n t o r y i t e m t e s t. cpp i n v e n t o r y i t e m. h c x x t e s t g e n. py e r r o r p r i n t e r o t e s t r u n n e r. cpp \ i n v e n t o r y i t e m t e s t. cpp c l e a n : rm f. o $ (PROG) t e s t r u n n e r. cpp

24 Testning Running tests $ make g++ g c i n v e n t o r y i t e m. cpp c x x t e s t g e n. py e r r o r p r i n t e r o t e s t r u n n e r. cpp \ i n v e n t o r y i t e m t e s t. cpp g++ g c t e s t r u n n e r. cpp g++ g o t e s t r u n n e r i n v e n t o r y i t e m. o t e s t r u n n e r. o $. / t e s t r u n n e r Running 2 t e s t s.. OK! If cost can find negative values: $. / t e s t r u n n e r Running 2 t e s t s. I n I n v e n t o r y I t e m T e s t : : t e s t n e g a t i v e c o s t : i n v e n t o r y i t e m t e s t. cpp : 1 5 : E r r o r : Expected ( i t. v a l u e ( ) == 0 ), found ( != 0) F a i l e d 1 o f 2 t e s t s S u c c e s s r a t e : 50%

INTRODUCTION. This is not a full c-programming course. It is not even a full 'Java to c' programming course.

INTRODUCTION. This is not a full c-programming course. It is not even a full 'Java to c' programming course. C PROGRAMMING 1 INTRODUCTION This is not a full c-programming course. It is not even a full 'Java to c' programming course. 2 LITTERATURE 3. 1 FOR C-PROGRAMMING The C Programming Language (Kernighan and

More information

C++ For Science and Engineering Lecture 8

C++ For Science and Engineering Lecture 8 C++ For Science and Engineering Lecture 8 John Chrispell Tulane University Friday 10, 2010 Arrays Structures are ways of storing more than one type of information together. A structure is a vesatile data

More information

Comp 11 Lectures. Mike Shah. July 26, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 26, / 40

Comp 11 Lectures. Mike Shah. July 26, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 26, / 40 Comp 11 Lectures Mike Shah Tufts University July 26, 2017 Mike Shah (Tufts University) Comp 11 Lectures July 26, 2017 1 / 40 Please do not distribute or host these slides without prior permission. Mike

More information

CS 7B - Fall Final Exam (take-home portion). Due Wednesday, 12/13 at 2 pm

CS 7B - Fall Final Exam (take-home portion). Due Wednesday, 12/13 at 2 pm CS 7B - Fall 2017 - Final Exam (take-home portion). Due Wednesday, 12/13 at 2 pm Write your responses to following questions on separate paper. Use complete sentences where appropriate and write out code

More information

C++ For Science and Engineering Lecture 14

C++ For Science and Engineering Lecture 14 C++ For Science and Engineering Lecture 14 John Chrispell Tulane University Monday September 27, 2010 File Input and Output Recall writing text to standard out You must include the iostream header file.

More information

PHP Extension Development with C++

PHP Extension Development with C++ PHP Extension Development with C++ Wrapping a C preprocessor API in C++ Florian Sowade August 25, 2012 About Me Florian Sowade Head of embedded software development at crosscan GmbH Currently studying

More information

APPENDIX A FASTFLOW A.1 DESIGN PRINCIPLES

APPENDIX A FASTFLOW A.1 DESIGN PRINCIPLES APPENDIX A FASTFLOW A.1 DESIGN PRINCIPLES FastFlow 1 has been designed to provide programmers with efficient parallelism exploitation patterns suitable to implement (fine grain) stream parallel applications.

More information

Auto-Tuning Complex Array Layouts for GPUs - Supplemental Material

Auto-Tuning Complex Array Layouts for GPUs - Supplemental Material BIN COUNT EGPGV,. This is the author version of the work. It is posted here by permission of Eurographics for your personal use. Not for redistribution. The definitive version is available at http://diglib.eg.org/.

More information

C++ For Science and Engineering Lecture 10

C++ For Science and Engineering Lecture 10 C++ For Science and Engineering Lecture 10 John Chrispell Tulane University Wednesday 15, 2010 Introducing for loops Often we want programs to do the same action more than once. #i n c l u d e

More information

Numerical differentiation

Numerical differentiation Chapter 3 Numerical differentiation 3.1 Introduction Numerical integration and differentiation are some of the most frequently needed methods in computational physics. Quite often we are confronted with

More information

Notater: INF3331. Veronika Heimsbakk December 4, Introduction 3

Notater: INF3331. Veronika Heimsbakk December 4, Introduction 3 Notater: INF3331 Veronika Heimsbakk veronahe@student.matnat.uio.no December 4, 2013 Contents 1 Introduction 3 2 Bash 3 2.1 Variables.............................. 3 2.2 Loops...............................

More information

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal

1 ListElement l e = f i r s t ; / / s t a r t i n g p o i n t 2 while ( l e. next!= n u l l ) 3 { l e = l e. next ; / / next step 4 } Removal Präsenzstunden Today In the same room as in the first week Assignment 5 Felix Friedrich, Lars Widmer, Fabian Stutz TA lecture, Informatics II D-BAUG March 18, 2014 HIL E 15.2 15:00-18:00 Timon Gehr (arriving

More information

More on Methods and Encapsulation

More on Methods and Encapsulation More on Methods and Encapsulation Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 31, 2009 H.-T. Lin (NTU CSIE) More on Methods and Encapsulation OOP(even) 03/31/2009 0 / 38 Local Variables Local

More information

Gascoigne 3D High Performance Adaptive Finite Element Toolkit

Gascoigne 3D High Performance Adaptive Finite Element Toolkit Introduction to Gascoigne 3D High Performance Adaptive Finite Element Toolkit Tutorial and manuscript by Thomas Richter thomas.richter@iwr.uni-heidelberg.de April 25, 2014 2 Contents 1 Introduction 5 1.1

More information

ITI Introduction to Computing II

ITI Introduction to Computing II (with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 9, 2019 Please don t print these lecture notes unless you really need to!

More information

C++ For Science and Engineering Lecture 17

C++ For Science and Engineering Lecture 17 C++ For Science and Engineering Lecture 17 John Chrispell Tulane University Monday October 4, 2010 Functions and C-Style Strings Three methods for representing the C-style string: An array of char A quoted

More information

Scripting Languages Fast development, extensible programs

Scripting Languages Fast development, extensible programs Scripting Languages Fast development, extensible programs Devert Alexandre School of Software Engineering of USTC November 30, 2012 Slide 1/60 Table of Contents 1 Introduction 2 Dynamic languages A Python

More information

More About Methods. Hsuan-Tien Lin. Deptartment of CSIE, NTU. OOP Class, March 8-9, 2010

More About Methods. Hsuan-Tien Lin. Deptartment of CSIE, NTU. OOP Class, March 8-9, 2010 More About Methods Hsuan-Tien Lin Deptartment of CSIE, NTU OOP Class, March 8-9, 2010 H.-T. Lin (NTU CSIE) More About Methods OOP 03/08-09/2010 0 / 24 Methods: the Basic Method (1/2, Callee s View) 1 p

More information

List reversal: back into the frying pan

List reversal: back into the frying pan List reversal: back into the frying pan Richard Bornat March 20, 2006 Abstract More than thirty years ago Rod Burstall showed how to do a proof of a neat little program, shown in a modern notation in figure

More information

E23: Hotel Management System Wen Yunlu Hu Xing Chen Ke Tang Haoyuan Module: EEE 101

E23: Hotel Management System Wen Yunlu Hu Xing Chen Ke Tang Haoyuan Module: EEE 101 E23: Hotel Management System Author: 1302509 Zhao Ruimin 1301478 Wen Yunlu 1302575 Hu Xing 1301911 Chen Ke 1302599 Tang Haoyuan Module: EEE 101 Lecturer: Date: Dr.Lin December/22/2014 Contents Contents

More information

Introduction to MPI. School of Computational Science, 21 October 2005

Introduction to MPI. School of Computational Science, 21 October 2005 Introduction to MPI John Burkardt School of Computational Science Florida State University... http://people.sc.fsu.edu/ jburkardt/presentations/ mpi 2005 fsu.pdf School of Computational Science, 21 October

More information

1 Java Night Countdown (30%)

1 Java Night Countdown (30%) Midterm Examination Problem Sheet TIME: 04/18/2009, 19:00 21:00 This is a open-textbook exam. You can use the Absolute Java textbook as your reference during the exam. Any other references are not allowed.

More information

Make and Gprof COS 217

Make and Gprof COS 217 Make and Gprof COS 217 1 Goals of Today s Lecture Overview of two important programming tools o Make for compiling and linking multi-file programs o Gprof for profiling to identify slow parts of the code

More information

Basic Java OOP 10/12/2015. Department of Computer Science & Information Engineering. National Taiwan University

Basic Java OOP 10/12/2015. Department of Computer Science & Information Engineering. National Taiwan University Basic Java OOP 10/12/2015 Hsuan-Tien Lin ( 林軒田 ) htlin@csie.ntu.edu.tw Department of Computer Science & Information Engineering National Taiwan University ( 國立台灣大學資訊工程系 ) Hsuan-Tien Lin (NTU CSIE) Basic

More information

ITI Introduction to Computing II

ITI Introduction to Computing II (with contributions from R. Holte) School of Electrical Engineering and Computer Science University of Ottawa Version of January 11, 2015 Please don t print these lecture notes unless you really need to!

More information

Applied C Fri

Applied C Fri Applied C++11 2013-01-25 Fri Outline Introduction Auto-Type Inference Lambda Functions Threading Compiling C++11 C++11 (formerly known as C++0x) is the most recent version of the standard of the C++ Approved

More information

NGsolve::Give me your element

NGsolve::Give me your element NGsolve::Give me your element And let your eyes delight in my ways Jay Gopalakrishnan Portland State University Winter 2015 Download code (works only on version 6.0) for these notes from here. Give me

More information

Introduction to functions

Introduction to functions Introduction to functions Comp Sci 1570 Introduction to C++ Outline 1 2 Functions A function is a reusable sequence of s designed to do a particular job. In C++, a function is a group of s that is given

More information

Searching, mainly via Hash tables

Searching, mainly via Hash tables Data structures and algorithms Part 11 Searching, mainly via Hash tables Petr Felkel 26.1.2007 Topics Searching Hashing Hash function Resolving collisions Hashing with chaining Open addressing Linear Probing

More information

High-performance processing and development with Madagascar. July 24, 2010 Madagascar development team

High-performance processing and development with Madagascar. July 24, 2010 Madagascar development team High-performance processing and development with Madagascar July 24, 2010 Madagascar development team Outline 1 HPC terminology and frameworks 2 Utilizing data parallelism 3 HPC development with Madagascar

More information

How To Write A Book About The Mandelbrot Set. Claude Heiland-Allen

How To Write A Book About The Mandelbrot Set. Claude Heiland-Allen How To Write A Book About The Mandelbrot Set Claude Heiland-Allen March 13, 2014 2 Contents 1 The Exterior 7 1.1 A minimal C program.................................... 7 1.2 Building a C program.....................................

More information

Comp 11 Lectures. Mike Shah. July 12, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 12, / 33

Comp 11 Lectures. Mike Shah. July 12, Tufts University. Mike Shah (Tufts University) Comp 11 Lectures July 12, / 33 Comp 11 Lectures Mike Shah Tufts University July 12, 2017 Mike Shah (Tufts University) Comp 11 Lectures July 12, 2017 1 / 33 Please do not distribute or host these slides without prior permission. Mike

More information

The Midterm Exam. Hsuan-Tien Lin. Department of CSIE, NTU. OOP Class, April 26-27, 2010

The Midterm Exam. Hsuan-Tien Lin. Department of CSIE, NTU. OOP Class, April 26-27, 2010 The Midterm Exam Hsuan-Tien Lin Department of CSIE, NTU OOP Class, April 26-27, 2010 H.-T. Lin (NTU CSIE) The Midterm Exam OOP 04/26-27/2010 0 / 20 Java Night Countdown I 1 (2%) What is the fully-qualified

More information

Python. chrysn

Python. chrysn Python chrysn 2008-09-25 Introduction Structure, Language & Syntax Strengths & Weaknesses Introduction Structure, Language & Syntax Strengths & Weaknesses Python Python is an interpreted,

More information

Anatomy of SINGULAR talk at p. 1

Anatomy of SINGULAR talk at p. 1 Anatomy of SINGULAR talk at MaGiX@LIX 2011- p. 1 Anatomy of SINGULAR talk at MaGiX@LIX 2011 - Hans Schönemann hannes@mathematik.uni-kl.de Department of Mathematics University of Kaiserslautern Anatomy

More information

1 Return to libc exploit

1 Return to libc exploit Year and Semester: 2015 Fall Course Number: CS-336 Work Number: LA-02 Work Name: Return to libc Work Vesion: Version 01 Long Date: Friday, 02 October 2015 Author Name: Domn Werner Abstract This is LA-02

More information

Recursion. Recursion. Steven Zeil. November 25, 2013

Recursion. Recursion. Steven Zeil. November 25, 2013 Steven Zeil November 25, 2013 Outline 1 2 Example: Compressing a Picture 3 Outline I 1 2 Example: Compressing a Picture 3 A function is recursive if it calls itself or calls some other function that eventually

More information

COMS 6100 Class Notes

COMS 6100 Class Notes COMS 6100 Class Notes Daniel Solus September 20, 2016 1 General Remarks The Lecture notes submitted by the class have been very good. Integer division seemed to be a common oversight when working the Fortran

More information

Memorandum. Introduction. Design. Discussion. Conclusion

Memorandum. Introduction. Design. Discussion. Conclusion Memorandum To: Dr. Randy Hoover From: Steffen Link Date: May 1, 2017 Subject: Lab 7: Proportional Motor Control Introduction The objective of the lab was to become more familair with the rest of the core

More information

Molecular Dynamics, Stochastic simulations, and Monte Carlo

Molecular Dynamics, Stochastic simulations, and Monte Carlo UMEÅ UNIVERSITY September 11, 2018 Department of Physics Modeling and Simulation, 7.5hp Molecular Dynamics, Stochastic simulations, and Monte Carlo Peter Olsson Miscellanous comments The following instructions

More information

CS429: Computer Organization and Architecture

CS429: Computer Organization and Architecture CS429: Computer Organization and Architecture Warren Hunt, Jr. and Bill Young Department of Computer Sciences University of Texas at Austin Last updated: September 3, 2014 at 08:38 CS429 Slideset C: 1

More information

Supplementary Material

Supplementary Material Supplementary Material Contents 1 Keywords of GQL 2 2 The GQL grammar 3 3 THE GQL user guide 4 3.1 The environment........................................... 4 3.2 GQL projects.............................................

More information

Algorithms. Algorithms 2.2 MERGESORT. mergesort bottom-up mergesort sorting complexity divide-and-conquer ROBERT SEDGEWICK KEVIN WAYNE

Algorithms. Algorithms 2.2 MERGESORT. mergesort bottom-up mergesort sorting complexity divide-and-conquer ROBERT SEDGEWICK KEVIN WAYNE Algorithms ROBERT SEDGEWICK KEVIN WAYNE 2.2 MERGESORT Algorithms F O U R T H E D I T I O N mergesort bottom-up mergesort sorting complexity divide-and-conquer ROBERT SEDGEWICK KEVIN WAYNE http://algs4.cs.princeton.edu

More information

Memorandum. Introduction. Design. Discussion. Contributions. Conclusion

Memorandum. Introduction. Design. Discussion. Contributions. Conclusion Memorandum To: Dr. Randy Hoover From: Steffen Link Date: April 7, 2017 Subject: Lab 6: State Machine Stoplight Introduction The objective of the lab was to become more familair with a number of embedded

More information

Växjö University. Software Security Testing. A Flexible Architecture for Security Testing. School of Mathematics and System Engineering

Växjö University. Software Security Testing. A Flexible Architecture for Security Testing. School of Mathematics and System Engineering School of Mathematics and System Engineering Reports from MSI - Rapporter från MSI Växjö University Software Security Testing A Flexible Architecture for Security Testing Martin Andersson Aug 2008 MSI

More information

SMT BASICS WS 2017/2018 ( ) LOGIC SATISFIABILITY MODULO THEORIES. Institute for Formal Models and Verification Johannes Kepler Universität Linz

SMT BASICS WS 2017/2018 ( ) LOGIC SATISFIABILITY MODULO THEORIES. Institute for Formal Models and Verification Johannes Kepler Universität Linz LOGIC SATISFIABILITY MODULO THEORIES SMT BASICS WS 2017/2018 (342.208) Armin Biere Martina Seidl biere@jku.at martina.seidl@jku.at Institute for Formal Models and Verification Johannes Kepler Universität

More information

Numerical solution of the time-independent 1-D Schrödinger equation. Matthias E. Möbius. September 24, 2010

Numerical solution of the time-independent 1-D Schrödinger equation. Matthias E. Möbius. September 24, 2010 Numerical solution of the time-independent 1-D Schrödinger equation Matthias E. Möbius September 24, 2010 1 Aim of the computational lab Numerical solution of the one-dimensional stationary Schrödinger

More information

CS 7B - Fall Assignment 4: Exploring Wumpus (Linked Rooms). Due 12/13/18

CS 7B - Fall Assignment 4: Exploring Wumpus (Linked Rooms). Due 12/13/18 CS 7B - Fall 2018 - Assignment 4: Exploring Wumpus (Linked Rooms). Due 12/13/18 In this project we ll build, investigate and augment the the game Hunt the Wumpus, as described in exercise 12 or PPP2, Chapter

More information

Tools for Feature Extraction: Exploring essentia

Tools for Feature Extraction: Exploring essentia Tools for Feature Extraction: Exploring essentia MUS-15 Andrea Hanke July 5, 2017 Introduction In the research on Music Information Retrieval, it is attempted to automatically classify a piece of music

More information

MiniMat: Matrix Language in OCaml LLVM

MiniMat: Matrix Language in OCaml LLVM Terence Lim - tl2735@columbia.edu August 17, 2016 Contents 1 Introduction 4 1.1 Goals........................................ 4 1.1.1 Flexible matrix notation......................... 4 1.1.2 Uncluttered................................

More information

COMPUTATIONAL PHYSICS Morten Hjorth-Jensen

COMPUTATIONAL PHYSICS Morten Hjorth-Jensen COMPUTATIONAL PHYSICS Morten Hjorth-Jensen University of Oslo, Fall 2005 Preface Computer simulations are nowadays an integral part of contemporary basic and applied research in the physical sciences.

More information

GRIDLang. Move-Driven Game Programming Language Final Report. May 10, 2017

GRIDLang. Move-Driven Game Programming Language Final Report. May 10, 2017 GRIDLang Move-Driven Game Programming Language Final Report Akshay Nagpal (an2756) Parth Panchmatia (psp2137) Dhruv Shekhawat (ds3512) Sagar Damani (ssd2144) May 10, 2017 1 Contents 1 Introduction 4 2

More information

ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University

ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University ECEN 449: Microprocessor System Design Department of Electrical and Computer Engineering Texas A&M University Prof. Sunil P Khatri (Lab exercise created and tested by Ramu Endluri, He Zhou and Sunil P

More information

Cantera / Stancan Primer

Cantera / Stancan Primer Cantera / Stancan Primer Matthew Campbell; A.J. Simon; Chris Edwards Introduction to Cantera and Stancan Cantera is an open-source, object-oriented software package which performs chemical and thermodynamic

More information

Elementary Sorts 1 / 18

Elementary Sorts 1 / 18 Elementary Sorts 1 / 18 Outline 1 Rules of the Game 2 Selection Sort 3 Insertion Sort 4 Shell Sort 5 Visualizing Sorting Algorithms 6 Comparing Sorting Algorithms 2 / 18 Rules of the Game Sorting is the

More information

Verified Characteristic Formulae for CakeML. Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 18, 2017

Verified Characteristic Formulae for CakeML. Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 18, 2017 Verified Characteristic Formulae for CakeML Armaël Guéneau, Magnus O. Myreen, Ramana Kumar, Michael Norrish April 18, 2017 CakeML Has: references, modules, datatypes, exceptions, a FFI,... Doesn t have:

More information

C++ For Science and Engineering Lecture 13

C++ For Science and Engineering Lecture 13 C++ For Science and Engineering Lecture 13 John Chrispell Tulane University Wednesday September 22, 2010 Logical Expressions: Sometimes you want to use logical and and logical or (even logical not) in

More information

Instance Methods and Inheritance (1/2)

Instance Methods and Inheritance (1/2) Instance Methods and Inheritance (1/2) 1 class Professor { 2 p u b l i c void say_hello ( ) { 3 System. out. p r i n t l n ( " Hello! " ) ; 4 } 5 } 6 class CSIEProfessor extends Professor { 7 p u b l i

More information

Python. Tutorial. Jan Pöschko. March 22, Graz University of Technology

Python. Tutorial. Jan Pöschko. March 22, Graz University of Technology Tutorial Graz University of Technology March 22, 2010 Why? is: very readable easy to learn interpreted & interactive like a UNIX shell, only better object-oriented but not religious about it slower than

More information

Congratulations you're done with CS103 problem sets! Please evaluate this course on Axess!

Congratulations you're done with CS103 problem sets! Please evaluate this course on Axess! The Big Picture Announcements Problem Set 9 due right now. We'll release solutions right after lecture. Congratulations you're done with CS103 problem sets! Practice final exam is Monday, December 8 from

More information

DARN: A Matrix Manipulation Language

DARN: A Matrix Manipulation Language DARN: A Matrix Manipulation Language Daisy Chaussee (dac2183) Anthony Kim (ak3703) Rafael Takasu (rgt2108) Ignacio (Nacho) Torras (it2216) December 20, 2016 1 Contents 1 Introduction to the Language 4

More information

CS-140 Fall 2018 Test 2 Version Practice Nov. 12, Name:

CS-140 Fall 2018 Test 2 Version Practice Nov. 12, Name: CS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018 Name: 1. (10 points) For the following, Check T if the statement is true, or F if the statement is false. (a) T F : If a child overrides its parent

More information

B-Spline Interpolation on Lattices

B-Spline Interpolation on Lattices B-Spline Interpolation on Lattices David Eberly, Geometric Tools, Redmond WA 98052 https://www.geometrictools.com/ This work is licensed under the Creative Commons Attribution 4.0 International License.

More information

Example problem: Adaptive solution of the 2D advection diffusion equation

Example problem: Adaptive solution of the 2D advection diffusion equation Chapter 1 Example problem: Adaptive solution of the 2D advection diffusion equation In this example we discuss the adaptive solution of the 2D advection-diffusion problem Solve Two-dimensional advection-diffusion

More information

Lecture 14: Nov. 11 & 13

Lecture 14: Nov. 11 & 13 CIS 2168 Data Structures Fall 2014 Lecturer: Anwar Mamat Lecture 14: Nov. 11 & 13 Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 14.1 Sorting

More information

A call-by-name lambda-calculus machine

A call-by-name lambda-calculus machine A call-by-name lambda-calculus machine Jean-Louis Krivine University Paris VII, C.N.R.S. 2 place Jussieu 75251 Paris cedex 05 (krivine@pps.jussieu.fr) Introduction We present, in this paper, a particularly

More information

Stepwise Refinement. Stepwise Refinement. Steven Zeil. September 29, 2013

Stepwise Refinement. Stepwise Refinement. Steven Zeil. September 29, 2013 Steven Zeil September 29, 2013 Outline 1 Pseudo-Code 2 Top-Down Design Example: Top-Down Auction Outline I 1 Pseudo-Code 2 Top-Down Design Example: Top-Down Auction Stepwise refinement is a basic technique

More information

Insertion Sort. We take the first element: 34 is sorted

Insertion Sort. We take the first element: 34 is sorted Insertion Sort Idea: by Ex Given the following sequence to be sorted 34 8 64 51 32 21 When the elements 1, p are sorted, then the next element, p+1 is inserted within these to the right place after some

More information

Porting RSL to C++ Ryusuke Villemin, Christophe Hery. Pixar Technical Memo 12-08

Porting RSL to C++ Ryusuke Villemin, Christophe Hery. Pixar Technical Memo 12-08 Porting RSL to C++ Ryusuke Villemin, Christophe Hery Pixar Technical Memo 12-08 1 Introduction In a modern renderer, relying on recursive ray-tracing, the number of shader calls increases by one or two

More information

ROSE Tutorial: A Tool for Building Source-to-Source Translators Draft Tutorial (version )

ROSE Tutorial: A Tool for Building Source-to-Source Translators Draft Tutorial (version ) ROSE Tutorial: A Tool for Building Source-to-Source Translators Draft Tutorial (version 0.9.9.139) Daniel Quinlan, Markus Schordan, Richard Vuduc, Qing Yi Thomas Panas, Chunhua Liao, and Jeremiah J. Willcock

More information

The Pip Project. PLT (W4115) Fall Frank Wallingford

The Pip Project. PLT (W4115) Fall Frank Wallingford The Pip Project PLT (W4115) Fall 2008 Frank Wallingford (frw2106@columbia.edu) Contents 1 Introduction 4 2 Original Proposal 5 2.1 Introduction....................................................... 5

More information

Robust Programs with Filtered Iterators

Robust Programs with Filtered Iterators Robust Programs with Filtered Iterators Jiasi Shen, Martin Rinard MIT EECS & CSAIL 1 Standard Scenario Input file Program Output 2 Structured Input Units Input Input unit Input unit Input unit unit Program

More information

Test Automation. Foundations and Applications of Model-based Testing

Test Automation. Foundations and Applications of Model-based Testing Test Automation Foundations and Applications of Model-based Testing Lecture Notes Jan Peleska and Wen-ling Huang {jp,huang}@cs.uni-bremen.de Issue 3.2 2017-04-26 Note. These lecture notes are still under

More information

CS Exam 1 Study Guide and Practice Exam

CS Exam 1 Study Guide and Practice Exam CS 150 - Exam 1 Study Guide and Practice Exam September 11, 2017 Summary 1 Disclaimer 2 Variables 2.1 Primitive Types.............................................. 2.2 Suggestions, Warnings, and Resources.................................

More information

Scientific Programming in C XIII. Shell programming

Scientific Programming in C XIII. Shell programming Scientific Programming in C XIII. Shell programming Susi Lehtola 11 December 2012 Introduction Often in scientific computing one needs to do simple tasks related to renaming of files file conversions unit

More information

(Mathematical Operations with Arrays) Applied Linear Algebra in Geoscience Using MATLAB

(Mathematical Operations with Arrays) Applied Linear Algebra in Geoscience Using MATLAB Applied Linear Algebra in Geoscience Using MATLAB (Mathematical Operations with Arrays) Contents Getting Started Matrices Creating Arrays Linear equations Mathematical Operations with Arrays Using Script

More information

2 Getting Started with Numerical Computations in Python

2 Getting Started with Numerical Computations in Python 1 Documentation and Resources * Download: o Requirements: Python, IPython, Numpy, Scipy, Matplotlib o Windows: google "windows download (Python,IPython,Numpy,Scipy,Matplotlib" o Debian based: sudo apt-get

More information

Answers for Homework #6 for CST P

Answers for Homework #6 for CST P Answers for Homework #6 for CST 407 02P Assigned 5/10/07, Due 5/17/07 Constructing Evans root locus diagrams in Scilab Root Locus It is easy to construct a root locus of a transfer function in Scilab.

More information

Introduction to Programming (Java) 3/12

Introduction to Programming (Java) 3/12 Introduction to Programming (Java) 3/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c 2006 2008 Michal Krátký Introduction

More information

Write a simple 1D DFT code in Python

Write a simple 1D DFT code in Python Write a simple 1D DFT code in Python Ask Hjorth Larsen, asklarsen@gmail.com Keenan Lyon, lyon.keenan@gmail.com September 15, 2018 Overview Our goal is to write our own KohnSham (KS) density functional

More information

COMP 204. Object Oriented Programming (OOP) Mathieu Blanchette

COMP 204. Object Oriented Programming (OOP) Mathieu Blanchette COMP 204 Object Oriented Programming (OOP) Mathieu Blanchette 1 / 14 Object-Oriented Programming OOP is a way to write and structure programs to make them easier to design, understand, debug, and maintain.

More information

Speculative Parallelism in Cilk++

Speculative Parallelism in Cilk++ Speculative Parallelism in Cilk++ Ruben Perez & Gregory Malecha MIT May 11, 2010 Ruben Perez & Gregory Malecha (MIT) Speculative Parallelism in Cilk++ May 11, 2010 1 / 33 Parallelizing Embarrassingly Parallel

More information

Lab 2: Static Response, Cantilevered Beam

Lab 2: Static Response, Cantilevered Beam Contents 1 Lab 2: Static Response, Cantilevered Beam 3 1.1 Objectives.......................................... 3 1.2 Scalars, Vectors and Matrices (Allen Downey)...................... 3 1.2.1 Attribution.....................................

More information

Constructors - Cont. must be distinguished by the number or type of their arguments.

Constructors - Cont. must be distinguished by the number or type of their arguments. Constructors - Cont. 1 Constructors can be overloaded! must be distinguished by the number or type of their arguments. 2 When no constructor is defined, there is a default constructor with no arguments.

More information

Concurrent HTTP Proxy Server. CS425 - Computer Networks Vaibhav Nagar(14785)

Concurrent HTTP Proxy Server. CS425 - Computer Networks Vaibhav Nagar(14785) Concurrent HTTP Proxy Server CS425 - Computer Networks Vaibhav Nagar(14785) Email: vaibhavn@iitk.ac.in August 31, 2016 Elementary features of Proxy Server Proxy server supports the GET method to serve

More information

CS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018

CS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018 CS-140 Fall 2018 Test 2 Version Practice Nov. 12, 2018 Name: 1. (10 points) For the following, Check T if the statement is true, or F if the statement is false. (a) T X F : If a child overrides its parent

More information

Computational Physics (6810): Session 9

Computational Physics (6810): Session 9 Computational Physics (6810): Session 9 Dick Furnstahl Nuclear Theory Group OSU Physics Department March 3, 2014 Session 8 Stuff Session 9 Overview Session 8 Stuff Damped, driven harmonic oscillator ẍ

More information

Generics. Hsuan-Tien Lin. OOP Class, May 23, Department of CSIE, NTU. H.-T. Lin (NTU CSIE) Generics OOP 05/23/ / 16

Generics. Hsuan-Tien Lin. OOP Class, May 23, Department of CSIE, NTU. H.-T. Lin (NTU CSIE) Generics OOP 05/23/ / 16 Generics Hsuan-Tien Lin Department of CSIE, NTU OOP Class, May 23, 2013 H.-T. Lin (NTU CSIE) Generics OOP 05/23/2013 0 / 16 How can we write a class for an Integer set of arbitrary size? H.-T. Lin (NTU

More information

DMDW: A set of tools to calculate Debye-Waller factors and other related quantities using dynamical matrices.

DMDW: A set of tools to calculate Debye-Waller factors and other related quantities using dynamical matrices. DMDW: A set of tools to calculate Debye-Waller factors and other related quantities using dynamical matrices. DMDW is a set of tools developed to calculate Debye-Waller (DW) factors and other related quantities

More information

CS 7B - Spring Assignment: Adapting the calculator for bitwise expressions. due 2/21/18

CS 7B - Spring Assignment: Adapting the calculator for bitwise expressions. due 2/21/18 CS 7B - Spring 2018 - Assignment: Adapting the calculator for bitwise expressions. due 2/21/18 Background Theory A bitwise number is a number in base 2. In base 2, place values are either a 1 or 0, depending

More information

Oversubscribing inotify on Embedded Platforms

Oversubscribing inotify on Embedded Platforms Oversubscribing inotify on Embedded Platforms By Donald Percivalle (CPE) and Scott Vanderlind (CSC) Senior Project California Polytechnic State University San Luis Obispo Dr. Zachary Peterson June 11,

More information

Antonio Falabella. 3 rd nternational Summer School on INtelligent Signal Processing for FrontIEr Research and Industry, September 2015, Hamburg

Antonio Falabella. 3 rd nternational Summer School on INtelligent Signal Processing for FrontIEr Research and Industry, September 2015, Hamburg INFN - CNAF (Bologna) 3 rd nternational Summer School on INtelligent Signal Processing for FrontIEr Research and Industry, 14-25 September 2015, Hamburg 1 / 44 Overview 1 2 3 4 5 2 / 44 to Computing The

More information

An Introduction to Z3

An Introduction to Z3 An Introduction to Z3 Huixing Fang National Trusted Embedded Software Engineering Technology Research Center April 12, 2017 Outline 1 SMT 2 Z3 Huixing Fang (ECNU) An Introduction to Z3 April 12, 2017 2

More information

Software Analysis AdaCore

Software Analysis AdaCore Software Analysis Tools @ AdaCore Yannick Moy LSL Seminar, CEA-LIST December 8 th, 2009 Outline Ada & AdaCore Dynamic Analysis Tools @ AdaCore Static Analysis Tools @ AdaCore Project Hi-Lite 1 / 46 Outline

More information

import java. u t i l. ;... Scanner sc = new Scanner ( System. in ) ;

import java. u t i l. ;... Scanner sc = new Scanner ( System. in ) ; CPSC 490 Input Input will always arrive on stdin. You may assume input is well-formed with respect to the problem specification; inappropriate input (e.g. text where a number was specified, number out

More information

Lecture 3: Finite Automata

Lecture 3: Finite Automata Administrivia Lecture 3: Finite Automata Everyone should now be registered electronically using the link on our webpage. If you haven t, do so today! I d like to have teams formed by next Monday at the

More information

Computational Physics Lectures: Variational Monte Carlo methods

Computational Physics Lectures: Variational Monte Carlo methods Computational Physics Lectures: Variational Monte Carlo methods Morten Hjorth-Jensen 1,2 Department of Physics, University of Oslo 1 Department of Physics and Astronomy and National Superconducting Cyclotron

More information

CS 3411 Systems Programming

CS 3411 Systems Programming CS 3411 Systems Programming Department of Computer Science Michigan Technological University Unix Processes Today s Topics Unix Processes Creating New Processes Unix Processes Process is the image of a

More information

Lecture II: Background

Lecture II: Background Lecture II: The Background EPFL & CERN London, 13.05.2014 Homogeneous cosmology treated by the module background.c. So this lecture will refer mainly to the content of input/background.h, source/background.c,

More information

Functional Programming with F# Overview and Basic Concepts

Functional Programming with F# Overview and Basic Concepts Functional Programming with F# Overview and Basic Concepts Radu Nicolescu Department of Computer Science University of Auckland 27 Sep 2017 1 / 52 1 Background 2 Overview 3 Type System and Type Inference

More information