functions and more. homework 1 due september 11 @ 11:59pm return a string count characters in a...

11
Functions and More

Upload: jared-lynch

Post on 30-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Functions and More. Homework 1 Due September 11 @ 11:59pm return a string count characters in a string call functions in a function

Functions and More

Page 2: Functions and More. Homework 1 Due September 11 @ 11:59pm return a string count characters in a string call functions in a function

Homework 1

• Due September 11 @ 11:59pm

• return a string• count characters in a string• call functions in a function

Page 3: Functions and More. Homework 1 Due September 11 @ 11:59pm return a string count characters in a string call functions in a function

git

• Version control• Might cover this in more detail later in the

semester• For now– git clone

https://[email protected]/hartloff/cse250-fall2015.git

• If SSH keys are needed (timberlake)– upload private key– git clone [email protected]:hartloff/cse250-

fall2015.git

Page 4: Functions and More. Homework 1 Due September 11 @ 11:59pm return a string count characters in a string call functions in a function

clone alternative

• Download files from the BitBucket web interface– Might get you through this course– Not ideal

• If you want to write software, you will need to learn version control at some point

Page 5: Functions and More. Homework 1 Due September 11 @ 11:59pm return a string count characters in a string call functions in a function

ftp (file transfer protocol)

• To move files across machines• If you want to develop locally– Use this to move your files to timberlake– submit_cse250 hw1.cpp

• Need ftp software– FileZilla– sftp://timberlake.cse.buffalo.edu– Port 22

Page 6: Functions and More. Homework 1 Due September 11 @ 11:59pm return a string count characters in a string call functions in a function

On to C++

Page 7: Functions and More. Homework 1 Due September 11 @ 11:59pm return a string count characters in a string call functions in a function

Functions in C++

• Function declaration– float foo(int);– C++ functions must be declared before they are called

• Function definition– float foo(int i){return i*1.5;}– can be defined later

• Put all declarations at the beginning of your file• Header file– Go one step further and put declarations in a separate

file– #include “stringFunctions.h”

Page 8: Functions and More. Homework 1 Due September 11 @ 11:59pm return a string count characters in a string call functions in a function

Makefile

• Useful when a project contains multiple files• A way to compile all necessary files with one

command– make

• Blank space matters in Makefiles• All Makefiles will be provided for you in this

class

Page 9: Functions and More. Homework 1 Due September 11 @ 11:59pm return a string count characters in a string call functions in a function

References &

• An alias (nickname) to a variable– int k = 3;– int& p = k;– p = 6;

• After executing these 3 lines– k == 6– Both k and p refer to the same location in memory

• Why not assign 6 to k directly?– When you have access to p, but not k

Page 10: Functions and More. Homework 1 Due September 11 @ 11:59pm return a string count characters in a string call functions in a function

back to functions

• void square(int i){i = i*i;}• int r = 5;• square(r);• r == 5• When square is called• int i = r;• i = i*i;

Page 11: Functions and More. Homework 1 Due September 11 @ 11:59pm return a string count characters in a string call functions in a function

back to functions &

• void square(int& i){i = i*i;}• int r = 5;• square(r);• r == 25• When square is called• int& i = r;• i = i*i;

• Use references when a function should alter a parameter• Caution: Be aware if a function takes a reference or not