TOPIC 1. Overview of Computer Programming and Problem Solving.pdf

Full Transcript

ITE 12. - Fundamentals of Programming INT RODUCTION Topic 1. Overview of Computer Programming and Problem Solving a. Basic computer concepts b. An overview of Computer Languages c. History of C Programming Language d. The software/programming development method...

ITE 12. - Fundamentals of Programming INT RODUCTION Topic 1. Overview of Computer Programming and Problem Solving a. Basic computer concepts b. An overview of Computer Languages c. History of C Programming Language d. The software/programming development method e. Flowcharting and psuedo-coding f. Designing Algorithm g. Introduction to C Programming ITE 12 – FUNDAMENTALS OF PROGRAMMING Learning Objectives 1. Identify the basic computer concepts 2. Describe the differences of computer languages 3. Apply software/programming development method in solving programming problems with flowcharts and algorithm 4. Convert mathematical formula into algorithms and flowcharts 5. Trace errors and program flow ITE 12 – FUNDAMENTALS OF PROGRAMMING Basic Computer Concepts ITE 12 – FUNDAMENTALS OF PROGRAMMING Computer ▪ A programmable device ▪ Operates under the instructions stored in its memory ▪ Accepts data, processes the data, display and/or store results. ITE 12 – FUNDAMENTALS OF PROGRAMMING Data vs Information ▪ Data o raw items o not really useful, meaningless ▪ Information o processed data ▪Computers process data and turn it into information ITE 12 – FUNDAMENTALS OF PROGRAMMING Advantage of Computers ▪ Speed - Computers process information and perform calculations much faster than humans. They can handle complex tasks and manage large volumes of data quickly and efficiently. ▪ Reliability - The electronic components in modern computers are dependable and reliable because they rarely break or fail. ▪ Consistency- Given the same input and processes, a computer will produce the same results — consistently. Computers generate error-free results, provided the input is correct and the instructions work. ▪ Storage - Computers store enormous amounts of data and make this data available for processing anytime it is needed ▪ Communication - Most computers today can communicate with other computers, often wirelessly. Computers allow users to communicate with one another. ITE 12 – FUNDAMENTALS OF PROGRAMMING Disadvantage of Computers ▪ Violation of Privacy - In many instances, where personal and confidential records stored on computers were not protected properly, individuals have found their privacy violated and identities stolen. ▪ Public Safety - People of all ages are sharing personal details online, including photos, videos, and written content. Unfortunately, some of these people have become targets of crime by dangerous individuals. ▪ Impact on Labor Force - Technology has created new jobs but also job losses. Workers must continually upgrade skills to remain competitive. Additionally, job outsourcing is impacting domestic employment. ▪ Health Risks - Prolonged or improper computer use can lead to health injuries or disorders. ▪ Environmental Impact - Computer manufacturing processes and computer waste are depleting natural resources and polluting the environment ITE 12 – FUNDAMENTALS OF PROGRAMMING Von Neumann Architecture ITE 12 – FUNDAMENTALS OF PROGRAMMING Major Components of a Computer 1. Hardware 2. Software 3. Peopleware 4. Dataware 5. Procedure ITE 12 – FUNDAMENTALS OF PROGRAMMING Major Components of a Computer ▪ Hardware o tangible o input / output, storage, system unit, communication devices ITE 12 – FUNDAMENTALS OF PROGRAMMING Hardware Components o Input Devices ▪ allow the user to enter data o Examples: ▪ Mouse, keyboard, touchpad, microphones, cameras ITE 12 – FUNDAMENTALS OF PROGRAMMING Hardware Components o Output Devices ▪ convey / display information in a human readable form. o Examples: ▪ Monitor, printer, speakers ITE 12 – FUNDAMENTALS OF PROGRAMMING Hardware Components o Storage Devices (Memory) ▪ Used to store data and instructions for future use. ▪ Can hold information either permanently or temporarily. o Examples: ▪ Flash Drive, Hard Disk Drive, RAM, ROM ITE 12 – FUNDAMENTALS OF PROGRAMMING ❖ Anatomy of a Memory Memory Cell – an individual storage location in a memory Address – Position of a memory cell Contents – the information stored 1000 Memory Cells ITE 12 – FUNDAMENTALS OF PROGRAMMING ❖ Storage Devices 1. Primary Memory o holds programs and data that the processor is currently working. o stores data temporarily o Volatile memory o Ex. : RAM ITE 12 – FUNDAMENTALS OF PROGRAMMING ❖ Storage Devices 2. Secondary Memory o Holds programs and data for long term use. o Non – volatile o Ex. : HDD, ROM, FD, SD card, CD/DVD ITE 12 – FUNDAMENTALS OF PROGRAMMING Hardware Components o System Unit ▪ contains hardware components, including memory responsible for processing data e.g. motherboard, memory, etc. ▪ the case provides mechanical support and protection controls directs the flow of cooling air ITE 12 – FUNDAMENTALS OF PROGRAMMING ❖ System Unit 1. Motherboard ▪ main component ▪ an integrated circuitry that connects other components as well as peripherals through ports and expansion slots. ITE 12 – FUNDAMENTALS OF PROGRAMMING ❖ Motherboard - in it ! 1. Processor (Central Processing Unit) ▪ interprets and carries out the basic instructions that operate a computer. ITE 12 – FUNDAMENTALS OF PROGRAMMING ❖ Motherboard - in it ! 1. Processor (Central Processing Unit) ▪ Parts a) Control Unit – interprets instructions and direct actions b) Arithmetic and Logic Unit – perform calculations and comparisons c) Registers –temporary storage for data currently being processed ITE 12 – FUNDAMENTALS OF PROGRAMMING ❖ Motherboard - in it ! 1. Processor (Central Processing Unit) ▪ Machine Cycle 1. Fetch – fetch instruction from memory 2. Decode – decode instruction to signals 3. Execute – carry out the command 4. Store – write result to storage ITE 12 – FUNDAMENTALS OF PROGRAMMING ❖ Motherboard - in it ! 1. Processor (Central Processing Unit) ▪ System Clock ▪ Controls the timing of all operations ▪ Usually in Gigahertz ITE 12 – FUNDAMENTALS OF PROGRAMMING ❖ Motherboard - in it ! 2. Memory ▪ stores instructions waiting to be executed, the data needed, and the result ▪ Stores instructions, softwares, and user data ▪ Examples: RAM, ROM, HDD ITE 12 – FUNDAMENTALS OF PROGRAMMING ❖ Motherboard - in it ! 2. Memory ▪ RAM ▪ Random Access Memory ▪ A primary memory ▪ Contains programs currently being executed ITE 12 – FUNDAMENTALS OF PROGRAMMING ❖ Motherboard - in it ! 2. Memory ▪ ROM ▪ Read Only Memory ▪ Non-volatile ▪ Contains programs needed to start the computer ITE 12 – FUNDAMENTALS OF PROGRAMMING ❖ Motherboard - in it ! 2. Memory ▪ HDD ▪ Hard Disk Drive ▪ Non-volatile ▪ Stores system and application software as well as user data ITE 12 – FUNDAMENTALS OF PROGRAMMING ❖ Motherboard - in it ! 3. CMOS ▪ Complementary Metal Oxide Semiconductor ▪ Keeps data on date and time ▪ Uses battery ITE 12 – FUNDAMENTALS OF PROGRAMMING ❖ Motherboard - in it ! 3. Chipset ▪ Data Flow Management System ▪ Mediates between the CPU and other components Controls flow and timing of data and instruction ▪ Divided into 2: ▪ Southbridge – IO controller hub ▪ Northbridge – Memory Controller hub ITE 12 – FUNDAMENTALS OF PROGRAMMING ❖ Motherboard - in it ! 4. Buses ▪ Electrical channels that serve as path way for data and control signals ▪ Interconnects all the components in the motherboard ▪ Purpose: data sharing, addressing, power, timing ITE 12 – FUNDAMENTALS OF PROGRAMMING ❖ System Unit 2. Power Supply Unit ▪ Converts AC to DC power for the internal components ITE 12 – FUNDAMENTALS OF PROGRAMMING Hardware Components o Communication Devices ▪ allows the computer to send and receive data ▪ communication can be either wired or wireless ▪ e.g. network cards, routers, USB WIFI, WIFI dongle ITE 12 – FUNDAMENTALS OF PROGRAMMING Major Components of a Computer What if there is no software? ▪ Software o also called a program o serves as the instructions for the hardware Tells the computer what to do and how to do it o Has a user interface for us to interact with (GUI / CLI) ITE 12 – FUNDAMENTALS OF PROGRAMMING Software Categories o System Software o Application Software ITE 12 – FUNDAMENTALS OF PROGRAMMING System Software o programs needed to control or maintain the operations of the computer and its devices o provides a platform for the application software o two types: Operating System Utility Programs ITE 12 – FUNDAMENTALS OF PROGRAMMING System Software 1. Operating System ◦ Act as an interface between hardware and user ◦ Every computer must have at least one OS ◦ A platform for application software ◦ Portion of OS is loaded and stays in the memory while the computer is on ITE 12 – FUNDAMENTALS OF PROGRAMMING System Software 1. Operating System - Functions ◦ Memory Management ◦ Control over system performance ◦ Processor Management ◦ Job accounting ◦ Device Management ◦ Error detecting aids ◦ File Management ◦ Coordination between other software ◦ Security and users ITE 12 – FUNDAMENTALS OF PROGRAMMING System Software 1. Utility Programs ◦ Allows users to perform maintenance-type tasks ◦ Most OS includes utility programs ◦ i.e. antivirus software Backup software Disk management tools ITE 12 – FUNDAMENTALS OF PROGRAMMING System Software 1. Utility Programs - Functions ◦ Deleting data ◦ Software updates ◦ Disk defragmentation ◦ System cleanup ◦ User accounts and security ◦ encryption/decryption ◦ antivirus software ◦ formatting ITE 12 – FUNDAMENTALS OF PROGRAMMING Application Software o Performs specific personal, educational, and business tasks on a computer o Assists users to processes related to Productivity Creativity Communication o Used by installing and running the application o i.e. games, office apps, editing apps, etc. ITE 12 – FUNDAMENTALS OF PROGRAMMING Peopleware o Uses the computer hardware and software to perform tasks o Includes: Individual people Group of people Project teams Businesses Developers ITE 12 – FUNDAMENTALS OF PROGRAMMING Dataware o The data to be processed as well as the processed data ITE 12 – FUNDAMENTALS OF PROGRAMMING Procedure o Refers to the instructions or steps on how to use / run the application to process the data ITE 12 – FUNDAMENTALS OF PROGRAMMING Programming Languages WHAT IS A PROGRAMMING LAN GUAGE TYPES OF PROGRAMMING LAN GUAGES ITE 12 – FUNDAMENTALS OF PROGRAMMING What is a programming language? o a standardized technique of expressing instructions to a computer o has syntax and semantics Syntax - define how we can put together symbols and identifiers Semantics – define what each statement means o translated to machine language to be executed ITE 12 – FUNDAMENTALS OF PROGRAMMING Types of Programming Languages 1. Machine Language 2. Assembly Language 3. High-level Language ITE 12 – FUNDAMENTALS OF PROGRAMMING Types of Programming Languages 1. Machine Language A series of 1s and 0s The only language our computer understands Machine dependent ITE 12 – FUNDAMENTALS OF PROGRAMMING Types of Programming Languages 1. Machine Language – Example o Problem 00010101 Add 4 to accumulator Add values 4 and 5 that are stored in the memory and store the result in the address of 4 00010110 Add 5 to accumulator o Assume 00110101 Copy the value from the 00000001 – memory address of the value 4 accumulator to the address 00000010 – memory address of the value 5 of 4 01110111 Halt the program ITE 12 – FUNDAMENTALS OF PROGRAMMING Types of Programming Languages 2. Assembly Language Uses keywords and variables instead of binary numbers ▪ Keywords – English-like abbreviations to represent operations ▪ Variable – names given to a memory address Translated to machine language by an assembler Machine-dependent ITE 12 – FUNDAMENTALS OF PROGRAMMING Types of Programming Languages 2. Assembly Language – Example Problem ADD A Add A to accumulator ▪ Add values 4 and 5 that are stored in the memory and store the result in the address of 4 ADD B Add B to accumulator Assume STA A Copy the value from the ▪ Let 00000001 that has 4 be A accumulator to A ▪ Let 00000010 that has 5 be B HLT Halt the program ITE 12 – FUNDAMENTALS OF PROGRAMMING Types of Programming Languages 3. High-level Language Machine-independent Combines algebraic expressions and symbols taken from English Language Designed for easier and faster programming Translated to machine language by a compiler Types: OOP, Procedural ITE 12 – FUNDAMENTALS OF PROGRAMMING Types of Programming Languages 3. High-level Language – Example Problem ▪ Add values 4 and 5 that are stored in the memory and store the result in the address of 4 Assume A=A+ B ▪ Let 00000001 that has 4 be A ▪ Let 00000010 that has 5 be B ITE 12 – FUNDAMENTALS OF PROGRAMMING C Programming HISTORY OF C YOUR FIRST C PROGRA M ITE 12 – FUNDAMENTALS OF PROGRAMMING Short History of C o C evolved from two previous languages: BCPL and B o BCPL (Basic Combined Programming Language) 1967, Martin Richards, Language for OS and Compilers oB (Modeled after BCPL) 1970, Ken Thompson, Used to create early versions of UNIX OS ITE 12 – FUNDAMENTALS OF PROGRAMMING Short History of C o C ( Evolved from B ) 1972, Dennis Ritchie Became widely used in developing UNIX OS Hardware – independent Most of today’s OS are written in C ITE 12 – FUNDAMENTALS OF PROGRAMMING C Compilers o Computer Codeblocks o Mobile Coding C – The offline C Compiler ITE 12 – FUNDAMENTALS OF PROGRAMMING Your first program! o Helloworld.c ITE 12 – FUNDAMENTALS OF PROGRAMMING The Software Development Method ITE 12 – FUNDAMENTALS OF PROGRAMMING Programming in Movies ITE 12 – FUNDAMENTALS OF PROGRAMMING Programming in Reality ITE 12 – FUNDAMENTALS OF PROGRAMMING Expectation vs Reality ITE 12 – FUNDAMENTALS OF PROGRAMMING Programming o Is a problem-solving activity o Uses problem solving methods Business students use the systems approach Engineering students use the engineering and scientific method We use the Software Development Method ITE 12 – FUNDAMENTALS OF PROGRAMMING Software Development Method 1. Problem Definition 2. Problem Analysis 3. Algorithm Development 4. Coding and Documentation 5. Testing and Development 6. Maintenance ITE 12 – FUNDAMENTALS OF PROGRAMMING Software Development Method 1. Problem Definition Specify the problem requirements Understand the problem and state it clearly and unambiguously Define the boundaries of the problem “A clearly defined problem is already half the solution” ITE 12 – FUNDAMENTALS OF PROGRAMMING Software Development Method 1. Problem Definition Example Compute and Display the total cost of apples given the number of kilos and the cost per kilo of apples purchased. ITE 12 – FUNDAMENTALS OF PROGRAMMING Software Development Method 2. Problem Analysis Analyze the problem Involves breaking down the problem into smaller and simpler subproblems Identify the inputs, outputs, and additional constraints ITE 12 – FUNDAMENTALS OF PROGRAMMING Software Development Method 2. Problem Analysis Example ▪ Inputs o Number of kilos of apples (kg) o Cost per kilo of apples (pesos) ▪ Output o Total cost of apples (pesos) ▪ Formula (if any) o Total = cost * kilos ITE 12 – FUNDAMENTALS OF PROGRAMMING Software Development Method 3. Algorithm Development Develop the algorithm to solve the problem An algorithm is a list of steps to solve the problem Don’t attempt to solve every details of the problem at the beginning o Use top-down approach (divide and conquer) ITE 12 – FUNDAMENTALS OF PROGRAMMING Software Development Method 3. Algorithm Development Top-down approach List the major subproblems and then do stepwise refinement After designing an algorithm, perform desk checking. ITE 12 – FUNDAMENTALS OF PROGRAMMING Software Development Method 3. Algorithm Development An algorithm can be expressed in many ways: Human Language Graphical Representation (Flowchart) Pseudocode ITE 12 – FUNDAMENTALS OF PROGRAMMING Algorithm Development 1. Human Language You can write a step by step procedure using English language. ITE 12 – FUNDAMENTALS OF PROGRAMMING Algorithm Development 2. Pseudocode A combination of human language and programming language ITE 12 – FUNDAMENTALS OF PROGRAMMING Algorithm Development 3. Graphical Representation Flowchart A visual representation of the steps or processes involved in solving a problem or performing a task. ITE 12 – FUNDAMENTALS OF PROGRAMMING Flowchart Symbols 1. Terminal ◦ Represents the starting or ending point of the program ◦ Start / Stop 2. Input / Output ◦ Used for any input / output operations in a program ITE 12 – FUNDAMENTALS OF PROGRAMMING Flowchart Symbols 3. Process ◦ Used for arithmetic operations ◦ Data manipulation 4. Decision ◦ Used for decision making between two or more alternatives ITE 12 – FUNDAMENTALS OF PROGRAMMING Flowchart Symbols 5. Flow Line ◦ Indicates the flow of logic by connecting the symbols ITE 12 – FUNDAMENTALS OF PROGRAMMING Software Development Method 3. Algorithm Development - Example in Human Language Find the Largest Number in a List Start: Have a list of numbers. Initialize: Set largest to the first number in the list. Iterate: For each number in the list: If the number is greater than largest, update largest to this number. Finish: After checking all numbers, largest is the largest number. Return/Display: Output largest. ITE 12 – FUNDAMENTALS OF PROGRAMMING Software Development Method 3. Algorithm Development - Example in Pseudocode SumOfTwoNumbers() AreaofTriangle() AreaOfCircle() Begin Begin Begin Read: base, height; Read: radius; Set area = 3.14159 * radius * Set sum =0; Set area = 0.5 * base * height; Print area; radius; Read: number 1, number 2; Print area; Set sum = number1 + number 2; End Print sum; End End ITE 12 – FUNDAMENTALS OF PROGRAMMING Software Development Method 3. Algorithm Development Example in Flowchart ITE 12 – FUNDAMENTALS OF PROGRAMMING Software Development Method 4. Coding and Documentation Implement the algorithm Properly document your code by adding comments ITE 12 – FUNDAMENTALS OF PROGRAMMING Software Development Method 5. Testing and Debugging Test and verify the program Test your program many times with different data sets Verify if the program is doing what is should Debugging The process of fixing errors (bugs) in your program ITE 12 – FUNDAMENTALS OF PROGRAMMING Software Development Method 5. Testing and Debugging Types of Errors 1. Compile-time Error ◦ Occur if there are syntax errors ◦ The compiler won’t compile the code if there are errors detected. 2. Runtime Error ◦ Occurs during the execution of the program ◦ Happens to programs that are syntactically correct but semantically wrong ITE 12 – FUNDAMENTALS OF PROGRAMMING Software Development Method 6. Maintenance Maintain and update the program Usually requires us to repeat the previous steps ITE 12 – FUNDAMENTALS OF PROGRAMMING NEXT TOPIC INTRODUCTION TO C PROGRAMMING ITE 12 – FUNDAMENTALS OF PROGRAMMING

Use Quizgecko on...
Browser
Browser