Physics 2660: Fundamentals of Scientific Computing. Lecture 7 Instructor: Prof. Chris Neu

Similar documents
Physics 2660: Fundamentals of Scientific Computing. Lecture 5 Instructor: Prof. Chris Neu

Physics 2660: Fundamentals of Scientific Computing. Lecture 3 Instructor: Prof. Chris Neu

CS 241 Data Organization. August 21, 2018

EECE.2160: ECE Application Programming Spring 2017

CSCI 136 Data Structures & Advanced Programming. Fall 2018 Instructors Bill Lenhart & Bill Jannen

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

CIS*1500 Introduction to Programming

Using the MIPS Calling Convention. Recursive Functions in Assembly. CS 64: Computer Organization and Design Logic Lecture #10 Fall 2018

Announcements. 1. Forms to return today after class:

At the end of this module, the student should be able to:

Functions in C. Lecture Topics. Lecture materials. Homework. Machine problem. Announcements. ECE 190 Lecture 16 March 9, 2011

Linked Lists CS 16: Solving Problems with Computers I Lecture #16

CIS 110: Introduction to Computer Programming. Lecture 2 Decomposition and Static Methods ( 1.4)

Physics 2660: Fundamentals of Scientific Computing. Lecture 14 Instructor: Prof. Chris Neu

Call-by-Type Functions in C++ Command-Line Arguments in C++ CS 16: Solving Problems with Computers I Lecture #5

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6

Class 9 Saturday, Feb 14

CPSC 121: Models of Computation

Programming with Arrays Intro to Pointers CS 16: Solving Problems with Computers I Lecture #11

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 12, FALL 2012

Course Information and Introduction

BLM2031 Structured Programming. Zeyneb KURT

Introduction to Computer Systems

Central Washington University Department of Computer Science Course Syllabus

Programming Assignment #4 Arrays and Pointers

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

Floating-point lab deadline moved until Wednesday Today: characters, strings, scanf Characters, strings, scanf questions clicker questions

Final Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Announcements. Course syllabus Tutorial/lab signup form (due 4pm today) Lecture 1 notes Homework 1 Initial assessment

Index. Course Outline. Grading Policy. Lab Time Distribution. Important Instructions

Tutorials. Tutorial every Friday at 11:30 AM in Toldo 204 * discuss the next lab assignment

CoSci 440 SYLLABUS Programming in C++ INSTRUCTOR Mari Rettke cell SECTION : and 13345

Functions and the MIPS Calling Convention 2 CS 64: Computer Organization and Design Logic Lecture #11

Introduction to Computer Systems

CprE 281: Digital Logic

CS Introduction to Programming Fall 2016

Function Calling Conventions 2 CS 64: Computer Organization and Design Logic Lecture #10

CS 61C: Great Ideas in Computer Architecture C Pointers. Instructors: Vladimir Stojanovic & Nicholas Weaver

Introduction to Information Technology ITP 101x (4 Units)

CS 106B, Lecture 1 Introduction to C++

General course information

Unit 10: Data Structures CS 101, Fall 2018

CS 241 Data Organization using C

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Administrivia. Administrivia. Faloutsos/Pavlo CMU /615

More Flow Control Functions in C++ CS 16: Solving Problems with Computers I Lecture #4

Course: Honors AP Computer Science Instructor: Mr. Jason A. Townsend

EL2310 Scientific Programming

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

Lecture 6. COMP1006/1406 (the OOP course) Summer M. Jason Hinek Carleton University

BSM540 Basics of C Language

378: Machine Organization and Assembly Language

CSE 114, Computer Science 1 Course Information. Spring 2017 Stony Brook University Instructor: Dr. Paul Fodor

Computer Science Technology Department

CS 107 Lecture 0: Welcome

Claims Management - Delay analysis Online Workshop. Week No. 1: concept of claims

Computer Programming Lecture 12 Pointers

Memory, Data, & Addressing II

CS261: HOMEWORK 2 Due 04/13/2012, at 2pm

Dynamic Arrays Makefiles and Mul3ple File Compiles

CMSC433 - Programming Language Technologies and Paradigms. Introduction

EECE.2160: ECE Application Programming Spring 2019

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

CS 240 Fall 2015 Section 004. Alvin Chao, Professor

Searching for Information. A Simple Method for Searching. Simple Searching. Class #21: Searching/Sorting I

TEACHING & ASSESSMENT PLAN

CSCI 4250/6250 Fall 2013 Computer and Network Security. Instructor: Prof. Roberto Perdisci

Course and Unix Intro

Notes slides from before lecture. CSE 21, Winter 2017, Section A00. Lecture 9 Notes. Class URL:

Overview of the Class

AE Computer Programming for Aerospace Engineers

Welcome to! 4DN4! Advanced Internet Communications"

Arrays 2 CS 16: Solving Problems with Computers I Lecture #12

Accounting & MIS 3610

Final Exam. Programming Assignment 3. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

CSC 111 Introduction to Computer Science (Section C)

6.S096 Lecture 1 Introduction to C

Programming in C. main. Level 2. Level 2 Level 2. Level 3 Level 3

Slide Set 1. for ENCM 339 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary

CISC 3130 Data Structures Spring 2018

CS 222: Pointers and Manual Memory Management

Outline. Computer Memory Structure Addressing Concept Introduction to Pointer Pointer Manipulation Summary

Welcome to CSL 201 Data Structures

ESC101N: Fundamentals of Computing End-sem st semester

COMP26120: Pointers in C (2018/19) Lucas Cordeiro

CS349/SE382 A1 C Programming Tutorial

Variables and Operators 2/20/01 Lecture #

Lab 3. Pointers Programming Lab (Using C) XU Silei

What is Graphic Design?

Biochemistry I: Biomolecules and an Introduction to Metabolic Energy MBIO2360/CHEM2360: A01 Summer 2015: 3 credit hours

CSE 544 Principles of Database Management Systems

ESc101 : Fundamental of Computing

LIS 2680: Database Design and Applications

Graphical Presentation of Data

CMPE 150/L : Introduction to Computer Networks

ECE Object-Oriented Programming using C++ and Java

Admin. ! Assignment 3. ! due Monday at 11:59pm! one small error in 5b (fast division) that s been fixed. ! Midterm next Thursday in-class (10/1)

CSc 2310 Principles of Programming (Java) Jyoti Islam

CS120 Computer Science I. Instructor: Jia Song

Fundamentals of Digital System Design ECE 3700, CPSC 3700

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

Transcription:

Physics 2660: Fundamentals of Scientific Computing Lecture 7 Instructor: Prof. Chris Neu (chris.neu@virginia.edu)

Reminder HW06 due Thursday 15 March electronically by noon HW grades are starting to appear! Exam next week! More on this later... Join Piazza! Office hours: all held in our computer lab, room 022-C of this bldg Me: After lecture 3:30-4:30 every Tuesday TAs: Mondays: 3-5pm and 6-8pm Wednesdays: 5-9pm 2

Last time: Followup on conditionals Followup on loops Scope Static vars Pointers experience in lab Recursion experience in lab Review and Outline Today: Review of pointers Pointers to functions Arrays Passing arguments to main(..) Making code reusable Review for exam Random numbers 3

Pointers 4

Memory Addresses: Storage in Functions 5

Pointers 6

Storing Pointers in Memory 7

Pointers: The Indirection Operator * 8

Pointers: Changing Data in a Memory Location 9

An Example: scanf 10

Passing Pointers As an Argument To A Function 11

Advantages: Passing Pointers As Args To Functions Through the use of pointers passed to functions, we can manipulate an arbitrary number of variables, rather than just return one result 12

Pointers: Be Careful! 13

Pointers: Be Careful! 14

Pointers to Functions and Trapezoidal Rule for Integration 15

Pointers to Variables: A Review Pointers allow direct access to memory locations where variables are stored in 1 s and 0 s address via & content via * Passing pointers into functions: In function prototype use pointer-to-values as argument(s) In call to function call with pointer-to-address as argument(s) In function definition, use pointer-to-values as argument(s) as done in prototype use pointer-to-values in body of function #include <stdio.h> void circle_stuff(double radius, double *a_ptr, double *c_ptr); void main(){ double radius = 3.0; double area = 0.0; } double circumference = 0.0; circle_stuff(radius, &area, &circumference); printf( area=%8.3f circumference= %8.3f\n, area, circumference); void circle_stuff(double radius, double *a_ptr, double *c_ptr){ *a_ptr = 3.1416*radius*radius; *c_ptr = 2.0*3.1416*circumference; } 16

How are Functions Stored in Memory? 17

Pointers to Functions: Example 18

Pointers to Functions: Pieces 19

Pointers to Functions: Example Numerical Integration Monte Carlo integration is one method one can use to integrate some complicated function, especially useful in multiplie dimensions. 20

Pointers to Functions: Example Numerical Integration 21

Pointers to Functions: Example Numerical Integration 22

Pointers to Functions: Example Numerical Integration 23

Arrays in C 24

What is an Array? Very often we need to store and access many instances or sets of related data Example: coordinates in 3-space: x=5, y=23, z=1 Can be represented by a vector: (5,23,1) The points in space are of the same type would like a container that holds them in a convenient format Arrays do this for us! Not just god for vectors in 3-space Good for matrices Good for collections of related items Good generally for similar pieces of data 25

An example: A vector in 3-space * 26

An example: A vector in 3-space using an array * 27

Defining Arrays 28

Using Arrays 29

Storage of Arrays in Memory 30

Storage of Arrays in Memory: Danger 31

Using Arrays: Danger 32

Passing Arrays to Functions * 33

Mid-term Exam 34

Information on Mid Term Exam Your mid-term is coming! Tuesday 20 March in this room at 7pm You will have 60 min to finish Bring a number 2 pencil Regular lecture and labs will of course meet that week Format: multiple choice matching short answer All material in readings, lectures, labs, HWs is fair game That being said I would not expect an emphasis in the exam on things that I did not emphasize in lecture, labs, HW Let s review some of the things we have learned so far Some examples follow 35

Review of C: What We Have Learned So Far 36

Variables Variables 37

Input and Output 38

Files 39

Loops 40

Conditionals 41

Functions 42

Pointers Pointers allow direct access to memory locations where variables are stored in 1 s and 0 s address via & content via * Passing pointers to functions: In function prototype use pointer-to-values as argument(s) In call to function call with pointer-to-address as argument(s) In function definition, use pointer-to-values as argument(s) as done in prototype use pointer-to-values in body of function #include <stdio.h> void circle_stuff(double radius, double *a_ptr, double *c_ptr); void main(){ double radius = 3.0; double area = 0.0; } double circumference = 0.0; circle_stuff(radius, &area, &circumference); printf( area=%8.3f circumference= %8.3f\n, area, circumference); void circle_stuff(double radius, double *a_ptr, double *c_ptr){ *a_ptr = 3.1416*radius*radius; *c_ptr = 2.0*3.1416*circumference; } 43

Questions About the Basics What is an operating system? What are the main hardware parts of a computer? What is a compiler? Etc. 44

Questions About the Linux Shell 45

Questions About the C Language 46

Questions About the C Language 47

Questions About the C Language 48

Questions About the C Language 49

We ll pick up from here next time. See you then. 50