Procedures (College Board AP® Computer Science Principles): Flashcards

1/23

0Still learning

Know0

Cards in this collection (23)

  • Define procedure.

    A procedure is a named group of instructions that performs a specific task.

  • Name two benefits of using procedures.

    Procedures avoid rewriting the same code multiple times and make programs easier to read and maintain.

  • Define procedure call.

    A procedure call executes the instructions inside the procedure.

  • Define parameter.

    A parameter is a variable in the procedure definition that receives a value when the procedure is called.

  • Define argument.

    An argument is the actual value passed into the procedure during the call.

  • In this code segment, which are the parameters and which are the arguments?

    PROCEDURE showTotal(a, b)
    
    {
    
       DISPLAY(a + b)
    
    }
    
    
    
    showTotal(4, 9)

    a and b are the parameters; 4 and 9 are the arguments.

  • Apart from parameters, how else can a procedure collect input?

    A procedure can collect input by calling INPUT() inside its body.

  • Define return value.

    A return value is a value that a procedure sends back to the part of the program that called it.

  • True or False?

    Every procedure returns a value.

    False.

    Not all procedures return a value; some only perform an action, such as displaying output.

  • When RETURN is reached, the procedure _____ executing immediately and no further statements in it run.

    When RETURN is reached, the procedure stops executing immediately and no further statements in it run.

  • What happens to the sequential flow of a program when a procedure is called?

    Sequential flow is temporarily interrupted: the program jumps to the procedure body, executes it, then resumes at the point of the call.

  • What value is displayed when this code segment runs?

    PROCEDURE triple(n)
    
    {
    
       RETURN(n * 3)
    
    }
    
    
    
    x ← triple(2)
    
    y ← triple(x + 1)
    
    DISPLAY(y)

    The code segment displays 21: triple(2) returns 6, so x is 6, then triple(7) returns 21.

  • What is displayed when this code segment runs?

    PROCEDURE check(n)
    
    {
    
       IF(n > 10)
    
       {
    
          RETURN("big")
    
       }
    
       RETURN("small")
    
    }
    
    
    
    DISPLAY(check(15))

    The code segment displays big, because 15 > 10, and the first RETURN ends the procedure before the second one is reached.

  • Define procedural abstraction.

    Procedural abstraction is the practice of defining a named process that hides its implementation details from the rest of the program.

  • How does procedural abstraction help when designing a program?

    A program can be subdivided into smaller modular sub-problems, each handled by a separate procedure.

  • What should each procedure in a modular program be responsible for?

    Each procedure should perform one specific task, making the program easier to design, test, and understand.

  • Name three benefits of procedural abstraction.

    The benefits are shared feature extraction, parameter generalization, and improved readability.

  • Define shared feature extraction.

    Shared feature extraction is moving code that appears in multiple places into a procedure that is called wherever it is needed.

  • Define parameter generalization.

    Parameter generalization is using parameters so a procedure can be reused with different inputs, rather than writing separate code for each case.

  • How do procedure names improve the readability of a program?

    Procedure names describe what the code does, making the program easier to follow at a glance.

  • Internal change _________ means that updating a procedure's logic only needs to happen in one place, however many times it is called.

    Internal change isolation means that updating a procedure's logic only needs to happen in one place, however many times it is called.

  • True or False?

    A procedure can only be tested once the whole program is complete.

    False.

    Each procedure can be tested and debugged independently from the rest of the program.

  • What does the calling code need to know about a procedure?

    The calling code only needs to know the procedure's name, what inputs it takes, and what it returns, not how it works internally.

Sign up to unlock flashcards

or