Welcome to Lesson 16!


Learning Objectives
By the end of today's class, you should know...

Announcements

  • Midterm 2 after a short review lesson and the break
  • Don't forget Assignment 15 due Monday
    • Get started early! It is a very long assignment with a lot of practice on functions!
  • Don't forget Lab 8 due Friday
  • Next quiz one week from today
    • Functions!
  • Typo in answer key question 5
    • Update statement should have been in body of while loop


Review Activity

With a partner, answer the following questions:


  • Label the components of the following function:

double calc_area_circle(int radius) {

    double area = 3.14 * radius * radius;

    return area;

}

Function Name:

Return type:

Parameter(s):


  • Write a correct function call for the above function, passing it the value of 9, and storing the result in the cArea variable:

         double cArea = ???????????????????;

    cout << "The area of the circle with radius 9 is: " << cArea << endl;


  • What is output by the following program? (Do not run the code -- work it out by hand)

#include <iostream>
using namespace std;

int mystery(int param) {
    cout << "param=" << param << endl;
    param = param * 2;
    return param;
}

int main() {
    int num = 2;

    cout << "At first, num=" << num << endl;
    int result = mystery(num);
    cout << "After calling, num=" << num << endl;
    cout << "And result=" << result << endl;

    return 0;
}
  1. At first, num=2
    param=2
    After calling, num=4
    And result=4
    
  2. At first, num=2
    param=4
    After calling, num=4
    And result=4
    
  3. At first, num=2
    param=2
    After calling, num=2
    And result=4
    
  4. None of these


  • Write the following functions:
  • areaRectangle
    • Takes in a double for the length and width
    • returns the area of the rectangle as a double
  • areaTriangle
    • Takes in a double for the base and height
    • returns the area of the triangle as a double
  • mpg
    • takes in an integer for the miles and the gallons
    • returns the miles per gallon as a double







Upcoming Assignments