Document Details

Uploaded by Deleted User

Tags

programming concepts software development computer science technology

Full Transcript

CHAPTER 1 PROGRAMMING CONCEPTS To many people, computers may seem intelligent machines because they can do tasks efficiently and easily, but in actuality, they are just machines which will not do anything unless the tasks are specified by the user's using programs that are executed into them. A....

CHAPTER 1 PROGRAMMING CONCEPTS To many people, computers may seem intelligent machines because they can do tasks efficiently and easily, but in actuality, they are just machines which will not do anything unless the tasks are specified by the user's using programs that are executed into them. A. SOFTWARE - A computer program is a set of instructions that tells a computer what to do, collectively called Software. For complicated or large programs, say, the NEUST enrolment system, the program is consists of two sets of codes, the first are codes that instruct the computer, and the second set is consists of codes which contain data. The lists of instructions are called program codes and the process of typing these codes into a computer is called program coding or simply coding. B. PROGRAMMERS - The people who write program codes are called programmers. There are several types of programmers, namely: 1\. SYSTEM PROGRAMMERS - These are the people who create and maintain programs that are used to carry out the computer's basic operating functions like operating systems, utilities and device drivers. 2\. APPLICATION PROGRAMMERS - They are the ones who create and maintain programs that have specific functions such as Point Of Sale (POS) programs that calculate and generate the payroll report of a certain company, and others. TYPES OF APPLICATION PROGRAMMERS DATABASE APPLICATION PROGRAMMERS GAME DEVELOPERS WEB APPLICATION PROGRAMMERS MICRO DEVICES PROGRAMMERS C. HARDWARE - refers to the computer itself and other equipment or peripherals such as keyboard, mouse, monitor, central processing unit (CPU) and printer. These are the tangible components of the computer system which you can touch. D. PROBLEM SOLVING - Just like when writing a term paper, the first step in creating an effective program is proper thought and preparation. A programmer must first plan the way in which to solve the problem at hand and come up with the desired results. STEPS IN PROGRAMMING The five steps in the programming process are: A screenshot of a computer Description automatically generated 1\. PLANNING - The planning stage revolves around the identification of the problem and setting the processes by which these goals are to be achieved. 2\. ANALYSIS - In the analysis stage, you must determine the precise objectives of the solution to the problem. The material that the program generates is called OUTPUT. A FILE, which is stored by name, is a collection of information. A file may contain data, a program or some other document. PLANNING ANALYSIS DESIGN DEVELOPMENT TESTING & DEBUGGING DOCUMENTATION 3 After deciding what the output will be, you should determine the information that is needed to achieve your objectives. These data that the program requires to produce the desired results are called INPUT. Next will be to decide what will be the major steps required for processing the input to produce the output. A PROCESS is a mechanism for converting input to output. 3\. DESIGN - After analyzing the problem, we use this analysis to design a solution. You can use modeling tools to guide you in designing a solution to the problem. Examples of such tools are flowcharts and algorithms. 4\. DEVELOPMENT - In this step, you translate the design into a program. The process of writing computer instructions in a programming language is called CODING and all or part of the program is called CODE. 5\. TESTING AND DEBUGGING Testing the problem's solution on the computer overlaps with the design and development phases. When the computer follows the instructions in a program, we say that the machine EXECUTES or RUNS the program. You should carefully select test data for the program to cover as many situations as possible. Computer errors are also called BUGS. The process of correcting errors is referred to as DEBUGGING. DOCUMENTATION - In documentation, you provide materials that support the design, development, and testing of the program. The listing of your source code is a type of documentation, so are comments within the source code as well as user manuals. All the steps in programming require documenting for the purpose of reference. E. ELEMENTS OF PROGRAMMING - Almost all the programs are designed to solve problems. The design team is presented with the problem and from there, the requirements are determined in order to produce the desired output. The following are the elements of programming: 1\. INPUT - The necessary information is collected at the start of programming. This means getting the INPUT into the program. INPUT means reading values in from the keyboard, mouse, disk, CD-ROM, or from an I/O port. 2\. DATA - There should be a place to keep the input. These inputs are now called DATA. DATA are constants, variables, and structures that contain numbers, text, or addresses. 3\. OPERATIONS - The data are then applied with the correct OPERATIONS to manipulate it. The OPERATIONS can be assigning one value to a variable, constant or identifier, combining values using mathematical operations such as addition, subtraction, multiplication, division and modulo, and comparing values using relational operators like greater than, less than, equals and others. 4\. OUTPUT - The manipulated data will be extracted from the program and sent back to the user. This is called the OUTPUT. OUTPUT means writing information to the screen, printer, disk, or to an I/O port. 5\. CONDITIONAL EXECUTION - Data can also be manipulated using conditional execution or BRANCHING.CONDITIONAL EXECUTION refers to executing a set of instructions if a specified condition is TRUE (and skipping them or executing a different set if it is FALSE) or if a data item has a specified value or range of values. 6\. LOOPS - Data can also be manipulated using looping. LOOPS execute a set of instructions some fixed number of times while a condition evaluates to TRUE. When the condition evaluates to FALSE, the loop terminates. 7\. SUBROUTINES - Data are sometimes manipulated by breaking them into small pieces and are executed at different locations in the program. These are called subroutines. SUBROUTINES are separately named sets of instructions that can be executed anywhere in the program just by referencing the name. F. PROGRAMMING PARADIGMS - A programming paradigm is a fundamental style of computer programming. There are four different programming paradigms, namely: 1\. PROCEDURAL - the program is written as a collection of actions (a procedure) that are carried out in sequence, one after the other. The order is important. 2\. MODULAR - can be used to break up a large program into manageable units, or to create code that can be easily re-used. A modular program consists of a main module and one or more auxiliary modules. 3\. DATA ABSTRACTION - is a methodology that enables us to hide how a compound data object is used from the details of how it is constructed from more primitive data objects. 4\. OBJECT-ORIENTED PROGRAMMING -- A programming methodology that represents concepts as "objects" that have attributes and associated procedures known as methods. Objects, which are usually instances of classes, are used to interact with one another to design applications and computer programs. CHAPTER 3 PROGRAMMING LANGUAGES A. HISTORY 1\. Machine Language - The first computer programming language ever developed was the machine language. The machine language is written with binary digits, that is, 0s and 1s. This is the only language that can be executed by the computer, though it is very tedious and the tendency of making errors is extremely high. Machine language codes can only be written by expert low level programmers. 2\. Assembly Language - The assembly language is a slightly high-level language than the machine language. This programming language uses mnemonics. Mnemonics are memory aids which are abbreviated alphabetic instructions. The programmers developed this language so that they can easily understand their programs as compared to the ones they wrote using machine language. Since the computer can only execute machine language, the programs written in assembly language should be translated into machine language using another program called the assembler. 3\. High-level Language - The high-level language is a program written in English words that even common people can understand. Most of the programming languages today like C language, C++, Java and others are high-level languages. For the computer to understand and execute a program written in high-level language, it should first be compiled by a compiler program into object code and then combined into a single executable program using a linker. B. TYPES OF HIGH-LEVEL PROGRAMS 1. Procedure-oriented programs - When you say procedure-oriented, the program is focused on its step by step process of solving a given problem. Examples: 2. Object-oriented programs - The object-oriented program focuses on transforming real-life objects into its digital representation. Examples of objects in programming are text boxes, frames, check boxes, buttons and combo boxes. 1. Sequence Structure - In the Sequence Structure, the statements are executed in the order that they appear in the program. All programs use this type of structure, although it can be embedded with the other two control structures. EXAMPLE: Make an algorithm that will show the process by which a Grade I student does his daily routine from the time he wakes up to the time he goes to school. SOLUTION: 1\. Wake up early. 4. Take a shower. 2\. Eat breakfast. 5. Put on his uniform. 3\. Brush his teeth. 6. Go to school. 2. Selection Structure In the Selection Structure, the program chooses which alternative it will take and execute the statement or block of statements based on the answer to the comparison expression. It is also called the DECISION STRUCTURE. EXAMPLE: From the previous example, make a selection structure in the part where the Grade I student is putting on his uniform. Every Wednesday is PE day, so the algorithm includes a selection statement that will make him put on his PE uniform on a Wednesday. SOLUTION: 1\. Wake up early. 2\. Eat breakfast. 3\. Brush his teeth. 4\. Take a shower. 5\. If (today is Wednesday) Put on his PE uniform else Put on his school uniform end if 6\. Go to school. 3. Repetition Structure The Repetition Structure is sometimes called LOOPING. In this structure, the statement or block of statements are repeated a number of times depending on the limit set by the program. EXAMPLE: Make the algorithm above show that the process of going to school will be repeated 5 times to cover the 5 school days of the week. SOLUTION: 1\. Repeat 5 times Wake up early. Eat breakfast. Brush his teeth. Take a shower. If (today is Wednesday) Put on his PE uniform else Put on his school uniform end if Go to school. end repeat D. FLOWCHART - Flowchart is a visual representation of a program. It is used as a guide for making computer programs. The table below lists the commonly used flowcharting symbols and their corresponding functions. ![A screenshot of a computer Description automatically generated](media/image2.png) A screenshot of a computer Description automatically generated Notice that only the text inside the double quotations is printed. The quotation marks are not displayed on the screen. Whatever form the text inside the quotation marks takes, the same will be displayed on the screen. The letters HLLWRL are displayed in capital letters while the letters eood are in small letters. This process is coined as WYSIWYG (What You See Is What You Get). Notice also that the cursor (represented by \_) is displayed after the last symbol printed on the screen. It is where the next symbol will be printed. If you want the succeeding symbols to be printed on the next line, you should print a newline so that the cursor will go to the next line instead of to the right of the last printed symbol. ![](media/image4.png) In this example, the first print statement (Dayle Xylia F. Florentino) was displayed on the screen, then a newline was printed, so the cursor transferred to the next line. The third print statement (16 years old) was displayed on the screen. A newline was next printed so at the end of the output, the cursor appeared on the next line of the last printed line. In this flowchart, variable age was first declared. Then, the prompt (My age is:) is displayed on the screen. The user entered 16 and the value was stored in variable age. 16 was compared to 18 (is age \< 18?). Since the result is yes, the message (You are too young to drink!!!) was displayed and the cursor remained after the last printed character. CHAPTER 4 C++ PROGRAMMING Using a compiler, a program written in a high level language, such as C++, is compiled into object code, which is the only code that the computer can understand. However, going from an idea to a program that works successfully takes a lot of time and effort. Therefore, students should learn a disciplined approach in coding and learn how to simulate programs so that they will know the flow of the program and the output it will give even before the code is executed. Step by step tracing of the code is necessary so that you may know precisely where errors are occurring. This process is called debugging. A debugger is a tool that helps programmers trace programs and find probable causes of errors. It cannot correct the errors in your program. It only assists the programmer find errors while in the process of programming. The graphically based debugger environment is a part of the Integrated Development Environment (IDE). Code::Blocks is an open source free IDE which is used for C++ Programming. It has a text editor and a compiler. It will allow you to create and test your programs from an easy to use development environment. The structure of a C++ program is shown below. \#include \ \#include \ using namespace std; int main() { statement\_1; statement\_2; : : statement\_n; } A. OPENING Code::Blocks 1. From the desktop, look for the Code::Blocks icon. Double click the icon. (If you cannot find the Code::Blocks icon in the desktop, you can click the START button and then look for Code::Blocks and click it). ![A screenshot of a computer Description automatically generated](media/image6.png) A screenshot of a computer Description automatically generated ![](media/image7.png) 2. Click the File Menu from the Menu bar and then, click New, and proceed to clicking Project. You will be presented with a new window like the one below. 3. Choose Console Application by double clicking its icon. Your screen will now look like this Figure: ![](media/image9.png) 4. Choose C++ and then, click Next 5\. Type the title of the project (example, LabEx1) and then, click Next. The figure below will be your next screen. ![](media/image11.png) 6\. Click Finish. You will now be presented with the Code::Blocks Editor screen. A screenshot of a computer Description automatically generated B. OPENING Code::Blocks TEXT EDITOR From the Code::Blocks Screen, click Projects on the Management Area, then find the file you have created, double click Sources, then double click main.cpp. The Work Area will display the basic structure of a simple C++ program. You can erase the unnecessary statements in the given program or you can completely erase all the data and create your own program. To familiarize yourself in creating a C++ program, erase the data completely. Type this simple program, following the structure as you can see it. EXAMPLE OF A SIMPLE C++ PROGRAM \#include \ \#include \ using namespace std; int main() { cout\

Use Quizgecko on...
Browser
Browser