Uploaded by J'Quan Evans

Computer Science Notes 08-30-19

advertisement
What is the difference between programming and problem solving?
What is the difference between programming and computer science?
Programming is only a part of computer science.
09-02-19 Notes
What is a computer?
A tool that follows instructions to the letter. So if something is done wrong it’s
99.9% of the time user error.
Ex. Laptop, Cell Phone, Calculator, Toaster, etc.
Parts of a computer:
Processor
Central Processing Unit (CPU)
- Function: It’s the brains of the operation
- Two pieces, ‘The Controller’, ‘ALU (Arithmetic Logic Unit)’
Motherboard
GPU
Case
Fan/ Cooling
RAM (Random Access Memory)
- Used to store data
- You don’t have to read sequentially through all the memory to access it
- Volatile, meaning it only holds the things that it’s remembering while it has
power. When turned off, the memory is wiped.
- It essentially functions as short-term memory.
- Keystrokes usually end up in RAM.
ROM (Random Operating Memory)
- Secondary Storage
- Long Term Memory
Power Supply
Drives-had/ Solid State
Battery
Input Devices
- Keyboard
- Mouse
- Microphone
- Flash Drive
Computers are just giant calculators.
Abstraction: A simplified representation, the hiding of details that we don’t need to
worry about so that you can focus on details that do matter.
Fetch and Execute Cycle: Give me the next instruction I’m supposed to execute.
Afterwards, it goes down to the next instruction, it goes back and fetch the next
instruction, then it’s ready to go again.
Compiled - code you enter is reduced to a set of machine-specific instructions
before being saved as an executable file.
Vs.
Interpreted - the code is saved in the same format that you entered.
Ex. Java, Python
09-04-19
1 bit = the amount of space required to hold a 0 or 1
1 byte = 8 bits
1 Kb = 1024 bytes (1000 or 8000 0’s and 1’s)
1 Mb = 1024 Kb (1,000,000 or 8,000,000 1’s and 0’s)
1 Gb = 1024 Mb (1,000,000,000 or 8,000,000,000 1’s and 0’s)
1 Tb = 1024 Gb (1,000,000,000,000 or 8,000,000,000,000 1’s or 0’s)
Software Engineering Life Cycle
1970’s- Software Crisis
1. Understand The Problem
- What is it we are trying to solve with technology?
- What are the conditions/ domain that it lives in?
2. Write an algorithm which solves the problem.
- An algorithm is a list of instructions.
- Should not be in a programming language.
- Come up with a few solutions, so that you have many to draw from.
3. Translate the algorithm into some programming language that the
computer can understand.
4. Test and Debug
- This is to make sure the program works.
- Test it from different sets of data.
- Does it produce the right answers?
- Find and eliminate bugs.
This is a cyclical process.
Practice Problems
Given a person’s age and their birth year, tell them what year they can
retire. Assume retirement at age 65.
1. We are trying to tell someone what year they turn 65.
2. Algorithm
I.
Input: Age, Birth Year
II.
Output: Retirement Year
III. Formulas/other: Assume 65, birth year + 65
A. Get Inputs
i.
Get the two inputs you need: age + birth year
a. You have to ask them what year they were born.
b. After the response, you’re going to remember what they
said.
B. Do the Work
i.
Calculate how many years are left are left
ii.
Calculate the year of retirement.
a. Year of retirement = birth year + 65
C. Display the Results
i.
Display the year of retirement.
a. Display the year of retirement…
09-06-19
Getting the birth year involves getting input from the other person.
Code:
Year_of_birth = int(input(\n))
Year_of_Retirement = Year_of_birth + 65
Print(Year_of_retirement)
09-09-19
I-----Object
I
State – Attributes
Instantiate------- I
Behaviors
I
Methods Attributes
I-----Class
Reuse
Data Types
i.
Interger
ii.
Float --------------I
iii. Characters--------I
iv.
Boolean (variable that holds a true or false)
v.
Strings (a collection or list of characters)
vi.
Concatenation (taking a longer string and combining it
into one line) ex. ,+ ; +=
End = ‘ ‘
Escape characters:
\n
\t
\”
\’
\\
09-11-19
Variables – Assignment Statement
Identifier = Expression
i.
Literal
ii.
Variable Identifier
iii. Complex Expression
Convention (High-Level Standards):
I.
Must start with a aletter
II.
Use “_” for multiple words
III. Use lower-case letters
IV. Use meaningful names
V.
Avoid Keywords
Python is a dynamically typed language, as opposed to statically typed. (ex. Java,
C)
“interesting Functions”:
Ord () = ordinal – The numeric representation of the character it’s assigned to
Chr () = Character function – takes the ordinal and converts it to the character.
ASCII – American Standard Code for Information Interchange
Unicode – A universal standard for coding. (Most computers support this)
Arithmetic Function
+ - Addition
- Subtraction
* - Multiplication
/ - Floating Point Division
// - Integer Division
% - Remainder
** - Multiplication to a power
All languages support PEMDAS
Download