Week 1 - Overview of Computer Programming.pdf
Document Details
Uploaded by Deleted User
Tags
Full Transcript
Course Material BSIT Department An Overview of Computers and Programming Fundamentals of Programming Course Material BSIT Department Objectives At the end of the discussion, each students w...
Course Material BSIT Department An Overview of Computers and Programming Fundamentals of Programming Course Material BSIT Department Objectives At the end of the discussion, each students will be able to: 01.01 Describe the components of computer systems 01.02 Develop simple program logic 01.03 List the steps involved in the program development cycle 01.04 Write pseudocode statements and draw flowchart symbols 01.05 Use a sentinel value to end a program 01.06 Describe programming and user environments 01.07 Describe the evolution of programming models Course Material BSIT Department Understanding Computer Systems (1 of 9) Computer system − Combination of all the components required to process and store data using a computer − Hardware ▪ Equipment associated with a computer − Software ▪ Computer instructions that tell the hardware what to do Course Material BSIT Department Understanding Computer Systems (2 of 9) Software − Programs ▪ Set of computer instructions written by programmers − Programming ▪ Writing software instructions Logic of a computer program − The complete sequence of tasks that lead to a problem’s solution Course Material BSIT Department Understanding Computer Systems (3 of 9) Types of software − Application software such as word-processing programs, spreadsheets, payroll and inventory programs, and games − System software includes operating systems, which include Windows, Linux, or UNIX for larger computers and Google Android and Apple iOS for smartphones Course Material BSIT Department Understanding Computer Systems (4 of 9) Computer hardware and software accomplish three major operations in most programs − Input ▪ Data items such as text, numbers, and other raw material that are entered into and processed by a computer − Processing ▪ Organizing or sorting data, checking them for accuracy, or performing calculations with them using the central processing unit (CPU) Course Material BSIT Department Understanding Computer Systems (5 of 9) − Output ▪ The resulting information after data processing that is sent to a printer, a monitor, or some other output devices such as storage devices The cloud refers to devices at remote locations accessed through the Internet Course Material BSIT Department Understanding Computer Systems (6 of 9) Programming language − Used to write computer instructions called program code − Writing instructions is called coding the program − Examples ▪ Visual Basic, C#, C++, or Java Course Material BSIT Department Understanding Computer Systems (7 of 9) Syntax − Rules that govern the word usage and punctuation used in every programming language − Mistakes in a language’s usage are syntax errors Computer memory − Computer’s temporary, internal storage where program instructions are stored ▪ Random access memory (RAM): Form of internal, volatile memory Course Material BSIT Department Understanding Computer Systems (8 of 9) − Internal storage is volatile—its contents are lost when the computer is turned off or loses power Permanent storage devices − Nonvolatile memory Compiler or interpreter − Translates source code into machine language (binary language) statements called object code − Checks for syntax errors Course Material BSIT Department Discussion Activity 1 How are compilers different from interpreters? Course Material BSIT Department Discussion Activity 1: Answer The basic function of compilers and interpreters is the same—they translate programming statements into code the computer can use. However, when you use a compiler, an entire program is translated before it can execute. But when you use an interpreter, each instruction is translated just prior to execution. Usually, programmers do not choose which type of translation to use—it depends on the programming language. Course Material BSIT Department Understanding Computer Systems (9 of 9) When instructions are carried out, a program executes, or runs − Some input will be accepted, some processing will occur, and results will be output Course Material BSIT Department Knowledge Check Activity What does cloud refer to? a. Devices at remote locations accessed through the Internet b. Data items that are entered into and processed by a computer c. Computer instructions that tell computer hardware what to do d. Equipment, or the physical devices, associated with a computer Course Material BSIT Department Knowledge Check Activity: Answer What does the cloud refer to? Answer: a. Devices at remote locations accessed through the Internet After data items have been processed by a computer, the output data is sometimes stored on a storage device, such as a hard drive, flash media, or a cloud-based device. The cloud refers to devices at remote locations accessed through the Internet. The data cannot be read or interpreted directly from these storage devices, but the devices hold information for later retrieval. Course Material BSIT Department Understanding Simple Program Logic (1 of 3) Programs with syntax errors cannot be translated fully and cannot be executed Programs with no syntax errors might produce incorrect output due to logical errors − Errors in program logic that produce incorrect output Course Material BSIT Department Understanding Simple Program Logic (2 of 3) Most simple computer programs include steps that perform input, processing, and output Example of a program using English-like statements input myNumber myAnswer = myNumber * 2 output myAnswer Course Material BSIT Department Understanding Simple Program Logic (3 of 3) The number-doubling process includes three instructions: The instruction to input myNumber is an example of an input operation The instruction myAnswer = myNumber * 2 is an example of a processing operation The output myAnswer instruction is an example of an output operation Course Material BSIT Department Understanding the Program Development Cycle (1 of 2) Program development cycle − Understand the problem − Plan the logic − Code the program − Use software (a compiler or an interpreter) to translate the program into machine language − Test the program Course Material BSIT Department Understanding the Program Development Cycle (2 of 2) − Put the program into production − Maintain the program Course Material BSIT Department Figure 1-1: The Program Development Cycle Course Material BSIT Department Understanding the Problem Users or end users − People for whom a program is written − Programmers must first understand what the users want − Documentation ▪ All supporting paperwork for a program that is provided to help programmers understand the problem One of the most difficult aspects of programming Course Material BSIT Department Planning the Logic (1 of 2) The heart of the programming process Programmer plans the steps of the program, decides what steps to include and how to order them Most common planning tools − Flowcharts − Pseudocode Algorithm is the sequence of steps or rules to be followed to solve a problem Course Material BSIT Department Planning the Logic (2 of 2) Desk-checking − Walking through a program’s logic on paper before the program is actually written ▪ Thinking about all the possible data values a program might encounter ▪ How the programmer wants the program to handle each scenario Course Material BSIT Department Coding the Program Hundreds of programming languages are available − Chosen based on features − Similar in their basic capabilities Some experienced programmers can successfully combine logic planning and program coding in one step Coding is easier than the planning step Course Material BSIT Department Using Software to Translate the Program into Machine Language Translator program written by a compiler or interpreter: − Changes the programmer’s English-like high-level programming language into low-level machine language (low-level programming language) Syntax error − Translator program issues an error message if a programming statement is written incorrectly − Programmer corrects the received list of syntax errors ▪ Might need to recompile the code several times Course Material BSIT Department Figure 1-2: Creating an Executable Program Course Material BSIT Department Testing the Program Logical error − Results when a syntactically correct statement, but the wrong one for the current context, is used After a program is free of syntax errors, the programmer can test it − Programmer can execute the program with some sample data to see whether the results are logically correct Debugging is the process of finding and correcting program errors − A program is debugged by testing it using many sets of data Course Material BSIT Department Putting the Program into Production Process depends on the program’s purpose − May take several months Conversion − Entire set of actions an organization must take to switch over to using a new program or set of programs Course Material BSIT Department Maintaining the Program Maintenance − Making necessary changes after the program is put into production Common first programming job for programmers − Maintaining previously written programs Programmer makes changes to existing programs − Repeats the development cycle Course Material BSIT Department Think, Pair, Share Suppose you have to write a program to calculate the ratio of students to teachers in a school. Think about the steps involved in the program development cycle. Pair with a partner or create a breakout group of four. Share your ideas with your partner or the group about the steps that need to be taken to write the program. Discuss how essential it is to satisfy each step before moving forward to the next step to be able to achieve the expected output. Course Material BSIT Department Using Pseudocode Statements and Flowchart Symbols Pseudocode − English-like representation of the logical steps it takes to solve a problem Flowchart − Pictorial representation of the logical steps Course Material BSIT Department Writing Pseudocode Pseudocode representation of a number-doubling problem start input myNumber myAnswer = myNumber * 2 output myAnswer stop Course Material BSIT Department Pseudocode Standards (1 of 2) Programs begin with start and end with stop; these two words are always aligned Program statements are indented a few spaces Each program statement appears on a single line if possible − If this is not possible, continuation lines are indented Program statements begin with lowercase letters No punctuation is used to end a statement Course Material BSIT Department Pseudocode Standards (2 of 2) Each program statement performs one action—for example, input, processing, or output Whenever a module name is used, it is followed by a set of parentheses Modules begin with the module name and end with return; these are always aligned Course Material BSIT Department Drawing Flowcharts (1 of 4) Process − Draw geometric shapes that contain the individual statements and that are Figure 1-3: Input symbol connected with arrows Input symbol − Indicates an input operation − Parallelogram Course Material BSIT Department Drawing Flowcharts (2 of 4) Processing symbol Figure 1-4: Processing symbol − Contains processing statements such as arithmetic operation statements − Rectangle Course Material BSIT Department Drawing Flowcharts (3 of 4) Output symbol Figure 1-5: Output symbol − Contains output statements − Parallelogram ▪ Often called the input/output symbol or I/O symbol as it is used for both input and output Course Material BSIT Department Drawing Flowcharts (4 of 4) Flowlines − Arrows that connect steps to show the correct sequence of statements Terminal symbol or start/stop symbol − Placed at each end of a flowchart − Shaped like a racetrack − Also referred to as a lozenge Course Material BSIT Department Figure 1-6: Flowchart and Pseudocode for Program that Doubles a Number Course Material BSIT Department Repeating Instructions To avoid high consumption of time while writing a program: − Create a loop ▪ Repetition of a series of steps − Avoid an infinite loop ▪ Repeating flow of logic with no end Course Material BSIT Department Figure 1-8: Inefficient Pseudocode for Program that Doubles 10,000 Numbers Course Material BSIT Department Figure 1-9: Flowchart of Infinite Number- Doubling Program Course Material BSIT Department Using a Sentinel Value to End a Program (1 of 2) Decision symbol − Represents testing a value or evaluating an expression in a flowchart − Diamond shape ▪ Contains a question or evaluation, the answer to which is one of two mutually exclusive options Course Material BSIT Department Figure 1-10: Flowchart of Number-Doubling Program with Sentinel Value 0 Course Material BSIT Department Using a Sentinel Value to End a Program (2 of 2) Dummy value − Preselected value that stops the execution of a program − Does not represent real data, but just a signal to stop − Referred to as sentinel value − eof (“end of file”) ▪ Marker at the end of a file that automatically acts as a sentinel Course Material BSIT Department Figure 1-11: Flowchart using eof Course Material BSIT Department Understanding Programming and User Environments (1 of 3) To enter a word processing program into a computer, a keyboard is usually used to type program statements into an editor − Plain text editor − Text editor that is part of an integrated development environment ▪ Program used to create simple text files ▪ Integrated development environment (IDE) Software package that provides an editor, compiler, and other programming tools Course Material BSIT Department Understanding Programming and User Environments (2 of 3) ▪ Example Microsoft Visual Studio IDE − Features included in an IDE’s editor ▪ It uses different colors to display various language components, making elements like data types easier to identify ▪ It highlights syntax errors visually ▪ It employs automatic statement completion ▪ It provides tools that allow one to step through a program’s execution one statement at a time Course Material BSIT Department Figure 1-12: A C# Number-Doubling Program in Notepad Course Material BSIT Department Figure 1-13: A C# Number-Doubling Program in Visual Studio Course Material BSIT Department Understanding Programming and User Environments (3 of 3) Command line is a location on your computer screen at which you type text entries to communicate with the computer’s operating system A graphical user interface, or GUI, allows users to interact with a program in a graphical environment Course Material BSIT Department Discussion Activity 2 What is the function of a text editor? Course Material BSIT Department Discussion Activity 2: Answer A text editor is a program that can be used to create simple text files. It is similar to a word processor but without as many features. Notepad is a text editor that is included with Microsoft Windows. An advantage to using a simple text editor to type and save a program is that the completed program does not require much disk space for storage. Course Material BSIT Department Figure 1-14: Executing a Number-Doubling Program in a Command-Line Environment Course Material BSIT Department Figure 1-15: Executing a Number-Doubling Program in a GUI Environment Course Material BSIT Department Understanding the Evolution of Programming Models (1 of 3) People have been writing modern computer programs since the 1940s The oldest programming languages required programmers to work with memory addresses and to memorize awkward codes associated with machine languages Newer programming languages − Look much more like natural language − Are easier to use − Allow programmers to create self-contained modules or program segments that can be pieced together in a variety of ways Course Material BSIT Department Understanding the Evolution of Programming Models (2 of 3) Major models or paradigms used by programmers − Procedural programming ▪ Focuses on the procedures that programmers create ▪ Focuses on the actions that are carried out Example: Getting input data for an employee and writing the calculations needed to produce a paycheck from the data Course Material BSIT Department Understanding the Evolution of Programming Models (3 of 3) − Object-oriented programming (OOP) ▪ Focuses on objects, or “things,” and describes their features (also called attributes) and their behaviors ▪ Example: Object-oriented programmers might design a payroll application by thinking about employees and paychecks and by describing their attributes Course Material BSIT Department Self-Assessment What are the different symbols that are used in a flowchart? What is a sentinel value? What are the two major models or paradigms that are used by programmers to develop programs? Course Material BSIT Department Summary Click the link to review the objectives for this presentation. Link to Objectives Course Material BSIT Department References Burd, B. (2021). Beginning Programming with Java for Dummies. (6th ed.). Crutcher, P. (2021). Essential computer science: a programmer’s guide to foundational concepts. Ellison, B. (2022). Java for Beginners: A Crash Course to Learn Java Programming in 1 Week (Programming Languages for Beginners). Horstmann, C. (2019). Core Java: volume II-advanced features. Sebesta, R. (2020). Concepts of Programming Languages. (11th ed.) Farrel (2024). Programming Logic and Design, 10th Edition. © 2024 Cengage.