Computer Programming Basics and Language Overview

king saud university college of applied studies l.w
1 / 22
Embed
Share

Explore the fundamentals of computer programming, including the definition of a computer, its organization, and the types of programming languages. Learn about machine languages, assembly languages, and high-level languages, as well as the role of translators and compilers in converting code. Understand the significance of different language levels and how they interact with computer systems.

  • Programming Basics
  • Computer Languages
  • Machine Language
  • High-Level Language
  • Language Overview

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel CHAPTER 1 INTRODUCTION 2ndSemester 1432-1433 H

  2. What Is a Computer? 2 Computer Executes statements (computations/logical decisions) Hardware :Physical devices of computer system Software: Programs that run on computers Central Processing Unit Control Unit Input device Output Device Arithmetic/Logic Unit My Progam Memory Unit My data Asma Alosaimi

  3. Computer Organization 3 Six logical units of computer system Input unit Mouse, keyboard Output unit Printer, monitor, audio speakers Memory unit Retains input and processed information Arithmetic and logic unit (ALU) Performs calculations Control unit Supervises operation of other devices Secondary storage unit Hard drives, floppy drives Asma Alosaimi

  4. What a computer program is? 4 For a computer to be able to perform specific tasks (i.e. print what grade a student got on an exam), it must be given instructions to do the task. The set of instructions that tells the computer to perform specific tasks is known as a computer program Asma Alosaimi

  5. Machine Languages, Assembly Languages and High-Level Languages Machine language Natural language of computer component Machine dependent Assembly language English-like abbreviations represent computer operations Translator programs convert to machine language High-level language Allows for writing more English-like instructions Contains commonly used mathematical operations Compiler convert to machine language

  6. An Overview Of Computer Languages 6 1-Machine language 2-Assembly language 3-High-level language Collection of binary numbers Symbolic machine language (I.e. symbolic names are used to represent operations, & memory locations) form of combines algebraic expressions with symbols taken from English language(ex. C, Pascal, FORTRAN, etc) representation registers 10100001 00000000 00000000 00000101 00000100 00000000 10100011 00000000 00000000 examples MOV AX,A MOV A , AX ADD AX, A=A+4 *c Assembler convert to machine language Directly understood by a computer Compiler or (interpter ) convert to machine language how does the computer understand ? Easier to use Asma Alosaimi More powerful

  7. Levels of Program Development 7 Human thought Pseudo-Natural Language (English, Arabic) High Level Programming Language (C, C++, Java, ) Machine Code Asma Alosaimi

  8. The Programmers Algorithm 8 An algorithm is a finite sequence of instructions that produces a solution to a problem. The programmer s algorithm: Define the problem. Plan the problem solution. Code the program. Compile the program. Run the program. Test and debug the program. Asma Alosaimi

  9. 91-Defining the Problem The problem must be defined in terms of: Input: Data to be processed. Output: The expected result. Look for nouns in the problem statement that suggest output and input. and processing: The statements to achieve. Look for verbs to suggest processing steps. output data input data Processing Keyboard Screen

  10. Input and Output 10 Inputs Can come from many sources, such as users, files, and other programs Can take on many forms, such as text, graphics, and sound Outputs Can also take on many forms, such as numbers, text, graphics, sounds, or commands to other programs Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP

  11. Example 1 Area and Perimeter of a rectangle 11 Input Length width Processing Area = length*width Perimeter = 2*( length + width) Output Area Perimeter Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP

  12. Example 2 Sum and Average of 5 numbers Page 12 Input five number x1, x2, x3, x4, x5 Processing Sum = x1+x2+x3+x4+x5 Average = Sum/5 Output Sum Average Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP

  13. Example 3 Area and Perimeter of a circle Page 13 Input Radius PI Processing Area = PI * Radius * Radius Perimeter = 2 * PI * Radius Output Area Perimeter Dr. S. GANNOUNI & Dr. A. TOUIR Introduction to OOP

  14. 2-Planning the Solution 14 When planning, algorithms are used to outline the solution steps using English like statements, called pseudocode. A flowchart is useful for the graphical representation of an algorithm. They are drawn using rectangles, diamonds, ovals, and small circles. Asma Alosaimi

  15. Write a Program to Print the Sum of two integer Numbers 15 start Start the program Read the first number and save in the variable ( N1 ) Read the second number and save in the variable ( N2 ) Sum the both numbers and save the result in the variable ( Sum ) Sum = N1 + N2 Print the variable ( Sum ) End the program 1. 2. Read N1 3. Read N2 4. Sum = N1 + N2 5. Print Sum 6. End Asma Alosaimi

  16. 3-Coding the Program 16 Coding is writing the program in a formal language called Programming Language. Programming Language : A set of rules, symbols and special words used to write statements. The program is written by translating the algorithm steps into a programming language statements. The written program is called Source code and it is saved in a file with .cpp extension. Algorithm Pseudocode Translating Coding Program Source Code (The .cpp ) Asma Alosaimi

  17. Why Coding in Programming Languages 17 We write computer programs (i.e. a set of instructions) in programming languages such as C, C++, and Java. We use these programming languages because they are easily understood by humans But then how does the computer understand the instructions that we write? Asma Alosaimi

  18. 4-Compiling Computer Programs 18 Computers do not understand programs written in programming languages such as C, C++ and Java Programs must first be convertedintomachine code that the computer can run A Software that translates a programming language statements into machine code is called a compiler In C , Preprocessorprogram, execute automatically before the compiler translation phase begin Preprocessorindicate that certain manipulations are to be performed on the program before compilation. Program Source code Compiling Translating Machine code Machine Code Asma Alosaimi

  19. Programming Language Compiler 19 A compiler is a software that: Checks the correctness of the source code according to the language rules. Syntax errors are raised if some rules were violated. Translates the source code into a machine code if no errors were found. Asma Alosaimi

  20. 5-Running The Program 20 Before running.. links the object code with the code for the missing functions to produce an executable image (with no missing pieces) , this is called link phase . If the program compiles and links correctly, a file called a.out is produced. Before a program can be executed, the program must first be placed in memory this called load phase . the computer, under the control of its CPU, executes the program one instruction at a time Asma Alosaimi

  21. 6-Testing and Debugging the Program 21 Testing Be sure that the output of the program conforms with the input. There are two types of errors: Logical Errors: The program run but provides wrong output. Runtime errors: The program stop running suddenly when asking the OS executing a non accepted statement (divide by zero, etc). Debugging Find, Understand and correct the error Asma Alosaimi

  22. Basics of a Typical C++ Environment Program is created in the editor and stored on disk. Editor Disk Preprocessor program processes the code. Phases of C++ Programs: 1. Edit 2. Preprocess 3. Compile 4. Link 5. Load 6. Execute Preprocessor Disk Compiler creates object code and stores it on disk. Compiler Disk Linker links the object code with the libraries, creates a.out and stores it on disk Linker Disk Primary Memory Loader Loader puts program in memory. Disk . . . . . . Primary Memory CPU CPU takes each instruction and executes it, possibly storing new data values as the program executes. . . . . . . 22

More Related Content