CS161_Topic#10

CS161_Topic#10 - CS161 CS161 Introduction to Computer...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CS161 CS161 Introduction to Introduction to Computer Science Computer Science Topic #10
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS161 Topic #10 2 Today in CS161 Functions with Arguments What are arguments? How do we define a function with args? Actual arguments versus Formal arguments Functions with Arguments Call by value versus Call by reference Questions? Programming assignment #4
Background image of page 2
CS161 Topic #10 3 Functions: What are arguments? If we want to send information to a function when we call it, we can use arguments For example, when we supplied two items within the parentheses for the pow function -- these were arguments that were being passed to the function pow! We can define functions with no arguments, or with many arguments
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS161 Topic #10 4 Functions: What are arguments? If we go back to our example of converting inches to millimeters. .. if we write a function to perform the calculations, we would need to somehow send to the function the number of inches to convert this can be done by passing in the number of inches as an argument and receiving the number of millimeters back as the returned value
Background image of page 4
CS161 Topic #10 5 Functions: What are arguments? For example, from our main program we could say: float convert (float inches); //prototype int main() { float in; //local variable to hold # inches float mm; //local variable for the result cout << “Enter the number of inches: “; cin >> in; mm = convert (in); //function call cout << in << “ inches converts to “ << mm << “mm”; return 0; }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS161 Topic #10 6 Functions: What are arguments? Then, to implement the function we might say:
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 20

CS161_Topic#10 - CS161 CS161 Introduction to Computer...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online