Chapter 4 - Updated_ UTAS PDF

Summary

This document provides an overview of various topics in programming, including concepts, programming language evolution, the Systems Development Life Cycle (SDLC), algorithms, pseudocode, flowcharts, and control structures. It's likely lecture notes or a similar educational resource for an undergraduate-level computer science course.

Full Transcript

Understanding Problem Solving and Programming Logic Chapter (4) Objectives: At the end of the topic, the students should be able to: Concepts of Programming & Evolutions of Programming Languages Classify computer languages (Machine language, Assembly language, High level lang...

Understanding Problem Solving and Programming Logic Chapter (4) Objectives: At the end of the topic, the students should be able to: Concepts of Programming & Evolutions of Programming Languages Classify computer languages (Machine language, Assembly language, High level language) Explain the different computer languages Understand the different phases of the Systems Development Life Cycle (SDLC) Explain each phase of SDLC Identify the phases of SDLC in relation to a given case/scenario Design algorithm and flowchart for problem solving. Explain the steps in problem solving and programming logic Identify the different flowchart symbols Plan solution to a given problem Design algorithm using flowchart and pseudocode Convert flowchart to pseudocode and vice versa Relate the solution designed to solve a problem with the different control structures Outcomes Covered: Outcome 5 Explain the System Development Life Cycle (SDLC) Outcome 6 Design algorithms and flowcharts for simple problems. Chapter Topics 01 Concepts of Programming 02 Evolutions of Programming Languages 03 Systems Development Life Cycle (SDLC) 04 0 Understanding Problem Solving Using Algorithms (Pseudo codes, Flow charts) 4.1 Concepts of Programming Computer Programming Computer programming, often referred to simply as programming, is the process of designing and writing instructions (code) for a computer to follow to perform specific tasks or solve problems. Programmers use programming languages to communicate with computers and create software applications, scripts, or algorithms. These languages provide a set of rules and syntax for expressing logical and computational instructions in a human- readable format. Programming Steps: The process of programming typically involves several steps, including: 1. Problem Solving: Understanding the problem to be solved and determining the steps and logic required to achieve the desired outcome. 2. Algorithm Design: Breaking down the problem into smaller, manageable steps and designing a series of logical instructions (an algorithm) to solve it. 3. Writing Code: Translating the algorithm into a programming language by writing code that represents the steps and logic of the solution. 4. Testing and Debugging: Running the program and identifying and fixing any errors or bugs (issues) that prevent it from working correctly. Programming Language Programming languages are formal languages used to communicate instructions to a computer. They are essential tools for developing software, websites, applications, and various digital solutions. 4.2 Evolution of Programming Languages Evolution of Programming Languages Programming Languages Low Level Language High Level Language COBOL, FORTRAN, PASCAL, C Machine and C#, JAVA,.NET, C+ Language +, PYTHON, etc. Assembly Language Evolution of Programming Languages Note: The only language understood by a computer is machine language. Machine language Machine language is the lowest level of computer languages. It is the only language that a computer understands. Programs written in machine language consist of entirely of 1 s and 0 s. Each statement in a machine language program is a sequence of bits. Each bit may be set to 0 or 1. Series of bits represent instructions that a computer can understand. Assembly language Assembly language is a low-level programming language that closely resembles the machine language instructions of a computer's architecture. Programs written in assembly language are translated into machine code through an assembler, which converts the mnemonic instructions into their corresponding binary representations. and operands instead of 1s and 0s. Assembler An assembler is a type of computer program that translates assembly language code into machine code, which consists of binary instructions that a computer's processor can execute directly. High Level languages A high-level programming language is a type of programming language that is designed to be easy for humans to read, write, and understand. These languages are typically closer to natural. High-level languages use constructs such as variables, loops, functions, and objects to enable programmers to express complex algorithms and logic in a more concise and understandable manner. Examples of high-level programming languages include Python, Java, C#, JavaScript, Ruby, and many others. High Level languages Translator A high-level language translator is a type of software that converts programs written in high-level programming languages into machine code that can be executed by a computer's hardware. There are two main types of high-level language translators: Compiler Interpreter Compiler Compiler: A compiler translates the entire source code of a program written in a high-level language into machine code in a single step. The resulting machine code is saved as an executable file that can be run directly by the computer's operating system. Compilation typically involves several stages, including lexical analysis, syntax analysis, semantic analysis, code optimization, and code generation. NOTE : Examples of compiled languages are C, C++, C#, Cobol and Fortran Interpreter Interpreter: An interpreter translates and executes high-level language programs line by line, without generating a separate machine code file. Instead, the interpreter reads each line of the source code, translates it into machine code, and immediately executes it. Interpreters are often used in environments where rapid development and debugging are important, as they allow programmers to interactively test and modify their code. NOTE: Examples of interpreted languages are Java, Perl, Python and Ruby Programming Languages Low Lowest High Level Level Human Programme Level Compiler Language Assembler Language Language r Language s (Binary/ s s (Assembly) Machine) Computer Programming Compiling Program -40 Programming Assembly Problem 0110110 Statemen 0 t Low-Level 1101011 High-Level Lowest-Level Languages (Assembly (Machine (C, C++, Fortran… Language) Language) etc) Low Vs High Level Languages High-Level Language Low-Level Language High-level languages are programmer-friendly Low-level languages are machine-friendly because they are easy to manage, because they are designed to be easily understand, debug, and widely used in modern interpreted by machines. However, they are times. very challenging for human beings to understand due to their complexity. These are very easy to execute. These are very difficult to execute High-level languages do not depend on Low-level languages are machine-dependent machines. and thus very difficult to understand by a normal user. High-level languages require the use of a Low-level language requires an assembler for compiler or an interpreter for their translation directly translating the instructions of the into the machine code. machine language. Some examples of high-level languages Examples of low-level languages include the include Perl, BASIC, COBOL, Pascal, Ruby, etc. Machine language and Assembly language. Video: High-level and Low-level languages High Level and Low-Level Language Video Study Material 4.3 Software Development Life Cycle (SDLC) Software Development Life Cycle (SDLC) Planning Understand Problem: A. Input B. Output The Software Development Life Cycle Analysis C. Process (SDLC) is the method used in the software Develop industry to explain how new software is made. It Algorithm Design serves as a roadmap for software developers to A. Pseudocode B. Flowchart make sure they create software that's cost- effective, high-quality, and finished quickly. Coding The SDLC consists of seven stages, and there Testing are various models used for different projects like Waterfall Model, Agile Model, etc. Deploymen t Maintenanc e Stages in SDLC Model Phases of SDLC 1. Planning This phase involves defining the project scope, objectives, requirements, and resources needed. It may also include risk assessment and feasibility studies. 2. Analysis During this phase, the project requirements are analysed in detail, including user needs, system functionalities, and technical specifications. The goal is to gather comprehensive information to guide the design and development process. Identify the constraints of the problem (Hint: Deliverable  IPO Model) Phases of SDLC 3. Design In this phase, the system architecture and design are created based on the requirements gathered during the analysis phase. This includes designing the software's structure, interfaces, data models, and algorithms. Develop algorithm Deliverable  Pseudocode Deliverable  Flowchart 4. Implementation/Coding/Programming This phase known as the coding phase; this is where the actual development of the software takes place. Programmers write the code according to the design specifications, incorporating best practices and coding standards. Phases of SDLC 5. Testing Once the software is developed, it undergoes various testing procedures to identify and fix defects or bugs. This includes functional testing, performance testing, usability testing, and more, to ensure the software meets quality standards. 6. Deployment After successful testing, the software is deployed or released to the end-users or customers. This phase may involve installation, configuration, and training, as necessary. Phases of SDLC 7. Maintenance The final phase involves ongoing maintenance and support for the software after it has been deployed. This includes addressing user feedback, fixing bugs, implementing updates or enhancements, and ensuring the software remains functional and up-to-date over time. Case Scenario of SDLC Model: Developing a Basic Website 1. Planning: The client, a small business owner, wants a simple website to showcase their products and services. They meet with a web development team to discuss their requirements, which include a homepage, product pages, contact form, and about us section. The outcome of this phase is Website plan, resource allocation and total budget. 2. Analysis: Based on the planning the development team will analyze the proposed website and create the functionals and non-functional requirements. 3. Design: Based on the requirements gathered and analysis, the development team creates a design plan for the website. They design the layout of each page, determine the colour scheme and select appropriate images 4. Coding: With the design approved, the development team begins coding the website. They create HTML, CSS, and JavaScript files to build the frontend of the website, ensuring it matches the approved design. 5. Testing: After the development phase, the website undergoes testing to ensure it functions correctly and meets the client's requirements. 6. Deployment: Once testing is complete and all issues are addressed, the website is ready for deployment. The development team uploads the website files to a web server and configures it for public access. 7. Maintenance: After deployment, the development team provides ongoing maintenance and support for the website. They monitor its performance, apply security patches, and address any issues reported by users. 4.4 Understanding Problem Solving using Algorithm (Pseudocode & Flowchart) Software Engineering vs Problem Solving  Computer science is the study of the theoretical foundations of information and computation, and of practical techniques for their implementation and application in computer systems.  Software engineering is a branch of computer science that provides techniques to facilitate the development of computer programs  Problem solving refers to the entire process of identifying the problem and its scope, and developing a computer program that solves that problem. Software Development Process Design Algorithm for Problem Solving Before the phase of coding or the development of the computer program, first we need to analyze and design the solution to the problem as follows: 1. Understanding the problem (problem analysis) 2. Designing the solution using an algorithm 3. Writing the program 4. Testing the program 5. Evaluating the solution Problem Analysis  Understanding the Problem o Use the Input -> Process -> Output (IPO) Model o Determine Input / Output Data or Objects o Identify the processes involved (mathematical calculations, logical analysis, etc.)  During the problem analysis, we use the I-P-O model without regard to programming control structures. Problem Analysis  Use of variable names o A variable name given to computer memory locations used to store values to be referenced and manipulated in a computer program. The information stored in a variable may change but the operation (process) on the variable remains the same. We must use variable names that refer to the actual information stored in them when we identify them during the I-P-O analysis. Identifying Input, Output and Process An input is identified from a given problem by referring to keywords such as Enter, Read, Get and Accept. An output is identified from the given problem by referring to keywords such as Display, Print, and Write. Verbs or action words must be used to indicate a process. We can also use the assignment statement using the = symbol to indicate a process. Similarly, comparison operators may be used for logical analysis Example (1) Write IPO chart to display the sum of 2 integers. INPUT PROCESS OUTPUT Number1 Sum= number1 +number2 sum Number2 Example (2) Write IPO chart to get the length and width of a rectangle and display the area. INPUT PROCESS OUTPUT Length Area=length + width area width Example (3) Write IPO chart to input the student’s grade and display Remark="Pass" if grade is more than or equal to 55 or Remark="Fail" if grade is less than 55. INPUT PROCESS OUTPUT Remark="Pass" if grade is Pass, grade more than or equal to 55 fail or Remark="Fail" if grade is less than 55. Designing a solution using an algorithm  After problem analysis, the next step we need to do is to use design tools that will allow us to breakdown the problem into smaller parts. This is made possible by developing the algorithm to design the solution to the problem. Algorithm An algorithm is a sequence of finite number of steps arranged in a logical order to produce a solution to a problem Characteristics of Algorithm Unambiguous – it should be clear General – should be applicable to similar type of problems Correct – it should produce the desired output Finite – there should be a beginning and end Efficient – it should solve the problem at the shortest possible time Algorithm Types Pseudocode – a semi-formal, English-like language with limited vocabulary that can be used to design and describe algorithms. An algorithm is described in this way using short, telegram-like English statements, describing each step of the solution to the problem. The pseudocode is independent of any programming language syntax. Sample of a Pseudocode Algorithm Types  Flowchart – represents the algorithm in a graphical symbol. It is a graph of geometrical shapes connected by lines that show the process flow of a solution to a problem.  Elements of a Flowchart  Geometrical shapes – represent the type of statements in the algorithm  Flow lines – show the order in which the statements of the algorithm are executed Flowchart Symbols Explaining the Flowchart Use of connectors in Flowchart Control Structures in Algorithms  Control Structures – describe the flow of execution  Basic Types:  Sequential (Linear)  Selection (Choice)  Repetition (Loop) Sequential Structure  A series of steps or statements that are executed in the order they are written in an algorithm  In Pseudocode, they mark the beginning and end of a block of statements.  In Flowchart, they are multiple statements considered as one statement. Sequential Structure Examples  Pseudocode Sequential Structure Examples  Flowchart Case Scenario Develop algorithm and flowchart to 1. Find the sum of 2 numbers 2. Find the total and average of 3 class activities 3. Accept 2 numbers and perform the four basic mathematical operations Selection Structure  The Selection Structure allows for a choice between two or more alternatives, that is, it allows you to make decisions.  In Pseudocode it requires the use of the keyword “if” and “else”  Example:  if condition  statement 1  else  statement 2  endif Selection Structure  Flowchart example Selection Structure  Check for certain condition and then execute or skip a sequence of statements.  Used to test logically whether the condition is True or False, a decision-making statement.  The condition is a Boolean expression. True False Compariso n operators = < > < > != = = = Selection Structure Example Condition : The Weather is nice If the weather is nice : go to the beach If the weather is not nice: will not go to the beach Case Scenario Develop the pseudocode and flowchart for the following: Moodle Learning Management System displays the remark “Passed” if the grade entered is greater than or equal to 55, otherwise, it displays the remark “Failed”. Lulu Hypermarket is offering discounts to its customers. It will read the bill of the customers. If the bill is greater than 10 OMR, the discount will be computed as 5% of the bill, otherwise the discount is 1% of the bill. The total bill is computed by subtracting the discount from the bill. Display all the data. Pseudocode and Flowchart Activities Q#1: Write algorithm for the following flowchart. Flowchart Algorithm Q#2: Write IPO chart, algorithm and Flowchart to Find Area and Perimeter of a circle. IPO Chart Algorithm Flowchart Q#3: Write IPO chart, algorithm and Flowchart to accept two numbers and swap/exchange their values. Example: Input: 10, 20 Output: 20, 10 IPO Chart Algorithm Flowchart Q#4: Write IPO chart, algorithm and Flowchart to accept amount in Omani Rials and convert to UAE Dirhams. Formula: One Rial = 9.54 Dirhams IPO Chart Algorithm Flowchart Q#5: Write IPO chart, algorithm and Flowchart to accept one number and check the given number is positive or negative. IPO Chart Algorithm Flowchart Q#6: Correct the following algorithm to print smallest of two numbers Incorrect Algorithm Correct Algorithm Step 1: read three numbers Read a, b, c Step 2: Start Step 3: if a < b print “b is larger” else print “c is larger” end if Step 4: Stop Q#7: Correct the following flowchart to find largest of two numbers Incorrect flowchart Correct flowchart Q#8: Write an algorithm to accept the purchase amount and calculate discount based on the following conditions purchase amount discount Less than 100 Rial 5% of purchase amount Otherwise 12.5 % of purchase amount

Use Quizgecko on...
Browser
Browser