Chapter-1-Introductory-Concepts-to-Computer-Programming.pdf
Document Details
Uploaded by Deleted User
Full Transcript
CC – 102: Fundamentals of Programming CHAPTER 1: INTRODUCTORY CONCEPTS TO COMPUTER PROGRAMMING Presented by: CHRISTIAN A. FAJARDO, MACE What is a computer program? A computer program, also known as...
CC – 102: Fundamentals of Programming CHAPTER 1: INTRODUCTORY CONCEPTS TO COMPUTER PROGRAMMING Presented by: CHRISTIAN A. FAJARDO, MACE What is a computer program? A computer program, also known as software or an application, is a set of instructions written in a programming language. It is designed to perform specific tasks or operations when executed by a computer. Computer programs can be simple or complex, ranging from a basic calculator program to sophisticated software applications used for various purposes, such as word processing, web browsing, gaming, or data analysis. Programs enable computers to carry out specific functions and provide users with the ability to interact with computers in a meaningful way. What is programming? Programming is the process of creating computer programs or sets of instructions that tell a computer how to perform specific tasks. It involves writing code using programming languages such as Java, Python, C++, or JavaScript to create software applications, websites, or other computer-based systems. Programming requires logic, problem – solving skills, and attention to detail to develop efficient and functional programs. What is a programming language? A programming language is a prescribed language used to write instructions or algorithms for a computer to perform specific tasks. It is a set of rules and syntax that allows programmers to communicate with a computer and give it commands. Different programming languages have different purposes and features, and they can be categorized into low – level languages (such as assembly language) and high – level languages (such as C++, Java, or Python). Programming vs. Programming Language (visualization) Programming Program written on a programming language How does a computer program work? Generally, a computer program works by executing a sequence of instructions written in a programming language. The following are the process as how a computer program works: 1. Writing the Program 2. Code Translation 3. Execution 4. Input and Output 5. Control Flow 6. Memory Management 7. Termination Overall, a computer program follows these steps to carry out its intended tasks through the instructions provided by the programmer. Low – Level PLs vs. High – Level PLs The main difference between low – level programming language with high – level programming language lies primarily on their level of abstraction. Abstraction is a concept in computer science and software engineering that refers to the process of simplifying complex systems or ideas by focusing on the essential features or properties, while hiding or ignoring irrelevant details. Low – Level PLs vs. High – Level PLs Low – level programming languages are closer to machine code and are generally specific to particular architectures. They provide a minimal abstraction from the hardware, allowing direct control over computer hardware resources. These languages are harder to read and write, but they offer excellent performance and efficiency. Examples: Assembly Language, Machine Language High – level programming languages are designed to be closer to human language and are less dependent on specific hardware architectures. They provide a higher level of abstraction by utilizing complex syntax, data structures, and libraries. High – level PLs are generally easier to read, write, and understand, making them more user – friendly. They prioritize developer productivity and maintainability over low – level performance. Examples: C++, Java, Python Low – Level PLs vs. High – Level PLs In summary, “low – level PLs offer fine – grained control over hardware but have a steeper learning curve, while high – level PLs focus on ease of use and productivity at the expense of some performance control.” Low – Level PLs vs. High – Level PLs (visualization) Low – Level PLs vs. High – Level PLs (comparison) What is a Translator? Any program written in a programming language is known as a source code. However, computers cannot understand a source code written on high – level PLs. Before it can be run into a program, it must first be translated into a form which a computer understands. A translator is a program that basically converts source code into machine code. Types of Translators An Interpreter is a type of translator that translates each statement in a high – level source program and executes it immediately upon translation. Python, JavaScript, Ruby, Perl, PHP, and Lua are some of the programming languages that are uses interpreter – based translators. Types of Translators A Compiler on the other hand, translates a high – level source program as a complete unit and stores it in an executable file before any statement is executed. C, C++, Java, Fortran, Ada and Go are programming languages that uses compiler – based translators. Interpreters vs. Compilers (visualization) Types of Errors in Programming To understand the errors programmers commit in writing programs, there are three basic steps during programming: ✓ Write or Edit the program ✓ Compile the program ✓ Execute the program In some instances though, programmers may commit a mistake, or error at some point along the way in making programs. These errors may fall in either one of the following categories: Types of Errors in Programming Syntax Errors – It occurs when the programmer violate the rules of the language (simply known as a syntax), no matter how minor. Run – time Errors – It occurs when the programmer ask the computer to do something it considers to be illegal. such as dividing by zero. Logic Errors – It occurs when the programmer fails to express themselves correctly or they don’t understand the whole logic on how the program should work and what it should does. What is an Algorithm? It is a finite set of instructions that specify a sequence of operations to be carried out in order to solve a specific problem or class of problems. Can be also defined as a step–by–step sequence of instructions that must terminate and describes how to perform an operation to produce a desired output When English phrases are used to describe an algorithm, the description is called a pseudocode. Algorithm Example Calculating the average of three numbers: ✓ Input the three numbers into the computer. ✓ Calculate the average by adding the numbers and dividing the sum by three ✓ Display the average Pseudocode Example Calculating the average of three numbers: start input Number1 input Number2 input Number3 set average = (Number1 + Number2 + Number3) / 3 output average stop What is an Flowchart? It uses symbols with phrases to designate the logic of how a problem is solved. A common method for defining the logical steps of flow within a program by using a series of symbols to identify the basic Input, Process and Output (IPO’s) function within a program. A diagram representing the logical sequence in which a combination of steps or operations is to be performed. It is a blueprint of the program. Flowchart Example Calculating the average of three numbers CC – 102: Fundamentals of Programming END of CHAPTER 1: INTRODUCTORY CONCEPTS TO COMPUTER PROGRAMMING Presented by: CHRISTIAN A. FAJARDO, MACE