Full Transcript

ITE 12 Fundamental of Problem Solving and Programming Overview of Computer Programming and Problem Solving TOPICS 1 BASIC COMPUTER CONCEPTS COMPUTERS AND PROGRAMMING A computer is just a machine (the hardware) for executing programs (the software) Hence, the software rules th...

ITE 12 Fundamental of Problem Solving and Programming Overview of Computer Programming and Problem Solving TOPICS 1 BASIC COMPUTER CONCEPTS COMPUTERS AND PROGRAMMING A computer is just a machine (the hardware) for executing programs (the software) Hence, the software rules the hardware! The process of creating software is called programming, and it is the focus of this course Virtually, anyone can learn how to program computers It requires only some grit! WHY LEARN PROGRAMMING? Computers have become commonplace in our modern life Ubiquitous Astronomy Computing Smaller, Faster, Cheaper Sensors Gene Sequencing and Biotechnology WHY LEARN PROGRAMMING? Computers have become commonplace in our modern life Applying ideas in different fields requires programming Programming can be loads of fun! It is an intellectually engaging activity that allows you to express yourself through remarkably beautiful constructs and structures Programming develops valuable problem-solving skills, especially ones that pertain to analysis, design and implementation Programmers are in great demand! HARDWARE BASICS To be a successful programmer, you need to know some details of how computers work For instance, understanding the basics of hardware will help you analyze the performance (or efficiency) of any of your programs Will the data of your program fit in memory? If not, how would that impact the performance of your program? Is your program CPU-bound or IO-Bound? If CPU-bound, how powerful is your CPU? If IO-bound, how big is your disk or network bandwidth? FUNCTIONAL VIEW OF A COMPUTER Output CPU Devices Input Devices Main Secondary Memory Memory FUNCTIONAL VIEW OF A COMPUTER The secondary memory is where your saved program and data reside It is a non-volatile storage E.g., Hard Disk I.e., when the power is turned off, your program and data will NOT be lost Secondary Memory FUNCTIONAL VIEW OF A COMPUTER The main memory is much faster (but more expensive) than the secondary one, however, it is volatile Your program and data are copied from secondary memory to main memory for efficiency reasons E.g., Random Access Memory (RAM) Main Secondary Memory Memory FUNCTIONAL VIEW OF A COMPUTER The Central Processing Unit (CPU) is the “brain” of the computer It can at least perform: Arithmetic operations CPU (e.g., adding 2 numbers) Logical operations (e.g., test if 2 numbers are equal) Main Secondary Memory Memory It can directly access information stored in main memory but not in secondary memory FUNCTIONAL VIEW OF A COMPUTER E.g., Monitor E.g., Keyboard Output and mouse CPU Devices Input Devices Main Secondary Memory Memory FUNCTIONAL VIEW OF A COMPUTER ▪ Humans interact with computers via Input and Output (IO) E.g., Monitor devices E.g., Keyboard Output and mouse Devices ▪ Information from Input devices Input are processed by the CPU and Devices may be shuffled off to the main or secondary memory ▪ When information need to be displayed, the CPU sends them to one or more Output devices Programming Languages A program is just a sequence of instructions telling the computer what to do Obviously, we need to provide these instructions in a language that computers can understand We refer to this kind of a language as a programming language Python, Java, C and C++ are examples of programming languages Every structure in a programming language has an exact form (i.e., syntax) and a precise meaning (i.e., semantic) MACHINE LANGUAGES Python, Java, C, and C++ are, indeed, examples of high-level languages Strictly speaking, computer hardware can only understand a very low-level language known as machine language If you want a computer to add two numbers, the instructions that the CPU will carry out might be something like this: Load the number from memory location 2001 into the CPU Load the number from memory location 2002 into the CPU Add the two numbers in the CPU A Lot of Store the result into location 2003 Work! HIGH-LEVEL TO LOW-LEVEL LANGUAGES In a high-level language like Python, the addition of two numbers can be expressed more naturally: c=a+b Much Easier! But, we need a way to translate the high-level language into a machine language that a computer can execute To this end, high-level language can either be compiled or interpreted 18 MACHINE LANGUAGES, ASSEMBLY LANGUAGES, AND HIGH-LEVEL LANGUAGES THREE TYPES OF PROGRAMMING LANGUAGES 1. Machine languages Strings of numbers giving machine specific instructions Example: +1300042774 +1400593419 +1200274027 2. Assembly languages English-like abbreviations representing elementary computer operations (translated via assemblers) Example: LOAD BASEPAY ADD OVERPAY STORE GROSSPAY 19 MACHINE LANGUAGES, ASSEMBLY LANGUAGES, AND HIGH-LEVEL LANGUAGES 3. High-level languages Codes similar to everyday English Use mathematical notations (translated via compilers) Example: grossPay = basePay + overTimePay AN OVERVIEW OF COMPUTER LANGUAGES Machine and assembly languages Algorithmic languages (Fortran, Algol, C) Business Oriented Languages (Cobol, SQL) Object Oriented Languages ( C++, C#, Ada, Java, Visual Basic, Python) Declarative Languages (Prolog, Lisp) Scripting languages (PERL) Document Formatting Languages (Tex, PostScript, SGML) WWW Display Languages (HTML, XML) Web Scripting (Java Script) History of C C – Evolved by Ritchie from two previous programming languages, BCPL and B – Used to develop UNIX – Used to write modern operating systems – Hardware independent (portable) – By late 1970's C had evolved to "Traditional C" 22 The C Standard Library C programs consist of pieces/modules called functions – A programmer can create his own functions Advantage: the programmer knows exactly how it works Disadvantage: time consuming – Programmers will often use the C library functions Use these as building blocks – Avoid re-inventing the wheel If a premade function exists, generally best to use it rather than write your own Library functions carefully written, efficient, and portable 26 Other High-level Languages Other high-level languages – FORTRAN Used for scientific and engineering applications – COBOL Used to manipulate large amounts of data – Pascal Intended for academic use COMPILING A HIGH-LEVEL LANGUAGE A compiler is a complex software that takes a program written in a high-level language and translates it into an equivalent program in the machine language of some computer Source Code Machine Compiler (Program) Code Running Inputs Outputs Program INTERPRETING A HIGH-LEVEL LANGUAGE An interpreter is a software that analyzes and executes the source code instruction-by-instruction (on-the-fly) as necessary Source Code (Program) Computer Running An Outputs Interpreter Inputs E.g., Python is an interpreted language COMPILING VS. INTERPRETING Compiling is a static (i.e., pre-execution), one-shot translation Once a program is compiled, it may be run over and over again without further need for the compiler or the source code Interpreting is dynamic (i.e., happens during execution) The interpreter and the source code are needed every time the program runs Compiled programs tend to be faster, while interpreted ones lend themselves to a more flexible programming environments (they can be developed and run interactively) SUMMARY A computer is a universal information-processing machine, which can carry out any process that can be described in sufficient detail A description of the sequence of steps for solving a particular problem is called an algorithm Algorithms can be turned into software (programs) that determine what the hardware (physical machine) can and does accomplish The process of creating software is called programming SUMMARY A basic functional view of a computer system comprises a central processing unit (CPU), a main memory, a secondary memory, and input and output devices The CPU is the brain of the computer that performs simple arithmetic and logical operations Information that the CPU acts on (data and programs) are stored in main memory (e.g., RAM), while more permanent information are stored in secondary memory (e.g., disk) SUMMARY Programs are written using a formal notation known as a programming language There are many different languages, but all share the property of having a precise syntax (form) and semantics (meaning) Computer hardware only understands a very low-level language known as machine language Programs are usually written using human-oriented high-level languages such as Python SUMMARY A high-level language must either be compiled or interpreted in order for the computer to understand it High-level languages are more portable than machine languages Thank you for Listening! PREPARED BY: MARY ROSE RAZ

Use Quizgecko on...
Browser
Browser