COSC-1435: EXAM 1
Binary Digits
(bits) on and off states
Selection structure
(decision logic) you ask a question and, depending on the answer you take one of two courses of action. -execute an operation if a condition is true
Repetition structure
(loop logic) execute a block(set) of operations multiple times until a certain condition is met. -EX: Shampoo Algorithm
logica operaters
-AND, OR, and NOT -combining conditions
What is the CPU composed of(2)?
-Arithmetic & Logic Unit -hardware optimized for high speed numeric calculation and logic comparisons; true/false, yes/no decisions -Control Unit -retrieves and decodes program instructions -coordinates activities of all other parts of the computer
What are the problem solving techniques(4)?
-Ask Questions: about the data, the process, the output, error conditions -Look for Familiar Things: certain situations arise again and again -Solve By Analogy: it may give you a place to start -Overcome Mental Block: by rewriting the problem in your own words
What is inside the black box(2)?
-Data Representation -Data Prosessing
Ways to combine conditions....
-If (condition 1 AND condition 2) -If (condition 1 OR condition 2) -If (NOT condition 1)
Main Hardware Component Categories (five)
-Input devices (keyboard, camera) -Output devices (screen, speakers, printer) -CPU:central processing unit -RAM (main memory) -Secondary storage devices
What are the data types and their data sets(5)?
-Numeric: Integer (all whole numbers +&-) EX: -397874, 3637 -Numeric: Real (all real numbers (whole+decimal)) EX: -28377.80, 0.01298, 83764 -Character (surrounded by quotations: all letters numbers and special symbols)EX: =, -, +, A, c, 1 -String (surrounded by quotations: combined of more than one character) EX: 48386, milk -Logical(True, False)
What is the machine cycle?
-fetch: retrieve the next instruction from memory and then increment the program counter(PC) -decode: decode bit pattern in the instruction register -execute: preform the action required by the instruction of the Instruction Register(IR)
Main Memory (RAM)
-is the main component of a computer in witch data is stored for quick access by the computers processor. -it is volatile. Main memory is erased when program terminates if computer is turned off -Random Access Memory
What is a program made of(5)?
-key words -programmer defined identifiers -operations -punctuation -syntax
What are the types of non-volatile memory(4)?
-magnetic -solid state -optical -flash drives
What kinds of data do we need to represent(6)?
-numbers -text -images -sound -logical (true, false) -video
What two conditions do computers recognise?
-presence of a voltage(short circuit) - state 1 -absence of a voltage (open circuit) - state 0
What are the three decision logic structures?
-straight through logic -nested if/else -if/else if/else (else if ladder)
What is the difference from real code vs pseudocode?
-the designer focuses on the LOGIC of the algorithm without being distracted by details of language syntax (real code)
What should the control unit control(2)?
-which operation to preform -which data to be operated on
Volts of 0
0 - 0.5
What are the byte values?
0000 0000 = 0 1111 1111 = 255 = 2^8-1
2^2 (binary)
00001111 (by fours)
2^1 (binary)
00110011 (by twos)
2^0 (binary)
010101010101 (by ones)
What are three steps that a program typically preforms?
1) GATHER IMPUT DATA -from keyboard -from files on disk drive 2)PROCESS IMPUT DATA 3) DISPLAY THE RESULTS AS AN OUTPUT -send it to the screen -write to a file IMPUT --> PROCESS --> OUTPUT
What are the fundamental control structures(3)?
1) Sequential logic structures 2) Selection structure (decision logic structure) 3)Repetition structure (loop logic structure)
Volts of 1
2.4 - 2.9
Byte
8 consecutive bits (bytes have addresses)
What is the maximum decimal number of 3 digits?
999 = 10^3-1
Flowchart: Decision Logic Structure
A (oval) false If (diamond) true Instruction (rectangle) Instruction (rectangle) B (oval)
What is a variable?
A named memory location that can store a value
Optical
CD-ROM,DVD
What is in a decision logic structure?
IF.....ELES IF.....ELSE....END IF
What is returned to the user?
Information
What does MAR stand for?
Memory Address Register
What does MDR stand for?
Memory Data Register
Flowchart: Sequential logic structure
Module name (oval) Instruction (rectangle) Instruction (rectangle) Exit (oval)
Write pseudocode that asks the user to enter a number. The algorithm will find and display the sum of all the even numbers up to the value entered by the user.
Print "Enter a number: " Get given number<--2 sum<--2 While (number<= given) sum<--sum +number number<--number +2 End while Print sum End
Write pseudocode that tells a user that the number they entered is neither a multiple of 5 nor a multiple of 6.
Print "Enter a number: " Get number byfive <-- number/5 bysix <-- number/6 If (byfive= 0) Print "The number you entered is a multiple of 5." Else if (bysix = 0) Print "the number you entered is a multiple of 6 Else Print "The number you entered is not a multiple of 5 or 6." End if
Write pseudocode that performs the following: a) Ask the user to enter a number. b) If the number is between 0 and 10 (inclusive), print the word 'Blue'. c) If the number is between 11 and 20 (inclusive), print the word 'Red'. d) if the number is between 21 and 30 (inclusive), print the word 'Green'. e) If it is any other number, print that it is not a correct color option.
Print "Enter a number: " Get x If (x >= 0 AND x <= 10) Print "Blue" Else if (x >=11 AND x <=20) Print "Red" Else if (x >= 21 AND x <= 30) Print "Green" Else Print "That is not a color option." End if
Write pseudocode that will perform the following. a) Read in 5 separate numbers (in 5 separate variables). b) Calculate the average of the five numbers. c) Find the smallest (minimum) and largest (maximum) of the five entered numbers. d) Write out the results found from steps b and c with a message describing what they are.
Print "Give me 5 numbers: " Get numone Get numtwo Get numthree Get numfour Get numfive average <-- (numone + numtwo + numthree + numfour +numfive)/5 If (numone > numtwo) maxnum <-- numone Else maxnum <-- numtwo End if If (maxnum < numthree) maxnum <-- numthree Else maxnum <-- maxnum End if If (maxnum < numfour) maxnum <-- numfour Else maxnum <-- maxnum End if If (maxnum < num five) maxnum <-- numfive Else maxnum <-- maxnum Print "The max number is : " maxnum If (numone < numtwo) minnum <-- numone Else minnum <-- numtwo End if If (minnum > numthree) minnum <-- numthree Else minnum <-- minnum End if If (minnum > numfour) minnum <-- numfour Else minnum <-- minnum End if If (minnum > num five) minnum <-- numfive Else minnum <-- minnum Print "The minimum number is : " minnum Print "The average is: " average
Write pseudocode that reads three numbers, multiplies them together, and prints out their product.
Print "Give me three numbers: " Get numone, numtwo, numthree total <-- numone* numtwo* numthree Print total End
What does PC stand for?
Program Counter
What is syntax?
The arrangement of words and phrases to create well-formed sentences in a language; Sentence structure
Low level programming languages
Used for communication with computer hardware directly. Often written in binary machine code (0's/1's) directly. -Machine language -Assembly Language
What is in a repetition structure?
WHILE....END WHILE LOOP DO....WHILE LOOP
Flowchart: decision
a diamond
Flowchart: input/output
a paralellogram
Flowchart: a process
a rectangle
Algorithm
a step-by-step procedure for solving a problem; well-defined procedure that allows an agent to solve a problem
What is a sentinel value?
a value to be typed in to stop a loop
Pseudocode
abstract logical steps describing a computer programming algorithm
What is a logic gate?
an electronic component whose output voltage depends on the input voltage
What is 0 usually called in a loop?
an indicator, flag, sentinel, or trip value
Machine Instructions
an instruction (or command) encoded as a bit pattern recognizable by the CPU
Flowchart: start/end
an oval
Flowchart: arrows
arrow : a relationship
Instructions and data are composed only a series of what?
bits
High level programming language
closer to human language -C++, Python, Java, ect.
Flash Drives
connected to USB port
Write pseudocode to print all multiples of 5 between 1 and 100 (inclusive).
count <-- 1 While (x <= 100 AND x >= 1) x <-- count * 5 Print x count <--count +1 End while
non-volatile memory
data retrained when program is not running or computer is turned off.
Solid-State
data stored in chips, no moving parts SSD
How many bits form a byte?
eight
What is a nested if?
if statement within an if statement
What do you call the amount of voltage in between 0 and 1?
illegal
What does IR stand for?
instruction register
Program
instructions in computer memory to make it do something
What is straight through logic?
multiple if statements outside of each other
Do computers understand pseudocode?
no
10d is....
number ten
10b is....
number two
What do computers only recognize?
on and off states (like a light switch)
Programmer
person who writes instructions (programs) to make computer perform a task
The sequential logic structure
preform an action or task, and then you preform the next action, in order
Computer
programmable machine designed to follow instructions
pseudocode primitives and conventions
pseudocode often asks for user input assigns variables and prints an output. variables constants
Machine Language (Machine Code)
set of all instructions recognized by a machine
Bit
smallest piece of memory. HAs a value of 0(off, false) or 1(on, true)
magnetic
traditional hard drives that use a moveable mechanical arm to read/write HDD
What is a compiler?
translates high level language to machine language -When you run compiled code; the machine language instructions will be loaded to memory and executed
What must a variable name be(2)?
unique and a single word
Address
uniquely identifies on byte in the computers main memory(RAM)
Data is...
unorganized facts that are processed by the program
What is a for loop?
use when you know, in advance, the number of times the loop will be executed
What is a constant?
variable that stays the same EXAMPLE: pi