The words you are searching are inside this book. To get more targeted content, please make full-text search by clicking here.

Introduction to Computers and Programming

Discover the best professional documents and content resources in AnyFlip Document Base.
Search
Published by sariah.rajuli, 2025-12-15 22:12:24

Introduction to Computers and Programming

Introduction to Computers and Programming

Introduction to Computers and ProgrammingSESSION 3 2025/20261


CHAPTER 1 – Understanding the Concept of Computer ProgrammingSubtopic1.1 Types of computers1.2 Overview of programming languages1.3 The Role of Programming in Problem Solving1.4 The Program Development Life Cycle (PDLC)2


1.1 Types of Computers OverviewServersManage resources and services in a network environment. used for various purposes such as hosting websites, managing email, storing files, running applications, or providing access to databases.MicrocomputersPersonal computers for everyday home and office use.MobilePortable devices for on-the-go computing needs.33


Types of Computers OverviewEmbedded computersCan be found in electronic devices ( washing machines, televisions, microwaves), and in computer devices such as smartphones and smartwatches, and even in vehicle.SupercomputersPowerful computer that can process massive amounts of data and perform complex calculations at very high speeds (weather forecasting, climate modeling, nuclear, cryptography MainframesVery good at managing big databases, processing many transactions, and running batch jobs such as banking, flight bookings, and payroll.34


1.2 Overview of programming languages and their hierarchy45


1.2 OVERVIEW OF PROGRAMMING LANGUAGESDIFFERENCES BETWEEN PROGRAMS AND PROGRAMMING• A program is a set of instructions that tell the computer how to solve aproblem or perform a task.• Programming is the process of designing and writing computer programs.• Programming is like cooking. You gather ingredients, follow a recipe, taste,adjust, and make sure everything works well together. It’s the process ofcreating something.• Program is like the finished dish. Once cooked, it’s ready to serve and eat. It’sthe end product that people use or enjoy.56


Overview of Programming LanguagesTranslatorSpecial software called a compiler /interpreter / assembler converts theprogramming language statements tomachine language instructions.Functions / purposesProgramming languages are used tocreate software applications, websites,mobile apps, games, and other typesof digital content.Languages• A programming language is acomputer language that is used byprogrammers (developers) tocommunicate with computers. It is aset of instructions written in anyspecific language (C, C++, Java,Python) to perform a specific task.57


Levels of Programming LanguagesHigh-Level LanguagesEasier to read and write, moreabstract concepts.Specialized for specific tasks, userfriendly syntax.Low-Level LanguagesClose to hardware, fast execution, hard to read.58


Low-Level Languages6Machine Language• Lowest level of programming language• Written in binary code (0s and 1s)• Directly understood by the computer• Very fast execution• Difficult for humans to read and write• Processor-dependent (not portable)Assembly Language• Low-level language that uses mnemonics (short words like MOV, ADD)• Easier to read than machine language• Requires an assembler to convert into machine code• Faster than high-level languages• Still hardware-dependent• Commonly used for system programming and embedded systemsSymbol (mnemonic) -AssemblyBinary code - MachineLoad 0000 0000Add 0000 0001Sub 0000 0010: :Stop 1111 11119


6PROGRAMMING LANGUAGE TRANSLATORThere are two main types of programming language translators: compilers and interpreters.CompilerIs a program that translates a high-level languageprogram into a separate machine language at once.Once the program has been compiled into machinelanguage, it can be executed directly on the computer.The machine language program can then be executedany time it is needed.InterpreterInterpreter translates the program line by line andexecute it immediately. As the interpreter reads eachindividual instruction in the program, it converts it tomachine language instructions then immediatelyexecutes them. This process repeats every instruction inthe program. The Python language uses an interpreter.10


GENERATIONS OF PROGRAMMING LANGUAGES611


1.3 The Role of Programming in Problem SolvingFieldsProgramming applications span multiple industries and domains.DesignCreating solutions involves structured approaches to coding.StepsIdentifying problems can lead to effective solutions.712


Programming follows the same stages as solving any problem:6Problem Solving and ProgrammingStep Description ExampleProblem identification and analysisUnderstand what needs to be solvedBreak the problem into smaller partsProblem: Students often forget their assignment deadlines because there’s no simple way to track them.Identify what data is needed: subject, due date, task statusDesign the solution Create a flowchart or pseudocodeOutline steps for entering, viewing, and updating assignments.Implementation / code Write the program using a programming languageDevelop the assignment tracker system.Test and debug Check for errors and improve Fix incorrect calculations or display errors.Evaluate and maintenance Review and enhance Add reminders or notifications in future updates.13


6EXAMPLES OF PROGRAMMING APPLICATIONS ACROSS DIFFERENT FIELDSField Example of Application Problem Solved / PurposeProgramming Concepts Commonly UsedBusiness Point of Sale (POS) System, Online Shopping PlatformAutomates sales, stock management, and reportingDatabase management, file handling, user interface designEducation Learning Management System (e.g., Google Classroom, Moodle)Allows teachers to share materials, track progress, and communicate with studentsWeb development, authentication, data storageHealthcare Patient Record System, Health Monitoring AppsManages patient data, tracks health status, and supports telemedicineData security, data visualization, IoT integrationFinance Mobile Banking Apps, Budget TrackersEnables cashless transactions and real-time balance trackingAPI integration, encryption, mobile app development14


Visualizing the impact of programming solutions615Types of Programming 1.4 Program Development Life Cycle


Program Development Life Cycle (PDLC) Phases1. AnalysisIdentify the needs and requirements for the project.2. DesignCreate the system architecture and design specifications (flowchart or pseudocode)3. ImplementationDevelop and deploy the system according to the design using programming language.4. Testing & DebuggingEnsure the system works correctly and efficiently.5. MaintenanceLaunch the system for user access and feedback.16


17Developing a programCONCEPT:Programs must be carefully designed before they are written. During the design process,programmers use tools such as pseudocode and flowcharts to create models of programs.• The process of developing a program is called as program development.• The process associated with creating successful application programs is called the ProgramDevelopment Life Cycle (PDLC)• The process of creating a program that works correctly typically requires the five phases• Starting with coding without a proper design can lead to errors, inefficiency, and difficultdebugging.


18PHASE 1 : ANALYSIS• Reviewing the program specifications is fundamental in making analysis. Therefore identifythe problem, objectives, and program requirements.• Other criteria are often identified, especially when the program involves data that will beused as input, the process involved and the output that will be produced.• Determine feasibility, constraints, and potential risks.


19• Example INPUT :Data inserted into the systemPROCESS :System will evaluate and computeOUTPUT :Data from the process will be generated


1. Calculate the total revenue of a product by entering the quantity sold and price per unit.Formula: Total Revenue = Quantity Sold × Price Per Unit2. Determine an employee's monthly salary, including bonuses.Formula: Total Salary = (Basic Salary + Bonuses)3. Develop a system to classify a customer's purchase category based on the total amount spent. If thepurchase amount is less than RM500 display “Regular Customer” and if the purchase amount iswithin RM500 - RM2000 display “Loyal Customer” and if RM2000++ then display “PremiumCustomer”4. Create a system to check if a business qualifies for a loan based on its annual revenue and creditscore.Condition: If Annual Revenue ≥ RM50,000 AND Credit Score ≥ 700 → \"Eligible\", Otherwise → \"NotEligible\"Individual Exercise 1.3.1Write the analysis step (input, output, process) and tabulate the answer, for the following questions: 20


21Answer for Exercise 1.3.1


22PHASE 2 : DESIGN• Create flowcharts, algorithms, or pseudocode for program logic – Develop a structuredrepresentation of how the program will function, ensuring logical flow and efficiency.• Define database structures, system architecture, and data flow – Plan how data will bestored, retrieved, and processed to ensure smooth system operations.• Plan user interfaces and interactions for an efficient experience – Design the visual layoutand usability aspects to ensure a smooth and user-friendly experience.


List of requirements that must be satisfied when creating an algorithm: 1. Well-Defined Inputs – The algorithm should clearly define the required input values or data needed forprocessing.2. Well-Defined Outputs – It must specify what results (outputs) will be produced after execution.3. Definiteness – Each step of the algorithm must be clear, precise, and unambiguous to avoid confusion inexecution.4. Effectiveness – The algorithm should be logically correct and accomplish its task using a finite number of steps.5. Finiteness – It must have a clear stopping point and not run indefinitely.6. Logical Sequence – The steps must be ordered logically and sequentially to ensure proper execution.7. Generality – The algorithm should be applicable to a range of inputs, making it reusable for similar problems.23


24• Before an algorithm is created, the three types of control structure should be understoodfirst.• A control structure is a pattern to control the flow of a program module.


PSEUDOCODEand FLOWCHART 25


A flowchart is a visual representation of a process, showing the steps in a logical sequenceusing different symbols. It helps in understanding and designing algorithms before writingcode.Flowcharts use specific shapes to represent different actions: such as (oval, rectangles,diamonds, arrows and etc) with each shapes correspond to specific action such as : (input,output, start, end, process, direction and etc)Flowcharts simplify complex processes, making it easier to debug, analyze, andcommunicate program logic. They are widely used in software development, businessprocesses, and system design.Flowchart text should be clear and readable. Generally, uppercase is used for keywords orimportant steps, while lowercase is used for detailed descriptions to improve clarity.FLOWCHART26


27FLOWCHART ALMANAC• Do not simply make a flowchart withoutunderstanding the function for each shape.• Be clear & use the right shape to define each data.


28• Study the example below, identify the input, output, process and the shape of the flowchart involved.


29• Another example : -


30• Different example using off page connector shape


31PSEUDOCODE• Pseudocode is a simplified way of writing program logic using a mix of plain language andprogramming concepts. It is not actual code, but a structured outline that helpsprogrammers plan before writing in a real programming language.• Structure & Writing Style – Pseudocode follows a logical sequence, using commonprogramming terms like: (BEGIN / END, DECLARE , DISPLAY, IF-ELSE / WHILE / FOR)• Pseudocode helps simplify complex algorithms, making it easier to understand, debug, andconvert into actual code. It is widely used in software development, system design, andteaching programming.


32PSEUDOCODE (SEQUENTIAL CONTROL STRUCTURE)Example 1 Example 2Question:Calculate the sum of two numbers.Solution:1.0 BEGIN2.0 DECLARE int num1, num2, sum3.0 READ num1, num24.0 CALCULATE sum = num1 + num25.0 DISPLAY sum6.0 ENDQuestion:Convert temperature from Celsius to Fahrenheit.Solution:1.0 BEGIN2.0 DECLARE double celsius, fahrenheit3.0 READ celsius4.0 CALCULATE fahrenheit = (celsius * 9/5) + 325.0 DISPLAY fahrenheit6.0 END


33PSEUDOCODE (SELECTION CONTROL STRUCTURE)Example 1 Example 2Question:Determine whether a person is eligible to vote based on their age.Solution:1.0 START2.0 DECLARE int age3.0 READ age4.0 IF (age >= 18)4.1 DISPLAY \"Eligible to vote\"5.0 ELSE5.1 DISPLAY \"Not eligible to vote\"6.0 ENDQuestion:Identify whether the number is postive or negative numberSolution:1.0 START2.0 DECLARE int num3.0 READ num4.0 if(num > 0) 4.1 DISPLAY “positive number”5.0 else 5.1 DISPLAY “negative number”6.0 END


PSEUDOCODE (SELECTION CONTROL STRUCTURE)Example 3Question:Solution:Design an algorithm that will prompt an operator for astudent’s id and the student’s exam score out of 100. Yourprogram is then to match the exam score to a letter gradeand print the grade to the screen. Calculate the lettergrade as follows:Score Grade80 and above A50 – 79 BBelow 50 F1.0 BEGIN2.0 DECLARE string studentID, grade; float Score;3.0 READ studentID, Score4.0 if Score >= 80 AND Score <= 1004.1 Grade = ‘A’5.0 else if Score >= 50 AND Score <= 795.1 Grade = ‘B’6.0 else6.1 Grade = ‘F’7.0 DISPLAY Grade8.0 END34


35SELECTION CONTROL STRUCTUREConvert the Pseudocode into FlowchartPseudocode1.0 START2.0 DECLARE double weight, charge, cost;3.0 READ weight4.0 if weight > 5.04.1 cost = 2.455.0 else if weight >= 2.5 AND weight <= 55.1 cost = 2.856.0 else6.1 cost = 3.507.0 CALCULATE charge = weight * cost8.0 DISPLAY charge9.0 ENDExample 1


36REPTITIVE CONTROL STRUCTUREConvert the Pseudocode into FlowchartPseudocode1.0 START2.0 DECLARE int no, sum, count; double avg3.0 INITIALIZE sum = 0, count = 0, avg = 04.0 while count < 34.1 READ no4.2 CALCULATE sum += no4.3 CALCULATE count += 15.0 CALCULATE avg = sum / count6.0 DISPLAY sum, avg7.0 ENDExample 2


PSEUDOCODE SELECTION + REPETITION CONTROL STRUCTUREQuestion:Formulate a pseudocode thatwill calculate a running sum. Auser will enter numbers that willbe added to the sum and when anegative number is encountered,stop adding numbers and displaythe final sum.EXERCISE1.0 START2.0 DECLARE int number, sum3.0 INITIALIZE sum = 04.0 READ number5.0 while number > 05.1 CALCULATE sum = sum + number5.2 READ number6.0 DISPLAY sum7.0 STOPPseudocode


38PSEUDOCODE SELECTION + REPETITION CONTROL STRUCTUREQuestion:Write a pseudocode for a program that reads a list of integers from the user until negative number is entered.The program should:▪ Add all even numbers to one total▪ Add all odd numbers to another total▪ Display the total of odd numbers and the total of even numbers after the input endsEXERCISE1.0 START2.0 DECLARE int number, oddSum, evenSum3.0 INITIALIZE oddSum = 0, evenSum = 04.0 READ number5.0 while number > 05.1 if number % 2 == 05.1.1 CALCULATE evenSum += number5.2 else5.2.1 CALCULATE oddsum += number5.3 READ number6.0 DISPLAY oddSum, evenSum7.0 ENDPseudocode


FlowchartPSEUDOCODE SELECTION + REPETITION CONTROL STRUCTURE39


EXTRA EXERCISE (SELF STUDY)Convert the following Pseudocode into FlowchartExercise 2:Identify whether a number is an odd or even number.Then find and display the sum of all the odd and evennumbers. To stop program, user must enter N.Solution:Exercise 1:Get the salary of a 20 employees then find the totalsalaries of all the employees.Solution:40


PHASE 3 : IMPLEMENTATION / CODING• Convert the design into actual code using a programming language – Write the programbased on the planned design, following structured coding principles such as C++ or Python• Coding practice – Maintain code readability, ensure proper commenting, and track changesefficiently using version control• Integrate necessary libraries, APIs, or external modules if required – Enhance functionalityby incorporating external tools, frameworks, or third-party services.41


42PHASE 4 : TESTING / DEBUGGING• Identify and fix errors (syntax, logic, runtime) through debugging – Check for common issues such as incorrectsyntax, faulty logic, or unexpected crashes.• Perform unit testing, integration testing, and user acceptance testing – Ensure individual components workcorrectly, integrate smoothly, and meet user requirements.• Optimize code performance and ensure compatibility with different environments – Improve executionspeed, reduce memory usage, and ensure the software runs on various devices/platforms.• Testing is the process of running a program to identify errors and verify that it functions as expected. It ensuresthat the program meets the requirements and behaves correctly under different conditions.• Debugging is the process of finding and fixing errors (bugs) in a program. It involves analyzing the code,identifying the issue, and making corrections to ensure proper execution.


PHASE 5 : MAINTENANCE• Provide updates and improvements based on user feedback or new requirements –Continuously refine the coding to add features, fix issues, and enhance user experience.• Fix security vulnerabilities, apply patches, and optimize performance – Ensure the system issecure, able to perform without any problem and remains efficient over time.• Ensure compatibility with new technologies and evolving system needs – Adapt to changesin hardware, software dependencies, and industry standards.End of slide43


Click to View FlipBook Version