Programming 1 - Honors - Florida State University

Transcription

Programming 1 - HonorsLecture 1COP 3014 Spring 2017January 10, 2017

Main Components of a computerICPU - Central Processing Unit: The “brain” of the computer.IIIALU - Arithmetic & Logic Unit responsible for performingarithmetic calculations, as well as logical operations(comparisons for equality, inequality, for instance).Main Memory (RAM - Random Access Memory).IIIIISA - Instruction Set Architecture: the specific set of low-levelinstructions available to a CPU. Differs for various CPU types(Intel Pentium, Mac G4, etc).storage close to CPUFaster to access than hard diskstores executing programs and data being currently worked onSecondary MemoryIhard disk, floppy disk, CD, DVD, etc.

Main Components of a computerIInput devicesIIOutput devicesIImouse, keyboard, scanner, network card, etc.screen/console, printer, network card, etc.Operating SystemIIIExamples: Mac OS, Windows XP, LinuxControls computer operationsManages allocation of resources for currently runningapplications

Memory ConceptsIbit: a binary digitIIIStores the value 0 or 1Smallest unit of storage in a computerbyte: 8 bitsIIISmallest addressable unit of storage in a computerStorage units (variables) in a program are 1 or more bytesEach byte in memory has an address (a number that identifiesthe location)

Programming, and Programming LanguagesProgram - a set of instructions for a computer to executeEvolution of Programming languagesI Machine LanguageIIIBased on machine’s core instruction setNeeded by computer, hard for humans to read (1’s and 0’s)Example: 1110110101010110001101010

Programming, and Programming LanguagesIAssembly LanguageIItranslation of machine instructions to symbols, slightly easierfor humans to readExample: ADD R1, R2, R3

Programming, and Programming LanguagesIHigh-level procedural languagesIIIIIAbstraction of concepts into more human-readable termsCloser to ”natural language” (i.e. what we speak)Easy to write and design, but must be translated for computerExamples include C, Pascal, FortranObject-oriented languagesIIIIAbstraction taken farther than procedural languagesObjects model real-world objects, not only storing data(attributes), but having inherent behaviors (operations,functions)Easier to design and write good, portable, maintainable codeExamples include Smalltalk, C , Java

Code TranslationBridging the gap between high-level code and machine codeIIInterpreted languages – source code is directly run on aninterpreter, a program that runs the code statementsCompiled LanguagesIIIA compiler program translates source code (what theprogrammer writes) to machine language (object code)A linker program puts various object code files together into anexecutable program (or other target type, like a DLL)C and C are compiled languages

Software DevelopmentInvolves more than just writing code

Software DevelopmentIAnalysis and problem definitionIDesign - includes design of program or system structure,algorithms, user-interfaces, and moreIImplementation (coding)ITesting - can be done during design, during implementation,and after implementationIMaintenance - usually the major cost of a software system.Not part of ”development”, but definitely part of the softwarelife cycle

Programming is about Problem SolvingIAlgorithm - a finite sequence of steps to perform a specifictaskIIITo solve a problem, you have to come up with the necessarystep-by-step process before you can code itThis is often the trickiest part of programmingSome useful tools and techniques for formulating an algorithmIIITop-down Refinement: Decomposing a task into smaller andsimpler steps, then breaking down each step into smaller steps,etcPseudocode: Writing algorithms informally in a mixture ofnatural language and general types of code statementsFlowcharting: If you can visualize it, it’s often easier to followand understand!

Programming is about Problem SolvingITesting - algorithms must also be tested!IIIDoes it do what is required?Does it handle all possible situations?Syntax vs. SemanticsIISyntax – the grammar of a language.A syntax error: ”I is a programmer.”Semantics – the meaning of language constructsCorrect syntax, but a semantic error: ”The headphones ate thetree.”

Basic Creation and Execution of a C programICreate source code with a text editor, store to disk.IIIPreprocessor – Part of compiler process, performs anypre-processing tasks on source code.Compilation – syntax checking, creation of object code.IIISource code is just a plain text file, usually given a filenameextension to identify the programming language (like .c for C,or .cpp for C )Object code is the machine code translation of the source code.Linking – Final stage of the creation of an executableprogram. Linking of object code files together with anynecessary libraries (also already compiled).Execution of programIIProgram loaded into memory, usually RAMCPU executes code instructions

Software Required for the ClassIA text editor compatible with C . There are several freetext editors.IIIIIWe will be using Notepad in class.Sublime (available for Windows and Macs).Atom.Vim/Emacs for Linux.A File Transfer ClientIIPutty, BitVise or SSH Client for Windows.Cyberduck or Filezilla for Macs.IYou can also use IDE’s like Visual Studio or XCode. However,if you do so, you still have to test your code on linprogbefore turning it in.IAn account on the CS department programming servers.

Programming, and Programming Languages I High-level procedural languages I Abstraction of concepts into more human-readable terms I Closer to "natural language" (i.e. what we speak) I Easy to write and design, but must be translated for computer I Examples include C, Pascal, Fortran I Object-oriented languages I Abstraction taken farther than procedural languages