110 likes | 119 Views
This assignment focuses on functions in C++, including function declaration, definition, and using references as parameters. It also covers version control, such as using Git and FTP for file transfer. A Makefile is provided for compiling multiple files.
E N D
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://hartloff@bitbucket.org/hartloff/cse250-fall2015.git • If SSH keys are needed (timberlake) • upload private key • git clone git@bitbucket.org:hartloff/cse250-fall2015.git
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
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
Functions in C++ • Function declaration • float foo(int); • C++ functions must be declared before they are called • Function definition • float foo(inti){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”
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
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
back to functions • void square(inti){i = i*i;} • int r = 5; • square(r); • r == 5 • When square is called • inti = r; • i = i*i;
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