0% found this document useful (0 votes)
6 views22 pages

AP Computer Science Practice

The document discusses the importance of collaboration in computing innovation, emphasizing that diverse perspectives help avoid bias and enhance the development process. It outlines various types of collaboration, such as pair programming and user consultation, and describes the iterative and incremental phases of program development, including investigation, design, prototyping, and testing. Additionally, it highlights the significance of acknowledging contributions from team members and external sources in program documentation.

Uploaded by

shaindyganz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views22 pages

AP Computer Science Practice

The document discusses the importance of collaboration in computing innovation, emphasizing that diverse perspectives help avoid bias and enhance the development process. It outlines various types of collaboration, such as pair programming and user consultation, and describes the iterative and incremental phases of program development, including investigation, design, prototyping, and testing. Additionally, it highlights the significance of acknowledging contributions from team members and external sources in program documentation.

Uploaded by

shaindyganz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

1.

1 VIDEO 1-Collaboration
★​ A computing innovation includes a program as an integral part of its function.
★​ A computing innovation can be physical (self-driving car), nonphysical computing
software (picture editing software), or a nonphysical computing concept (e-commerce).
★​ Effective collaboration produces a computing innovation that reflects the diversity of
talents and perspectives of those who design it.
★​ Collaboration that includes diverse perspectives helps avoid bias in the development of
computing innovations.
★​ Effective collaboration teams practice interpersonal skills, including, but not limited to:
○​ Communication
○​ Consensus building
○​ Conflict resolution
○​ Negotiation
Examples
1.​ Facebook: has large areas for team collaboration
2.​ Super Mario brothers 2 vs. Super Mario brothers 3: Kensuke Tenabe and Shigeru
Miyamoto worked together to create Super Mario brothers 2 and 3.

Practice
What are the benefits of collaborating with your peers?
a.​ Effective collaboration suppresses communication, consensus building, conflict
resolution, and negotiation skills.
b.​ Effective collaboration produces a computing innovation that reflects the diversity
of talents and perspectives of those who designed it.
c.​ Collaboration gives you a chance to be the alpha and lets your classmates marvel at
your sheer dominance while you belittle them.
d.​ Collaboration that includes diverse perspectives promotes bias in the development of
computing innovations.

1.1 VIDEO 2-Collaboration


●​ Consultation and communication with users are important aspects of the development
of computing innovations.
●​ Information gathered from potential users can be used to understand the purpose of a
program from diverse perspectives and to develop a program that fully incorporates
these perspectives.
●​ Online tools support collaboration by allowing programmers to share and provide
feedback on ideas and documents.
●​ Common models such as pair programming exist to facilitate collaboration.
●​ Types of collaboration:
○​ Pair programming-2 programmers work together as a pair. One (the driver)
writes the program code, while the other (the observer, pointer, or navigator)
reviews each line of program code as it is typed in.
○​ Think-Pair-Share-students think through a problem alone, pair with a partner to
share ideas, and then share results with the class.
●​ Leaving comments in code:
○​ Helps you communicate with your partners
○​ Communicate with yourself (remind yourself what you were doing)
○​ Acknowledge code segments used from other sources
○​ Acknowledge media used from other sources
○​ Differentiate what you and your partner(s) did (give credit where credit is due)
○​ Clarify the functionality of your code.
■​ If your programming language does not let you include comments, add
them in an editor in post.
●​ How to collaborate in class:
○​ repl.it-multiplayer
○​ GitHub-collaboration and repository (collaborate with different people working in
your industry)
○​ Shared document or folder
○​ Ask friends and family to test drive your program and give you feedback

1.2 VIDEO 1

The purpose of computing innovations is to solve problems or to pursue interests through


creative expression.

An understanding of the purpose of a computing innovation provides developers with an


improved ability to develop that computing innovation.

There are different categories of Computing innovations:


A)​ Applications-all things you download onto your device (computer, phone, tablet). These
are software applications (u download).
a)​ Games
b)​ Social media
c)​ Business
d)​ Productivity
B)​ Physical Devices- things you hold in your hand, sit on a table,wear,etc.
a)​ Computers
b)​ Smart Phones/tablets
c)​ Smart “things”-something that you may not always be interacting with physically,
but it’s interacting with your computer, tablet, phone. Ex is a smartwatch, a smart
doorbell, garage door opener, thermostat, etc.
d)​ Wearables-something you wear on your body that helps you do things you
couldn't do before-smart watch.
C)​ Systems
a)​ E-commerce (electronic commerce)-how we shop online
b)​ Cloud services-all files we store online are stored in the “cloud”
c)​ E-mail
To determine the purpose of a computing innovation, think:
●​ Why does the computing innovation exist?
●​ What problem(s) does computing innovation solve?
●​ What does the computing innovation allow us to do that we could not do before?

~Social media applications-My answer


Social media is to help people connect and communicate. It solves the problem of
people being unable to communicate with people far. It allows us to communicate in a
way that was not possible before. People can also speak to millions of people at once
with one post..
~Social media applications-Their answer
Social media allows users to connect from a distance and archive their activities (can
scroll back and see what they did in past.

~E-commerce-My answer
E-commerse exists to help people shop online without needing to go out to stores

~E-commerce-Their answer
Allows users to save money and time by being able to shop from home.

~Digital Assistant device-My answer


To assist the user quickly and efficiently
~Digital Assistant device-Their answer
Allows users to control their devices hands-free, making them safer while driving or more
convenient when trying to multitask.

1.2 VIDEO 2 Program Function and Purpose

Computer programs take inputs in a variety of fashions to influence the program’s behavior

Program inputs are data sent to a computer for processing by a program. Inputs can come in a
variety of different forms, such as tactile, audio, visual, or text.

An event is associated with an action and supplies data to a program.

Events can be generated when a key is pressed, a mouse is clicked,a program is started, or any
other defined action occurs that affects the flow of execution.

Inputs usually affect the output produced by a program.

In event driven programming, program statements are executed when triggered rather than
through the sequential flow of control.
Input can come from a user or other programs.

Program outputs are any data sent from a program to a device. Program output can come in a
variety of forms, such as tactile, audio, visual, or text.

Program output is usually based on a program’s input or prior state (ex: internal values).

Identifying inputs-inputs come in different forms such as:


❖​ Tactile (touch)
❖​ Audio
❖​ Visual
❖​ Text (including numbers)

➔​ Phones/tablets-have a touchscreen (touch input). Different ways you touch the screen,
different buttons you press=different inputs through touch. Face ID=visual input. Type in
your passcode=text.
➔​ Laptop-has a mouse, keyboard
➔​ Gaming console-you push the different buttons (A, B, up, down…)-you’re inputting
information.

Most programs are written in an event driven environment

Events are triggered by some action, which usually sends input to the program.

Ex of events that a user can trigger


Mouse clicks, screen taps/ swipes (force touch-if you touch the screen really hard), physical
button clicks, keyboard entries, audio trigger (keyword/phrase=hey siri)

What does the input accomplish in a program?


The input usually affects the output. (Usually because if you click the screen but your phone is
off, nothing will happen. It’s the same input but you won't have an output. Or if you say “what’s
the weather?” but you don’t say “hey siri” first.)

Outputs come in different forms such as:


★​ Visual
★​ Audio
★​ Tactile (touch/feel)
★​ Text

Ex of outputs in our devices:


➢​ phone/tablet
○​ when you say things, press things, etc.-you can see diff things changing on your
screen=visual
○​ You can also hear different things=audio
○​ If you press something and then your phone vibrates=tactile
○​ If your phone displays a certain text to give you instructions/ inform you of an
error=text output

➢​ Laptop-has a screen, you can see things=visual


○​ You can hear things=audio
○​ Laptops don’t really have tactile
○​ Displays text=text

➢​ Gaming console
○​ Remote vibrates=tactile

How does a program know what to do upon an event?


An action triggers an event. Action may be initiated by the user or another program/device. Let's
say you have a smart doorbell and someone rings the bell-that may trigger an event/notification
on your phone.

The program jumps to the code segments according to the event. There may be many lines of
code. They don’t all have to be executed in the order they are written. The code segment is
executed and the output is triggered by the code segment (or additional events are triggered).

Event driven programming is when the program jumps to a specific line of code and executes it
based on a trigger to that event.

Program code is not necessarily executed in order. They are executed as they are called,
according to the events triggered.

1.2 VIDEO 3- Program Function and Purpose


A program is a collection of program statements that performs a specific task when run by a
computer. A program is often referred to as software.

A code segment is a collection of program statements that is part of a program.

A program needs to work for a variety of inputs and situations.

The behavior of a function is how a program functions during execution and is often described
by how a user interacts with it.

A program can be described broadly by what it does, or in more detail by both what the program
does and how the program statements accomplish this function.

What is a program?
A collection of statements.
~A statement is a single command.
​ ~A group of statements is called a code segment.
​ ~Code segments are executed according to the rules of the programming language.
​ ~A program is often referred to as software. Software is something that you download.
(you download a program and run it on your device)

Ex: Have a code segment in pseudocode and block segment. The code segment was written to
find the minimum value in a list.

Code segments need to work for a variety of different lists, like lists that include:
-Numbers out of order
-Negative numbers
-Large numbers
-Decimals

This code segment could be inserted into a larger program.

The description of a code segment should simply explain what the code segment does. It should
be explained in a way that someone could use the code segment in a larger program. Or the
description should include how the segment does what it does, by explaining in detail how the
code segment functions, so that someone could expand upon the code segment.

1.3 VIDEO 1-Program Design and Development


➔​ A development process can be ordered and intentional or explanatory in nature.
➔​ There are multiple development processes. The following phases are commonly used
when developing a program:
◆​ Investigating and reflecting
◆​ Designing
◆​ Prototyping
◆​ Testing
➔​ A development process that is iterative requires refinement and revision based on
feedback, testing, or reflection throughout the process. This may require revisiting earlier
phases of the process.
➔​ A development process that is incremental is one that breaks down the problem into
smaller pieces and makes sure each piece works before adding it to the whole.
➔​ The design of a program incorporates investigation to determine its requirements.
➔​ Investigation in a development process is useful for understanding and identifying the
program constraints, as well as the concerns and interests of the people who will use the
program.
➔​ Some ways investigation can be performed are as follows:
◆​ Collecting data through surveys
◆​ User testing
◆​ Interviews
◆​ Direct observations
➔​ Program requirements describe how a program functions and may include a description
of user interactions that a program must provide.
➔​ A program’s specification defines the requirements for the program.
➔​ In a development process, the design phase outlines how to accomplish a given
program specification.
➔​ The design phase of a program may include:
◆​ Brainstorming
◆​ Planning and storybooking
◆​ Organizing the program into modules and functional components
◆​ Creation of diagrams that represent the layouts of the user interface
◆​ Development of a testing strategy for the program

How is a program developed?


It all starts with an idea. Programs are developed with a specific purpose in mind. Developers
follow specific steps and stick to their plan. Sometimes the development is more explanatory
than anything, and the steps are dictated by what happens (both good and bad).

Think about early AI projects, like a personal assistant (set an alarm for 7:30am, search for
….,play this song,etc.)
Newer AI projects use the old ones and expand them more.

Developers start investigating the problem/purpose and reflect.


Through investigation developers must:
●​ Determine the requirements of the program
●​ Understand the constraints (device does not have screen, or no buttons, or program
must be ready in 2 weeks)
●​ Understand the user concerns and interests

Developers investigate by:


​ Doing surveys-(send out list of mc,short answer questions to people)
​ Doing user testing-(send prototype to someone to use and then log what the user does)
​ Doing interviews- (ask questions, can engage in conversations about what user wants to
use this for….)
​ Doing direct observations- (sit someone in a room, tell them to use program and watch
to see how the user interacts with it)

After investigation and reflection, the developers design the program by:
➢​ Brainstorming (draw on investigation)
➢​ Storyboarding the program (draw out what the user is going to do to show what is
possible with our program)
➢​ Planning the user experience (this is how the user will interact with the program. This is
what they will see, hear…)
➢​ Laying out the user interface (what does the user have to do to interact with the device.
Does there need to be a screen? Does the user need to click different buttons? What do
they have to say?)
➢​ Organizing into modules ( Different components of the program that will be developed
individually so they can say group A will do ….. Group B will do ….)
➢​ Developing a testing strategy (how will they know that the program is actually doing what
it’s meant to do)
➢​ Deciding on program requirements that:
a)​ Describe how a program should behave
b)​ Include a list of user interactions
➢​ Making Program specifications that outline all of the requirements.
➢​ Creating a prototype. Developers create a prototype of the program (or components):
○​ An incremental process is frequently used so developers can refine small parts
(modules) of the program
➢​ Doing lots of testing at the micro and macro level. The program is tested every step of
the way.
➢​ Developers refine and revise through testing, feedback, and reflection.

1.3 VIDEO 2-Program Design and Development:


●​ It is important to acknowledge any code segments that were developed collaboratively
or by another source.
●​ Acknowledgement of a code segment(s) written by someone else and used in a program
can be in the program documentation. The acknowledgement should include the origin
or original author’s name.
●​ Program development is rarely a solo endeavor. They are usually developed by teams of
people.
●​ Individuals or teams work on different functional components. Each member of the
project deserves to receive credit for their work.
●​ Their names must be written in the documentation of the program indicating their
contributions to the project. (ex: person 1,2,& 3 worked on this part, person 4,5,& 6
worked on this part, and 7,8,9 worked on combining all the parts…)
●​ While documentation is an important place to give credit:
○​ Many projects use comments within the programming language to give credit.
○​ This is an important part of the development of the program
○​ When developers find a bug (or an error in a program), they need to be able to
determine who can/should fix the problem.
○​ This may be most useful after a program is completed, and users find additional
bugs.
●​ Many times developers use code segments, procedures, algorithms, and more
that are written by others.
○​ These other individuals are not necessarily part of the project, but thwy still
deserve to be credited.
○​ This is similar to quoting someone in a research paper or article.
○​ Any code segments, procedures, algorithms are considered intellectual property
of the author.
○​ The program documentation should include the author’s name and the source of
any code segment being used
○​ This portion of the documentation may resemble a bibliography or a works cited
page in a research paper.

Practice question:
Which of the following does not need to be sourced:
1.​ Use of code segments from another program written by someone else in a program you
are writing
2.​ Use of your own original code segments in a program you are writing.
3.​ Use of an algorithm written by someone else in a program you are writing.
4.​ Use of code segments you collaborate on with others in a program you are writing.

1.3 VIDEO 3-Program Design and Development


​ Program documentation is a written description of the function of a code segment,
event, procedure, or program, and how it was developed.
​ Comments are a form of program documentation written into the program to be read by
people, and do not affect how a program runs.
​ Programmers should document a program throughout its development.
​ Program documentation helps in developing and maintaining correct programs when
working individually or in collaborative programming environments.
​ Not all programming environments support comments, so other methods of
documentation may be required.
Programmers create program documentation in order to:
a)​ Describe the overall program
b)​ List program specifications
c)​ Describe:
i)​ functions/procedures/methods within the code
ii)​ Specific code segments
iii)​ Lists of events and corresponding outputs
iv)​ The development of the program
v)​ How other programs may interact in the program
d)​ List the contributors (authors of the program)

Documentation happens throughout the development of the program:


1.​ At the beginning: list specifications
2.​ During: to keep track of process
3.​ After: to explain the overall process (give people credit)

Documentation throughout the development process can improve:


1.​ Efficiency of overall programming process
2.​ Programmers’ ability to test and refine the program
3.​ Programmers’ response to bugs

How do programmers document while programming?


Most programming languages offer a commenting feature, although some do not.
★​ Commenting allows programmers to write text within the program.
★​ This text does not affect the program
★​ Comments are for programmers to read
★​ This is a form of documentation and can be very useful when programmers collaborate
or work individually.

Ex of comments in different programming languages:


A.​ In python:
1.​ # Comments appear on lines that follow the pound/hashtag symbol (#)
B.​ In Java:
1.​ //Comments Single line comments appear after double forward slashes (///)
2.​ /*Comments*/ Multiple line comments appear between forward slash-asterisk
combinations
3.​ /**Documentation */ Multiple line documentation comments appear between
forward slash-double asterisk combinations
C.​ Javascript, C/C++, Swift: similar to Java
D.​ XML/HTML:
1.​ <!--Comments--> Comments can be single or multi line and appear after less
than, exclamation point dash-dash, and terminate with dash-dash greater than.
E.​ Applescript/Pascal:
1.​ (* Comments *) Comments can be single or multi line and appear after an open
parenthesis asterisk and terminate asterisk close parenthesis.
In block based languages such as:
A.​ Scratch: you have a little box that pops out where you can write a comment. The box can
be minimized.
B.​ MIT AppInventor-has a question mark with a speech bubble where you can write
comments- speech bubble can be minimized.

1.4 VIDEO 1-Identifying and Correcting Errors


Errors are an inevitable part of programming!
There are 4 types of errors:
1.​ Logic Error-a mistake in the algorithm or program that causes it to behave incorrectly or
unexpectedly.
2.​ Syntax Error-a mistake when a program makes a type or writes some code or forgets to
write some code that doesn't follow the rules of the language. Syntax errors cause the
program to fail to run/compile.
3.​ Run-time Error-a mistake in the program that occurs during the execution of a program.
Programming languages define their own runtime errors. Commonly referred to as a
bug. The program starts running but can’t finish due to a problem.
4.​ Overflow Error-an error that occurs when a computer attempts to handle a number that
is outside the defined range of values.

Logic error examples-


Code for displaying letter grades based off of # grades.
Grade <-INPUT (“Enter a grade”)
IF (grade > 89) (DISPLAY (“A”))
IF (grade > 79) (DISPLAY (“B”))
IF (grade > 69) (DISPLAY (“C”))
IF (grade > 59) (DISPLAY (“D”))
ELSE (Display (“F”))

The error is that the ranges are overlapping. For example, if someone got a 99, A,B,C,D would
be displayed because 99 > 89,79,69,59…
Border case- if you got an 89.5 it should count as an A, but an 89.4 should count as a B.

Syntax error examples:


Forgetting to include
●​ A colon/ semicolon
●​ Parenthesis
●​ Curly braces
●​ Indentation
●​ Quotes
●​ Variable definition

Run-time errors may result from:


●​ Dividing by zero
●​ Inappropriately entered data type (enter a word instead of a number)
●​ Many other possibilities

Overflow error example:


If you have a calculator that can only display 4 digits, the largest number the calculator can
display is 9999. If you tried to do 100*100 you would get an overflow error because the answer
is above 9999.

1.4 VIDEO 2- Identifying and Correcting Errors


Ways to find and correct errors:
1.​ Test cases
2.​ Hand tracing
3.​ Visualizations
4.​ Debuggers
5.​ Adding extra output statement(s)

Ex: ​ 1. Most integrated development environments (IDEs) display information when there is
a syntax error. This information usually directs the programmer to the line in the program
where the error has occurred. (might say:syntax error:bad input on line 2). Sometimes
you need to do a little digging to find the error.
2. Logic errors are harder to identify. Using test cases is the first strategy programmers
use to find logic errors.

To fix the earlier example…


grade <-INPUT (“Enter a grade”)
IF (grade > 89) (DISPLAY (“A”))
IF (grade > 79 AND grade <_89) (DISPLAY (“B”))
IF (grade > 69 AND grade <_79) (DISPLAY (“C”))
IF (grade > 59 AND grade<_69) (DISPLAY (“D”))
ELSE (Display (“F”))

OR

IF (grade >89)
(DISPLAY (“A”))
ELSE (IF grade > 79) (DISPLAY (“B”))
ELSE (IF (grade > 69)(DISPLAY (“C”))
ELSE (IF (grade > 59)(DISPLAY (“D”))
ELSE (IF (grade> 49)(DISPLAY (“F”))

Hand tracing:
➔​ Hand tracing is writing out the values of the values of the variables within the loop as it
iterates to determine if the outcome is correct.
➔​ Useful for small code segments and loops that iterate a small number of times.
➔​ Larger code segments or loops might require a debugging program.
●​ Here we used hand tracing to find out that this algorithm is incorrect. The algorithm was
actually just displaying the last time a number was less than the number after it in a list.
It was not comparing each number to all the other numbers.
●​ Sometimes, even if the algorithm works one time, it is still incorrect and wont work with
other examples. Therefore, multiple varying test cases must be used.
●​ To correct this algorithm, we would need to ask if the min<list(index)<list(index+1). And
repeat the LENGTH (list) times

Adding Extra Output Statements


★​ A programmer would use this strategy to help find and fix an error.
★​ Once the error is corrected, the extra output statements are usually removed
★​ This has a similar effect as hand tracing, but allows the computer to do more of the work.

If those strategies fail…


Some IDEs allow programmers to use visualizations and/or debuggers.
➢​ Visualizations show graphs, images, color, etc. (things that can be visualized) that can
help determine if a program is working correctly.
➢​ Debuggers use software designs to run a program, allowing it to be paused and tested in
the midst of running to determine if it's working properly.

1.4 VIDEO 3-Identifying and Correcting Errors


●​ In the development process, testing uses defined inputs to ensure that an algorithm or
program is producing the expected outcomes. Programmers use the results from testing
to revise their algorithm or programs.
●​ Defined inputs used to test a program should demonstrate the different expected
outcomes that are at or just beyond the extremes (minimum and maximum of input data.
●​ Program requirements are needed to identify appropriate defined inputs for testing.

Programmers start thinking about testing on the onset of development. As soon as


programmers determine the program specifications, they start trying to answer the question,
“How will we know if the program is working properly?”.

Program Specifications influence testing


~The program specifications list the behaviors, events, and corresponding
responses/outputs the program is to support.
~Programmers need to define inputs that will determine whether or not the program
specifications are met
~This program asks if a number is less than the number after it. If yes displays the lower
number. The asks if the 2nd number is less than the one after that, if yes displays the
lower number if not, continues to display the min from before…

Programmers test their programs a ton and use the results to revise, refine, and improve their
programs. Then they test their programs again. After the programmers test, the users test and
the program is refined even more. Eventually, the program is released.
VIDEO 3.1-Variables and Assignments
A variable is an abstraction inside a program that can hold a value. (Value can be text, number,
lists, boolean values, etc.)

Think of a variable as a box


-you can store numbers in box and then label box ‘num of students’
-you can store ‘false’ in the box and label the box ‘is passing’
-you can store the text ‘hello world’ in a box labeled ‘welcome’

label=variable

Ex=
Dos: Keep it short but clear.
Let’s say you want to store the high score of a game, create a variable called ‘highScore’
If you want to store a name- fistName
For boolean value-isRaining
For phone number-phoneNumber

Don't write highestScoreInTheGame=too long


‘N’-for name=not clear enough
Is it raining=no spaces allowed
555-number=dont start a variable name with a number and -s are not allowed.

There are different data types. Make sure to store your variable with the correct type
High score=integer
First name=text or string
Is raining=boolean
Phone number=text (not integer because integer is when doing math with the numbers.)

Practice
To store a person's age
Variable name: age
Variable type: integer (have to add 1 every yr)

⬅️
3.1 VIDEO 2- Variables and Assignments

⬅️
High score 100

⬅️
firstName ”Ashley”

⬅️
isRainging true
phoneNumber ”555-0101”
“” show text/string

Changing variables

⬅️
Ex:

⬅️
Num1 4

⬅️
Num2 6
Num1 num2
After sunning code segment, num1 will be displayed as 6 and num 2 will also be displayed as 6

⬅️
⬅️
Num1 25

⬅️
Num2 15

⬅️
Num3 30

⬅️
Num2 num3

⬅️
Num3 num1
Num1 num2
After running code segment:
Num 2 will be displayed as 30
Num 3 will be displayed as 25
Num 1 will be displayed as 30 (change num 1 based off of the already changed num 2)

The output is the changed variable’s value, not the original value.

3.2 VIDEO 1-Data Abstraction


A.​ List= an ordered sequence of elements
a.​ Each element is a variable
b.​ Ex: playlist of songs, names of students in a school/class, contacts in your
phone, etc.
B.​ Element= an individual value in a list that is assigned a unique index
C.​ Index= a common method for referencing the elements (parts) in a list or string using
natural numbers
a.​ In the AP, the index starts at 1
b.​ Ex: animals- “zebra” “elephant” “giraffe” “warthog” “lion”
1 2 3 4 5
D.​ String=an ordered set of characters.
a.​ May contain letters, numbers and all other special characters
b.​ Can be words, phrases, sentences, ID numbers, etc.
c.​ Ex: “hello world!” “Chana Leah is awesome”

3.2 VIDEO 2-Data Abstraction


★​ Data Abstraction provides a separation between the abstract properties of a data type
and the concrete details of its representation.
★​ Data abstraction can be created using lists.
★​ The AP reference sheet provides notation for lists.
★​ The exam reference sheet describes a list structure whose index values are 1 through
the number of elements in the list, inclusive. For all list operations, if a list index is less
than 1 or greater than the length of the list, an error message is produced and the
program will terminate.
★​ Lists allow for data abstraction
○​ Lists bundle variables together (IT) (strings, #s, characters, etc.)
○​ Lists give one name to a set of memory cells
■​ You do not need to know how many variables will be needed in all
■​ You also don’t need to know how the variables are stored together (you
just have to trust that it works)
★​ There are 2 forms of lists
○​ Text form: word <- [“.....”]
■​ Ex: colors<- [“red”, “blue”, “yellow”, “green”]

○​ Block form: word <- “....”


■​ Ex: colors<- “red”, “blue”, “yellow”, “green”

★​
★​ Sometimes you may create an empty list so you can add things to it in future
★​ Sometimes you will want to replace one list with another which you can do with the
arrow store button thing
○​ classAStudents<-classBStudents

★​
★​

3.2 VIDEO 3-Data Abstraction


➔​ Data abstractions manage complexity in programs by giving a collection of data a
name without referencing the specific details of the representation
➔​ Developing a data abstraction to implement in a program can result in a program that is
easier to develop and maintain
➔​ The use of lists allows multiple items to be treated as a single value

How lists manage complexity of a program


●​ Improves readability
●​ You may not need as many variables. (think:variable for each student vs. one variable
that holds all the students)
●​ Change the number of variables (think: student transfers in/out of school- do not need to
add/ delete entire variable)
●​ Consistent computations (combining variables) (think: lists of test scores can be
curved with the same calculation for all the scores)

●​
●​
3.3 VIDEO 1-Mathematical Expressions
Algorithms:
➔​ An algorithm is a finite set of instructions that accomplish a specific task. (ex:recipe,
morning routine, how you wash dishes)
➔​ Beyond visual and textual programming languages, algorithms can be expressed in a
variety of ways, such as natural language, diagrams, and pseudocode.
➔​ Algorithms executed by programs are implemented using programming languages.
➔​ Every algorithm can be constructed using combinations of sequencing, selection, and
iteration.

Algorithms are made up of 3 components:


1.​ Sequencing-states that the steps will be done in a certain order
2.​ Selection- helps me choose two different outcomes based on a decision I need to make
(if yes, do… if no, do….) (asking a question)
3.​ Iteration- repeat something if something is true and stop once a condition is done (loop)

Flow charts- a form of displaying an algorithm

Arrows show sequencing


If yes/no shows selection
Loop back if yes shows iteration

Pseudocode-fake code (another form of displaying an algorithm)

The steps by # is sequencing


Step 3 shows selection
Iteration is in step 4

3.3 VIDEO 2-Mathematical Expressions


Sequencing:
❖​ Sequencing is the application of each step of an algorithm in the order in which the code
statements are given.
❖​ A code statement is a part of a program code that expresses an action to be carried out.
❖​ An expression can consist of a value, a variable, an operator, or a procedure call that
returns a value
❖​ Expressions are evaluated to produce a single value.
❖​ The evaluation of expressions follows a set order of operations defined by the
programming language
❖​ Sequential statements execute in the order they appear in the code segment.
❖​ Clarity and readability are important considerations when expressing an algorithm in a
programming language.

Code Statements and Expressions


We can store things in variables:
Grade <- 82
highScore <-currentScore
Name <- first name + last name

If we have a bunch of expressions, sequencing/order of operations will tell us in what order to


execute the expressions.

Sequencing tells us to go in order of the list…

Ex: Calculate and display the average of 3 numbers: 25, 43, 18


num1<-25
num2<-43
num3<-18
average<- (num1+num2+num3)/3
Display (average)

3.3 VIDEO 3-Mathematical Expressions


Arithmetic
●​ Arithmetic operators are part of most programming languages and include addition,
subtraction, multiplication, division, and modulus operators
●​ The reference sheet provides a MOD b, which evaluates to the remainder when a is
divided by b. Assume a is an integer greater than or equal to 0 and b is an integer
greater than 0. Ex: 17 MOD 5 =2
●​ The reference sheet provides arithmetic operators +,-,*,/, and MOD.
●​ PEMDAS is used in coding too. MOD is evaluated in the same precedence as * and /.
●​ You can use variables in your expression (grade+10)
●​ Ex:
num2 MOD 3=2
2*40=80
103/2=51.5
80+4-51.5=32.5

3.4 VIDEO 1-Strings


➢​ A string concatenation joins 2 or more strings end-to-end to make a new string.
➢​ A substring is part of an existing string
➢​ len (str) returns the number of characters in a string
➢​ Strings are ordered sequences of characters.
○​ Some procedures may exist that can be used with strings.
○​ Each language has its own procedures/methods/functions

~Len tells me that there are 5 letters in the string (“happy”)


~Concat combines the 2 strings (“CS”) and (“fun”) to get (“CSfun”)
~Substring is telling the computer which part of the string it should pull out. It needs to know
the original string, which letter to start pulling out from, and how many letters it should pull out)
(“APCSPrinciples”) is string, 3 tells comp to start at 3rd letter (C) and 6 tells the comp to pull out
6 letters= “CSPrin”

You might also like