Module 3 Guided Notes_Using Abstractions
Module 3 Guided Notes_Using Abstractions
Using Abstraction
Guided Notes
Mathematical Expressions
Vocabulary Term Definition
Element A smaller component in a larger system
Constructs The basic building blocks of a program
Sequence The order in which programming statements are executed.
Selection The path a program takes given a choice
Iteration The repeated execution of a section of code
Code Statement A single line of code that performs a specific task
Natural language uses the Flow charts are a more Pseudocode is a programming-like
language you speak to formal and visual way to way of presenting algorithms that
communicate the steps of an express algorithms. Each uses some of the structure of a
algorithm and is a good choice flow chart element has a programming language but is
for programmers working on standard meaning. intended for people to read and
teams where some people may be understand. The AP™ Exam uses
unfamiliar with coding. pseudocode for some
However, natural language can programming questions.
sometimes be too vague or have
alternative meanings that may
need to be clarified when
defining algorithms.
Unless Otherwise Noted All Content © 2023 Florida Virtual School. FlexPoint™ is a trademark of Florida
Virtual School.
Answer Key
the order in which the path a program takes the repeated execution of a
programming statements given a choice section of code
are executed.
Unless Otherwise Noted All Content © 2023 Florida Virtual School. FlexPoint™ is a trademark of Florida
Virtual School.
Answer Key
1. To move the cows to the pen and the chickens to the barn, one set of animals must go to a
temporary holding pen while the other is transferred.
2. The cows are moved from the barn to the temporary pen. Now the barn is empty, and the
chickens can move from their pen to the barn.
3. The chickens are all settled, and the cows can move from the temporary pen into the pen
that originally held the chickens.
1 3
2
Explain the role of and provide the symbol for each of the operators:
Review the table to see the way JavaScript uses arithmetic operators.
𝑥𝑥 𝑛𝑛
Arithmetic
Operator + - × ÷
JavaScript
Operator + - * / **
JavaScript a+b b−a a*b b/a b ** a
Examples 5 + 10 10 − 5 5 * 10 10 / 5 5 ** 10
Unless Otherwise Noted All Content © 2023 Florida Virtual School. FlexPoint™ is a trademark of Florida
Virtual School.
Answer Key
Expressions in programming are evaluated from left to right, following the order of operations you
learned in math class. You may have learned the PEMDAS acronym to help remember the order:
P Parentheses ( )
E Exponents **
M Multiplication *
D Division /
A Addition +
S Subtraction -
Modulus is an arithmetic operator that finds and only returns the remainder of the division of two
positive integers. It can be expressed as: a MOD b or a % b.
• In programming, modulus is expressed using the % operator and is evaluated at the
same level as multiplication and division for the order of operations.
• Even numbers modulus 2 evaluate to 0, and odd numbers modulus 2 evaluate to 1.
• Programmers use modulus 2 to figure out if a value is even or odd.
Code Result
13 MOD 2 1
6 MOD 3 0
20 % 6 2
32 % 7 4
Unless Otherwise Noted All Content © 2023 Florida Virtual School. FlexPoint™ is a trademark of Florida
Virtual School.
Answer Key
Calling Functions
Functions help programmers divide a program into smaller parts to create reusable and less complex
code. Writing a function once and using it multiple times reduces the complexity of a program
through easier debugging.
For example, winLevel(); calls the function winLevel() and tells the program to execute it now.
Unless Otherwise Noted All Content © 2023 Florida Virtual School. FlexPoint™ is a trademark of Florida
Virtual School.
Answer Key
Function Parameters
function calcValue(num1) Num1
function printName(first, last) first, last
JavaScript stores user input from the prompt() method as a string. Storing data as a string is
useful for inputs like the current month or a person's name, but it causes a problem when that
input should be a number. Programmers resolve this issue by casting a variable's data type from one
type to another. The Number() method casts a string to a number. Remember that JavaScript is
case-sensitive, so the Number() method must start with an uppercase N.
The prompt() method is inside the Number() method. The Number() method casts the string
returned by the prompt() methos to the number data type!
programmers often need to create functions that return data to be used elsewhere in the program
or as input for another function. Functions do this by using return values. Return values return
data and execution control back to the program.
What is the value that is returned when the code below runs if val1 is 10 and val2 is 7?
Unless Otherwise Noted All Content © 2023 Florida Virtual School. FlexPoint™ is a trademark of Florida
Virtual School.
Answer Key
When a program reaches the return value in a function, it stops executing and returns the control
to the main program. The program will not execute any code statements after the return
statement.
Developing Functions
a programmer may work on a program that needs a user login. Since users log into many
applications, the programmer may create a reusable function for this task and share it with other
programmers to use in their programs. The programmers who reuse the user login code don't need to
know exactly how the function works; they only need to know its name, the inputs, and the
expected output. Reusing a function without knowing its details is called functional abstraction.
Using functional abstraction to create generalized functions helps programmers manage the
complexity of their programs. Defining functions once and reusing them as needed helps make the
code easier to read and update.
Programmers first Next, the programmers map out Then the programmer mocks up an expected
define the purpose, the functionality of the program. output that they want the program to output
Unless Otherwise Noted All Content © 2023 Florida Virtual School. FlexPoint™ is a trademark of Florida
Virtual School.
Answer Key
** For this simulation, the display flight information, user input for seat number, and print ticket
processes are good candidates for functions because the program can reuse the processes for each
passenger. **
Unless Otherwise Noted All Content © 2023 Florida Virtual School. FlexPoint™ is a trademark of Florida
Virtual School.
Answer Key
Programming Libraries
Application program interfaces the details and directions for using methods from libraries
Let's say you're writing a program for a website that calculates the total for an online shopping
cart, but you also want to add a currency conversion option for your customers that live in other
countries. You could write a currency conversion function yourself. However, since currency
conversion is a common task, you could search for a currency conversion programming library
instead.
If you find a library that fits your needs, you could use that code in your program. Finding a
currency conversion library can save you time because you don't need to create the code. But
remember, when programmers use code authored by another programmer, they must also give credit
to the original programmer.
Software languages also supply their own standard libraries for common tasks. For example, the
Math module in JavaScript provides functions for most common mathematical tasks.
Unless Otherwise Noted All Content © 2023 Florida Virtual School. FlexPoint™ is a trademark of Florida
Virtual School.
Answer Key
What may start as a function in a programmer's code may also become a library that can help
other programmers. Let's explore some standard libraries that programmers may use to help reduce
their coding time and manage the complexity of their programs.
Application program interfaces (APIs) provide documentation details for libraries and include when
to use a library and the way the library works. This documentation instructs programmers on using
the library in their code and
should include a name, description,
introduction, background, and
usage examples.
Ex)
Unless Otherwise Noted All Content © 2023 Florida Virtual School. FlexPoint™ is a trademark of Florida
Virtual School.