Computer Science 1000 Terminology IV Permission to redistribute these slides is strictly prohibited without permission Software a collective term for computer programs recall our definition for a computer program a sequence of instructions designed to perform a task a true definition should also include data, as most programs include non-instructional data as well examples of data: button labels, menu items, numbers, etc note that both instructions and data stored as binary sequences software is typically classified into two types Software - Types 1) Application Software designed to perform a user task basically, the programs you are used to using examples: text editing (notepad, Word) spreadsheets (Excel, Calc) browser (Chrome, Firefox, Internet Explorer) music (iTunes, Windows Media Player) many others Software 2) System Software designed to perform system tasks they support the applications that you use examples: operating systems (O/S) drivers* loaders* utility programs* and others * These are sometimes considered part of the operating system. MultiTasking consider your typical desktop experience you are probably running several programs at once e.g. you are typing notes while surfing Facebook and updating Twitter this "simultaneous" execution is known as multitasking in order for a program to "run", its instructions have to execute how is it that one CPU core is able to run more than one program simultaneously? MultiTasking as it turns out, each core will only execute a single program at a time in other words, programs have to share processor time a core will execute a program for a small amount of time (a time slice), and then start executing another program this change is known as a context switch typical time slice lengths: 10-100ms* these switches occur so quickly, that to us, it appears that the programs occur simultaneously *http://www.stanford.edu/class/cs140/cgi-bin/lecture.php?topic=scheduling Loading a Program recall that programs are stored on your hard drive when not in use to run a program, it (or part or it) is copied into RAM this is known as loading a program how does loading take place? another program, called a loader A Few Unresolved Issues multitasking program loading how does a processor know which program to switch to on a context switch? what defines the length of a time slice? how does a processor know where a program exists in memory? what decides where a program is loaded in memory? Answer: the operating system Operating System the most important software on your system a collection of programs that perform many of these tasks: allocate CPU time to programs loads and manages programs in RAM keeps track of files on your hard drive (file system) facilitates communication with devices like keyboard, mouse, display, etc and much more! Popular Operating Systems Windows developed by Microsoft first released: 1985 the most popular operating system 82% market share (December 2012) http://www.netmarketshare.com/operating-system-market-share.aspx?qprid=8 Popular Operating Systems MacOS developed by Apple for their computers first released: 1984 excluding Windows, comparatively popular 6% market share Popular Operating Systems Linux developed by Linus Torvalds first released: 1991 1.27% market share, but fills niche roles supercomputers (90% of worlds fastest)* servers (64.7% market share) academics most variants are free! *http://www.top500.org/ Input/Output almost always referred to as I/O refers to the process of: input output reading data into the computer sending data out of the computer occurs via ports on your computer Input – Sources the obvious ones: keyboard mouse game controller the not-so-obvious ones internet connection external hard drive webcam Output – Sources the obvious ones: display speakers printer the not-so-obvious ones internet connection external hard drive game controller (force-feedback) Note that devices can be both input and output. Two Neat Facts about I/O 1) It's typically slow ... ... by comparison to other operations in your computer e.g. consider how many CPU cycles occur between user keystrokes/mouse clicks/webpage loads often, a program that is waiting for I/O will be context-switched (so that processor stays busy) Two Neat Facts about I/O 2) It requires a driver different devices have different communication protocols for a program to communicate with a device, it has to speak its language a driver is a program that acts as a translator between other programs and its device "Concept" Terminology certain terms refer to concepts that: we consider a few here are not specific to computer science often used in computer science algorithm abstraction your textbook discusses others generalization, factors of improvement, operational attunement, mnemonic, etc ... Algorithm a precise and systematic method for solving a problem – Text notice anything about this description? no mention of hardware no mention of software in other words, algorithm is not computer science specific however, algorithms and computer code are often used interchangeably why? Algorithm – Example write an algorithm for making a chocolate cake (assume you have correct ingredient amounts and supplies.) Step 1: Step 2: Step 3: Step 4: Step 5: Step 6: Melt chocolate and butter Stir sugar into melted chocolate Mix in flour Spread mix in greased pan. Bake at 350F for 40 minutes Cool in pan http://www.gmtel.net/web/windowshelp/algorithm.htm Algorithm not all algorithms execute in such a linear fashion 1) some steps may not execute under certain conditions example: algorithm for making a salad Step 1: Step 2: Step 3: Step 4: Step 5: Add lettuce to bowl Add tomatoes to bowl Add carrots to bowl Add dressing to bowl if I am not on a diet Add croutons to bowl Algorithm not all algorithms execute in such a linear fashion 2) some steps may execute more than once example: algorithm for washing hair Step 1: Step 2: Step 3: Step 4: Add shampoo Lather Rinse Repeat Steps 1-3 until hair is clean Algorithm and Programming many people equate programming with coding programming largely involves: e.g. if you know code, you are a programmer this is a bit like saying if you know English, you are a writer developing an algorithm converting that algorithm to code the following is an example from my 1620 class not necessary to understand the code – the point is to illustrate this process Example (Text): Write a program to compute the perimeter and area of a rectangle. The length and width of the rectangle will be specified by the user. Algorithm Step 1: Step 2: Step 3: Step 4: Step 5: Read the length of the rectangle from the user. Read the width of the rectangle from the user. Compute the perimeter of the rectangle. Compute the area of the rectangle Output the results of this computation to the screen. Design (area and perimeter calculation) Step 1: Read the length of the rectangle from the user. Step 2: Read the width of the rectangle from the user. Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen. Design (area and perimeter calculation) Step 1: Read the length of the rectangle from the user. Step 2: Read the width of the rectangle from the user. Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen. Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; Step 2: Read the width of the rectangle from the user. Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen. Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; Step 2: Read the width of the rectangle from the user. Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen. Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen. Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; Step 3: Compute the perimeter of the rectangle. Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen. Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; int perimeter = 2 * (length + width); Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen. Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; int perimeter = 2 * (length + width); Step 4: Compute the area of the rectangle Step 5: Output the results of this computation to the screen. Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; int perimeter = 2 * (length + width); int area = length * width; Step 5: Output the results of this computation to the screen. Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; int perimeter = 2 * (length + width); int area = length * width; Step 5: Output the results of this computation to the screen. Design (area and perimeter calculation) int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; int perimeter = 2 * (length + width); int area = length * width; cout << "The perimeter of the rectangle is " << perimeter << endl; cout << "The area of the rectangle is " << area << endl; Write program to compute the perimeter and area of a rectangle. The size of the rectangle will be specified by the user. #include <iostream> using namespace std; int main() { int length; cout << "Please enter the rectangle's length: "; cin >> length; int width; cout << "Please enter the rectangle's width: "; cin >> width; int perimeter = 2 * (length + width); int area = length * width; cout << "The perimeter of the rectangle is " << perimeter << endl; cout << "The area of the rectangle is " << area << endl; return 0; } To summarize, an algorithm refers to the process, not just the code Abstraction expressing a concept in a more general form related to level of detail the higher the abstraction, the less details are considered common in computer science/algorithms Abstraction - Example consider our chocolate cake example Step 1: Step 2: Step 3: Step 4: Step 5: Step 6: Melt chocolate and butter Stir sugar into melted chocolate Mix in flour Spread mix in greased pan. Bake at 350F for 40 minutes Cool in pan Abstraction – Less (More Detail) consider our chocolate cake example Step 1: Step 2: Step 3: Step 4: Step 5: Step 6: Melt chocolate and butter Stir sugar into melted chocolate Mix in flour Spread mix in greased pan. Bake at 350F for 40 minutes Cool in pan Step 1a: Step 1b: Step 1c: Step 1d: Place chocolate in pan Place butter in pan Apply blowtorch Repeat Step 1d until soft Abstraction – More (Less Detail) consider our chocolate cake example Step 1: Step 2: Step 3: Step 4: Step 5: Step 6: Melt chocolate and butter Stir sugar into melted chocolate Mix in flour Spread mix in greased pan. Bake at 350F for 40 minutes Cool in pan Step 1: Combine ingredients Abstraction – Examples in computer algorithms High Abstraction Less Abstraction Step 1: Load file Step 2: Convert all a's to @'s Step 3: Save file Step 1: Step 2: Step 3: Step 4: Open Windows Explorer Double click on required file Click Ctrl-F .... Abstraction – Why? in computer programs, there is usually a lot going on some details are not important in certain contexts saving a file can be described without discussing individual bits, hard drive sectors, etc ... complete details can be overwhelming billions of instructions executing I/O read/writes etc ... imagine trying to describe saving a file at a hardware level the right amout of abstraction depends on situation electrical engineer: very low level of abstraction tech support: very high level of abstraction