Unformatted text preview:

Computer- a 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 instructionsthat is used to operate a computerHardware: the computer’s physical componentsFor input- keyboard, mouseFor processing- CPU, motherboard, random access memoryFor output-monitor, speakers, printersFor storage -floppy disks, CDRW’s, hard driveSoftware- 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 proceduresto perform a specific task, essentially a recipea. an algorithm for making a peanut butter sandwichb. an algorithm of how to determine the average of a bunch of test scoresc. an algorithm to determine which card is missing from a deck of 51 cardsd. 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 ofa. turning the keyb. pressing on the gas pedalc. pressing on the brake pedald. turning the steering wheel These are translated by the inner workings on the car toApplying brake pads, turning axles, causing pistons to turn,causing sparkplugs to operateSimilarly, we can described algorithms like “averaging” 10 grades using short, English like statements, called pseudo code.a. Read in 10 gradesb. Compute the sum of the 10 gradesc. The average is the sum divided by 10d. Print out the average.Some people prefer to describe their algorithms using flowcharts, a description that uses specifically defined graphical symbols as in:Read gradeAdd grade to sumSet sum to zeroAverage is sum/10; print it10 grades read yetendstartFlowchart for eating pizza. Eat slicePut pizza box in garbagePut leftover slices in refrigeratorAny slices left?Still hungryendstartBut 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 assum=0.0;counter=1;while(counter<=10){cin >>grade;sum =sum+grade; //add grade to sumcounter=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 invarious 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 languageThe C++ statement:If (income <10000) tax= .03*incomeMight be compiled into several machine language statements that look like0110000100011010010000010000111011010101010101001011101101010001Higher level language like C++ Machine languageEnglish like commands, arabic numbersComposed of 0’s and 1’sMachine independent Specific to machineDifferent for IBM, AppleOne statement Many statementsLess efficient because cannottake advantage of architectureMore efficientSymbolic locations Specific numbered locationsCompilers 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 intoexecutable statements. Each statement is executed immediately after translation.good for finding errors, object code tends to be less efficient.Ex. BasicAs English has syntax (grammar and spelling)rules and semantic(meaning) rules, so do programming languages.In English it is grammatically incorrect to writeThe 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 writesum:= sum +grade;All programming languages have ways ofReading dataWriting resultsAssigning expressions to variablesAsking questions and selecting resultsLooping when the terminating condition is known beforehandLooping when the terminating condition is not known beforehandDoing arithmeticDividing 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 oriented- interested in implementing algorithms. Emphasis was on how something was donehow well it was done.Possibly because of a large amount of graphics programming, languages have become object orientedIf you do graphical text processing as I did when making the flow charts, one is given a set of objects- like diamonds, rectangles, ovals, arrowsa 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 eachinstance 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 theparts of C++ that are found in C.In CS240, the object oriented part will be


View Full Document

WPU CS 2300 - CS 2300 LECTURE NOTES

Download CS 2300 LECTURE NOTES
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view CS 2300 LECTURE NOTES and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view CS 2300 LECTURE NOTES 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?