1 / 11

C++ Functions & More Homework 1

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.

cwarkentin
Télécharger la présentation

C++ Functions & More Homework 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Functions and More

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

  3. 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

  4. 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

  5. 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

  6. On to C++

  7. 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”

  8. 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

  9. 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

  10. 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;

  11. 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

More Related