Computera machine that under the control of a program does a. input, b. processing (like arithmetic operations or comparisons or spell checking), c. output( like the list of misspelled words), d. saving of the results for later use. Program- a structured combination of data and instructions that is used to operate a computer Hardware: the computer’s physical components For input- keyboard, mouse For processing- CPU, motherboard, random access memory For output-monitor, speakers, printers For storage -floppy disks, CDRW’s, hard drive Software- computer programs, a list of instructions that tell the computer what to do. Divided into system software( like operating systems and utilities)and applications software(word processing) Programs implement “algorithms”- step by step procedures to perform a specific task, essentially a recipe a. an algorithm for making a peanut butter sandwich b. an algorithm of how to determine the average of a bunch of test scores c. an algorithm to determine which card is missing from a deck of 51 cards d. an algorithm how to drive from Willowbrook Mall to WPU. Can your car understand these directions? Does it think? You translate these directions into a sequence of a. turning the key b. pressing on the gas pedal c. pressing on the brake pedal d. turning the steering wheel These are translated by the inner workings on the car to Applying brake pads, turning axles, causing pistons to turn, causing sparkplugs to operate Similarly, we can described algorithms like “averaging” 10 grades using short, English like statements, called pseudo code. a. b. c. d. Read in 10 grades Compute the sum of the 10 grades The average is the sum divided by 10 Print out the average. Some people prefer to describe their algorithms using flowcharts, a description that uses specifically defined graphical symbols as in: start Set sum to zero Read grade Add grade to sum 10 grades read yet Average is sum/10; print it end Flowchart for eating pizza. start Eat slice Any slices left? Put pizza box in garbage end Still hungry Put leftover slices in refrigerator But just as a car might not respond to “go right”, a computer must be addressed in a way it can handle. A programming language is a set of instructions, data, and rules that can be used to construct a program. The averaging pseudo code or flow chart might be written in the C++ programming language as sum=0.0; counter=1; while(counter<=10) { cin >>grade; sum =sum+grade; //add grade to sum counter=counter+1; //add 1 to counter } average = sum/10; cout << “the average is “ << average; But like the car, where a turn of the steering wheel really turns the tires, the computer needs this higher level language to be translated into “machine code”, a sequence of 1’s and 0’s, indicating current flowing and not flowing in various locations of the computer. The translating program is called the “compiler”. Compilers translate a sequence of instructions written in a higher level language or source code, like C++, into machine language or object code. Pseudo code -> higher level language -> machine language The C++ statement: If (income <10000) tax= .03*income Might be compiled into several machine language statements that look like 0110000100011010 0100000100001110 1101010101010100 1011101101010001 Higher level language like C++ English like commands, arabic numbers Machine independent One statement Less efficient because cannot take advantage of architecture Symbolic locations Machine language Composed of 0’s and 1’s Specific to machine Different for IBM, Apple Many statements More efficient Specific numbered locations Compilers translate a whole higher level language program (many statements)to object code, that is then “executed” An interpreter translates one source statement at a time into executable statements. Each statement is executed immediately after translation. good for finding errors, object code tends to be less efficient. Ex. Basic As English has syntax (grammar and spelling)rules and semantic(meaning) rules, so do programming languages. In English it is grammatically incorrect to write The student eat a apple? and it does not make much sense to write The house eats the moon. Each programming language has its own set of rules. The statement in C++ sum= sum+grade; is grammatically correct, but the following are incorrect: sum+grade =sum; sum= sum+ grade (missing the semicolon) In PASCAL we would write sum:= sum +grade; All programming languages have ways of Reading data Writing results Assigning expressions to variables Asking questions and selecting results Looping when the terminating condition is known beforehand Looping when the terminating condition is not known beforehand Doing arithmetic Dividing a big problem into smaller subproblems using a procedure, a logically consistent set of instructions that produces a specific result. But they might have slightly different ways of expressing these concepts. Until the last decade , most languages were procedure orientedinterested in implementing algorithms. Emphasis was on how something was done how well it was done. Possibly because of a large amount of graphics programming, languages have become object oriented If you do graphical text processing as I did when making the flow charts, one is given a set of objects- like diamonds, rectangles, ovals, arrows a set of operations-putting in text, increasing their size, rotating the object, moving the object. In object-oriented programs, these general shapes and procedural characteristics are examples of classes, and each instance is an object. The procedures contained within an object are called member functions or methods. C++ is an object oriented language that grew out of C, a procedure oriented language. In CS 230 we will essentially confine ourselves to the parts of C++ that are found in C. In CS240, the object oriented part will be introduced.