Full Transcript

ICDT 1201Y (3) Computer Programming (week 1) ICDT 1201Y Computer Programming 0 Introduction to Computers & Programming ICDT 1201Y Computer Programming 1 Sub-topics Computer Model Computer Programs Translation ICDT 1201Y Computer Programming 2...

ICDT 1201Y (3) Computer Programming (week 1) ICDT 1201Y Computer Programming 0 Introduction to Computers & Programming ICDT 1201Y Computer Programming 1 Sub-topics Computer Model Computer Programs Translation ICDT 1201Y Computer Programming 2 Learning Outcomes & Assessment Criteria Learning Outcomes: Assessment Criteria: Understand the basic components of a computer system: ○ Students should be able to identify and explain the main Recognition of Computer Components: components of a computer system (CPU, memory, ○ Ability to correctly identify the main storage, input/output devices) and their role and components of a computer system. function of each component in the execution of programs. ○ Describe the function and importance of each Explain what a computer program is: ○ Students should be able to define what a computer component in simple terms. Definition and Purpose of Programs: program is and explain how it is used to solve problems. ○ Understand the process of writing, compiling, and ○ Provide a clear definition of a computer running a program. program. Understand the concept of translation in programming: ○ Explain, in basic terms, how programs are used ○ Students should be able to distinguish between to solve problems. different types of translators (compilers, interpreters, assemblers). Explain the role of each type of translator Translation Process in Programming: in the execution of a program. ○ Distinguish between compilers, interpreters, and assemblers. ○ Explain how each translator works and their role in program execution. ICDT 1201Y Computer Programming 3 Ice-Breaking Exercise What’s your idea about software? Let’s talk about Computer Programming ○ Who are those with prior programming experience? ○ Programming Languages you have heard about? ○ Tips for mastering this module ICDT 1201Y Computer Programming 4 Computer – An Everyday Analogy Feed some fruits and veggies to the juicer. The juicer crushes and juices the Fruits & Veggies Finally the fresh and nice juice comes out Input->Process->Output ICDT 1201Y Computer Programming 5 What is a Computer A typical computer consists of Hardware (a CPU, memory, hard disk, input/output devices, and communication devices) and Software. CPU Output Devices Input devices Secondary Main memory memory ICDT 1201Y Computer Programming 6 Programs / Software Computer programs, known as software, are instructions to the computer. You tell a computer what to do through programs. Without programs, a computer is an empty machine. Computers do not understand human languages, so you need to use computer languages to communicate with them. ICDT 1201Y Computer Programming 7 Software Software are programs written to perform specific tasks Application programs perform a specific task for the user These programs include word processors, spreadsheets, and games (e.g. Microsoft Office, Google Chrome, Skype, WhatsApp, etc.) System programs take control of the computer, such as an Operating System (e.g.:Windows , Linux, MacOS, Android, etc.) Programs that support the execution and development of other programs Operating systems -> execute other programs Translation systems (Compilers and Interpreters)-> development of other programs ICDT 1201Y Computer Programming 8 Operating Systems The operating system (OS) is a program that manages and controls a computer’s activities. Windows is currently the most popular PC operating system. (Which OS are you using? What about your phones?) Application programs such as an Internet browser and a word processor cannot run without an operating system. ICDT 1201Y Computer Programming 9 What do Programs do? Programs instruct the computer to solve some specific problems What Problem Can Be Solved By Computer? (Discuss) o When the solution can be produced by a set of step-by-step procedures or actions. o This step-by-step action is called an algorithm. o The algorithm will process some inputs and produce some output. o Algorithms are implemented using programming languages. ICDT 1201Y Computer Programming 10 Programming Languages Natural language is fraught with ambiguity and imprecision ○ “I saw the man in the park with the telescope!” Computer scientists have gotten around this problem by designing notations for expressing computations in an exact, and unambiguous way. A set of special notations is called a programming language. ○ E.g. C, C++, Pascal, Visual Basic, Java, Python, … Every structure in a programming language has: ○ A precise form, its syntax ○ A precise meaning, its semantics In fact, programmers often refer to their programs as computer code. An algorithm is a finite sequence of effective statements, that when applied to the problem, will solve it. The process of writing an algorithm in a programming language is called coding. ICDT 1201Y Computer Programming 11 Types of Programming Languages Machine Language Programming languages Assembly Language High-Level Language Low level High level Are you familiar with any of the above? Machine Assembly language language ICDT 1201Y Computer Programming 12 Programming Languages – Machine Language Machine language is a set of primitive instructions built into every computer. The instructions are in the form of binary code, so you have to enter binary codes for various instructions. Programming with native machine language is a tedious process. Moreover the programs are highly difficult to read and modify. For example, to add two numbers, you might write an instruction in binary like this: 1101101010011010 ICDT 1201Y Computer Programming 13 Programming Languages – Assembly Language Assembly languages were developed to make programming ‘easy’. Since the computer cannot understand assembly language, however, a program called assembler is used to convert assembly language programs into machine code. For example, to add two numbers, you might write an instruction in assembly code like this: ICDT 1201Y Computer Programming 14 Programming Languages – High-Level Language The high-level languages are English-like and easy to learn and program. For example, the following is a high-level language statement that computes the area of a circle with radius 5: area = 5 * 5 * 3.1415 And of course, similar to Assembly Language, Computers do not understand High-Level Language. ICDT 1201Y Computer Programming 15 Popular High-Level Languages (1) Python: Known for its readability and simplicity, Python is widely used in web development, data science, artificial intelligence, and more. JavaScript: A core technology of the web, JavaScript is essential for front- end development and is increasingly used for back-end development with Node.js. Java: A versatile and platform-independent language used in web development, mobile apps (especially Android), and large-scale enterprise systems. PHP: A server-side scripting language used primarily in web development to create dynamic web pages. ICDT 1201Y Computer Programming 16 High Level Language to Machine Language Compiler A compiler is a complex computer program that takes another program written in a high-level language and translates it into an equivalent program in the machine language of some computer. The written high-level program is called source code. The resulting machine code is a program that the computer can directly execute. The black arrow in the diagram represents the execution of the machine code. ICDT 1201Y Computer Programming 17 High Level Language to Machine Language Source code (your Machine program) Compiler code Running Inputs Outputs program ICDT 1201Y Computer Programming 18 High Level Language to Machine Language Interpreter An interpreter is a program that simulates a computer that understands a high-level language. Rather than translating the source program into a machine language equivalent, the interpreter analyzes and executes the source code instruction by instruction as necessary. ICDT 1201Y Computer Programming 19 High Level Language to Machine Language Source code (your program) Computer running an Outputs Interpreter Inputs ICDT 1201Y Computer Programming 20 Writing Programs Learning to write programs requires two skills. 1. You need to develop a plan for solving a particular problem. This plan or algorithm is a sequence of steps that, when followed, will lead to a solution of the problem. 1. You need to use specific terminology and punctuation that can be understood by the machine; that is, you need to learn a programming language. ICDT 1201Y Computer Programming 21 Planning your solution Identify a problem Break the problem into simpler problems Describe the steps to be taken to solve the simpler problems ○ Can start with flowcharts ○ Or Textual description (PseudoCodes) ICDT 1201Y Computer Programming 22 Pseudocode and Flowchart Example https://www.youtube.com/watch?app=desktop&v=vOEN65nm4YU ICDT 1201Y Computer Programming 23 Setting up Depending on your Operating System, watch the corresponding YouTube Video and setup the environment for Python Development. Windows https://www.youtube.com/watch?v=ou ANCqLtr98 Linux https://www.youtube.com/watch?v=6u swHeYXIBo MacOS https://www.youtube.com/watch?v=Ni rAuEAblvo ICDT 1201Y Computer Programming 24 Testing your setup The traditional way: You write a piece of code to display the text “Hello World” on screen. Create a file named myfirst.py and type the following codes: print("Hello, my name is John Smith") Feel free to modify the text as you wish Execute your code by clicking on ICDT 1201Y Computer Programming 25 Lab Exercise Using your knowledge of the print() on the previous slide, recreate the drawing using python: ICDT 1201Y Computer Programming 26 Acknowledgements Slides adapted from: Dr P.Appavoo’s slides & ICDT 1201Y Computer Programming 27

Use Quizgecko on...
Browser
Browser