Home
Introduction to Computers and Programming∗
Contents
1. 3 1 1 1 Analyze the problem This step is required to ensure that the problem is clearly defined and understood The person doing the analysis has to analyze the problem requirements in order to understand what the program must do what outputs are required and what inputs are needed Understanding the problem is very important Do not start to solve the problem until you have understood clearly the problem 3 1 2 2 Develop a Solution Programming is all about solving problems In this step you have to develop an algorithm to solve a given problem Algorithm is a sequence of steps that describes how the data are to be processed to produce the desired outputs An algorithm should be at least complete i e cover all the parts unambiguous no doubt about what it does finite it should finish 3 1 3 3 Code the solution This step consists of translating the algorithm into a computer program using a programming language 3 1 4 4 Test and correct the program This step requires testing of the completed computer program to ensure that it does in fact provide a solution to the problem Any errors that are found during the tests must be corrected Figure below lists the relative amount of effort that is typically expended on each of these four development and design steps in large commercial programming projects Analyze the problem 10 Develop a solution 20 Code the solution 20 Test and correct the program 50 F
2. Predefined process al Figure 5 Flowchart symbols The meaning of each flowchart symbol is given as follows http cnx org content m27277 1 1 OpenStax CNX module m27277 10 Indicates the beginning or end of an algorithm Indicates an input or output operation Indicates computation or data manipulation Connects the flowchart symbols and indicates the logic Terminal Input Output Process Flow lines Decision Connector Predefined process flow Indicates a program branch point Indicates an entry to or exit from another part of the flowchart or a connection point Indicates a predefined process as in calling a function Figure 6 Description of flowchart symbols To illustrate an algorithm we consider the simple program that computes the pay of a person The flowchart for this program is given in the Figure below Note Name Hours and Pay are variables in the program http cnx org content m27277 1 1 OpenStax CNX module m27277 11 Input Name Hours Rate Calculate Pay lt Hours x Rate Figure 7 A sample flowchart 4 2 Algorithms in pseudo code You also can use English like phases to describe an algorithm In this case the description is called pseu docode Pseudocode is an artificial and informal language that helps programmers develop algorithms Pseudocode has some ways to represent sequence decision and repetition in algorithms A carefully pre pared pseudocode can b
3. calculations and tells the output unit when to send information from the memory unit to certain output devices 1 1 6 Secondary Storage Secondary storage devices are used to be permanent storage area for programs and data Virtually all secondary storage is now done on magnetic tapes magnetic disks and CD ROMs A magnetic hard disk consists of either a single rigid platter or several platters that spin together on a common spindle A movable access arm positions the read and write mechanisms over but not quite touching the recordable surfaces Such a configuration is shown in Figure 2 giidi arm assembly roiaiion Figure 2 The internal structure of a magnetic hard disk drive 1 2 Computer Software A computer program is a set of instructions used to operate a computer to produce a specific result Another term for a program or a set of programs is software and we use both terms interchangeably throughout the text Writing computer programs is called computer programming The languages used to create computer programs are called programming languages To understand C programming it is helpful to know a little background about how current program ming languages evolved http cnx org content m27277 1 1 OpenStax CNX module m27277 4 1 2 1 Machine and Assembly Languages Machine languages are the lowest level of computer languages Programs written in machine language consist of entirely of 1s and Os Progr
4. The procedures associated with an object are referred as functions or methods Variables that are associated with an object are referred to as properties or attributes Object oriented programming allows programmers to use programming objects that they have written themselves or that have been written by others 3 Problem Solution and Software Development No matter what field of work you choose you may have to solve problems Many of these can be solved quickly and easily Still others require considerable planning and forethought if the solution is to be appropriate and efficient Creating a program is no different because a program is a solution developed to solve a particular problem As such writing a program is almost the last step in a process of first determining what the problem is and the method that will be used to solve the problem One technique used by professional software developers for understanding the problem that is being solved and for creating an effective and appropriate software solution is called the software development procedure The procedure consists of three overlapping phases Development and Design Documentation Maintenance As a discipline software engineering is concerned with creating readable efficient reliable and main tainable programs and systems 3 1 Phase I Development and Design The first phase consists of four steps http cnx org content m27277 1 1 OpenStax CNX module m27277 7
5. OpenStax CNX module m27277 1 INTRODUCTION TO COMPUTERS AND PROGRAMMING Dr Duong Tuan Anh This work is produced by OpenStax CNX and licensed under the Creative Commons Attribution License 3 0t Abstract This chapter discusses what computers are how they work and how they are programmed This chapter also includes an introduction to problem solving and program development 1 Hardware and Software A computer is a device capable of performing computations and making logical decisions at speeds millions and even billions of times faster than human beings can For example many of today s personal computers can perform hundreds of millions of additions per second Computers process data under the control of sets of instructions called computer programs These computer programs guide the computer through orderly sets of actions specified by people called computer programmers A computer is comprised of various devices such as the keyboard screen mouse disks memory CD ROM and processing units that are referred to as hardware The computer programs that run on a computer are referred to as software 1 1 Computer Hardware Almost every computer may be seen as being divided into six logical units Figure 1 illustrates the main computer components 1 1 1 Input Unit This unit obtains information from various input devices and places this information at the disposal of the other units so that the information may be processed Th
6. ams in machine language can control directly to the computer s hardware 00101010 000000000001 000000000010 10011001 000000000010 000000000011 A machine language instruction consists of two parts an instruction part and an address part The instruction part opcode is the leftmost group of bits in the instruction and tells the computer the operation to be performed The address part specifies the memory address of the data to be used in the instruction Assembly languages perform the same tasks as machine languages but use symbolic names for opcodes and operands instead of 1s and Os LOAD BASEPAY ADD OVERPAY STORE GROSSPAY Since computers can only execute machine language programs an assembly language program must be translated into a machine language program before it can be executed on a computer Assembly Translation Machine language program language program assembler program Figure 3 Assembly translation Machine languages and assembly languages are called low level languages since they are closest to com puter hardware 1 2 2 High level Programming Languages High level programming languages create computer programs using instructions that much easier to under stand than machine or assembly language instructions Programs written in a high level language must be translated into a low level language using a program called a compiler A compiler translates programming code into a low level format High leve
7. art in Figure above to understand the meaning of the do while construct used in the pseudo code 4 4 Flowchart versus pseudocode Since flowcharts are inconvenient to revise they have fallen out of favor by programmers Nowadays the use of pseudocode has gained increasing acceptance Only after an algorithm has been selected and the programmer understands the steps required can the algorithm be written using computer language statements The writing of an algorithm using computer language statements is called coding the algorithm which is the third step in our program development process http cnx org content m27277 1 1
8. at software development was a far more complex activity than they had imagined Research activity in the 1960s resulted in the evolution of structured programming a discipline approach to writing programs that are clearer than unstructured programs easier to test and debug and easier to modify Chapter 5 discusses the principles of structured programming Chapters 2 through 6 develop many structured programs One of the more tangible results of this research was the development of the Pascal programming lan guage by Niklaus Wirth in 1971 Pascal was designed for teaching structured programming in academic environments and rapidly became the preferred programming languages in most universities In the 1980s there is a revolution brewing in the software community object oriented programming Objects are essentially reusable software components that model items in the real world Software developers are discovering that using a modular object oriented design and implementation approach can make software development groups much more productive than with previous popular programming techniques such as structured programming Object oriented programming refers to the creation of reusable software objects that can be easily in corporated into another program An object is programming code and data that can be treated as an individual unit or component Data refers to information contained within variables constants or other types of storage structures
9. e converted easily to a corresponding C program Example The following set of instructions forms a detailed algorithm in pseudocode for calculating the payment of person http cnx org content m27277 1 1 OpenStax CNX module m27277 12 Input the three values into the variables Name Hours Rate Calculate Pay Hours U FOB4 Rate Display Name and Pay 4 3 Loops in Algorithms Many problems require repetition capability in which the same calculation or sequence of instructions is repeated over and over using different sets of data Example 1 1 Write a program to do the task Print a list of the numbers from 4 to 9 next to each number print the square of the number The flowchart for the algorithm that solves this problem is given in Figure below You will see in this figure the flowchart symbol for decision and the flowline that can connect backward to represent a loop http cnx org content m27277 1 1 OpenStax CNX module m27277 Figure 8 SQNUM lt NUM Print NUM SONUM NUM lt NUM 1 Flowcharts of example 1 1 Note http cnx org content m27277 1 1 OpenStax CNX module m27277 14 1 In the flowchart the statement NUM NUM 1 means old value of NUM 1 becomes new value of NUM The above algorithm can be described in pseudocode as follows NUM 4 do SQNUM NUM NUM Print NUM SQNUM NUM NUM 1 while NUM lt 9 You can compare the pseudo code and the flowch
10. e information is entered into computers today through keyboards and mouse devices 1 1 2 Output Unit This unit takes information that has been processed by the computer and places it on various output devices to make information available for use outside the computer Most output from computer today is displayed on screens printed on paper or used to control other devices Version 1 1 Jul 7 2009 1 04 am 0500 thttp creativecommons org licenses by 3 0 http cnx org content m27277 1 1 OpenStax CNX module m27277 2 1 1 3 Memory Unit The memory unit stores information Each computer contains memory of two main types RAM and ROM RAM random access memory is volatile Your program and data are stored in RAM when you are using the computer Central processing unit Secondary Memory storage Figure 1 Basic hardware units of a computer ROM read only memory contains fundamental instructions that cannot be lost or changed by the user ROM is non volatile 1 1 4 Arithmetic and Logic Unit ALU The ALU performs all the arithmetic and logic operations Ex addition subtraction comparison etc 1 1 5 Central Processing Unit CPU The unit supervises the overall operation of the computer The CPU tells the input unit when information should be read into the memory unit tell the ALU when information from the memory should be used in http cnx org content m27277 1 1 OpenStax CNX module m27277 3
11. he 1980s C compilers were written for other platforms including PCs To provide a level of standardization for C language in 1989 ANSI created a standard version of C that is called ANSI C One main benefit of the C language is that it is much closer to assembly language other than other types of high level programming languages The programs written in C often run much faster and more efficiently than programs written in other types of high level programming language 2 3 The C Programming Language C is an extension of C that adds object oriented programming capabilities C is a popular program ming language for writing graphical programs that run on Windows and Macintosh http cnx org content m27277 1 1 OpenStax CNX module m27277 6 The standardized version of C is commonly referred to as ANSI C The ANSI C and ANSI C standards define how C C code can be written The ANSI standards also define run time libraries which contains useful functions variables con stants and other programming items that you can add to your programs The ANSI C run time library is also called the Standard Template Library or Standard C Library 2 4 Structured Programming and Object Oriented Programming During the 1960s many large software development effects encountered severe difficulties Software schedules were typically late costs greatly exceeded budgets and finished products were unreliable People began to realize th
12. igure 4 Four development and design steps in commercial programming projects 3 2 Phase II Documentation Documentation requires collecting critical documents during the analysis design coding and testing There are five documents for every program solution e Program description e Algorithm development and changes e Well commented program listing http cnx org content m27277 1 1 OpenStax CNX module m27277 8 e Sample test runs e User s manual 3 3 Phase III Maintenance This phase is concerned with the ongoing correction of problems revisions to meet changing needs and the addition of new features Maintenance is often the major effort and the longest lasting of the three phases While development may take days or months maintenance may continue for years or decades 4 Algorithms An algorithm is defined as a step by step sequence of instructions that describes how the data are to be processed to produce the desired outputs In essence an algorithm answers the question What method will you use to solve the problem You can describe an algorithm by using flowchart symbols By that way you obtain a flowchart which is an outline of the basic structure or logic of the program 4 1 Flowchart Symbols To draw flowchart we employ the symbols shown in the Figure below http cnx org content m27277 1 1 OpenStax CNX module m27277 Input output S Flow lines y f __ _ Decision Connector
13. l languages allow programmers to write instructions that look like every English sentences and commonly used mathematical notations Each line in a high level language program is called a statement Ex Result First Second Third Once a program is written in a high level language it must also be translated into the machine language of the computer on which it will be run This translation can be accomplished in two ways http cnx org content m27277 1 1 OpenStax CNX module m27277 5 When each statement in a high level source program is translated individually and executed immediately upon translation the programming language used is called an interpreted language and the program doing the translation is called an interpreter When all of the statements in a high level source program are translated as a complete unit before any one statement is executed the programming language used is called is called a compiled language In this case the program doing the translation is called a compiler 1 2 3 Application and System Software Two types of computer programs are application software and system software Application software consists of those programs written to perform particular tasks required by the users System software is the collection of programs that must be available to any computer system for it to operate The most important system software is the operating system Examples of some well known operating systems i
14. nclude MS DOS UNIX and MS WINDOWS Many operating systems allow user to run multiple programs Such operating systems are called multitasking systems Beside operating systems language translators are also system softwares 2 High Level Programming Languages Because of the difficulty of working with low level languages high level languages were developed to make it easier to write computer programs High level programming languages create computer programs using instructions that are much easier to understand than machine or assembly language code because you can use words that more clearly describe the task being performed Examples of high level languages include FORTRAN COBOL BASIC PASCAL C C and JAVA C and C are two separate but related programming languages In the 1970s at Bell Laboratories Dennis Ritchie and Brian Kernighan designed the C programming language In 1985 at Bell Laboratories Bjarne Stroutrup created C based on the C language C is an extension of C that adds object oriented programming capabilities 2 1 What is Syntax A programming language s syntax is the set of rules for writing grammatically correct language statements In practice this means a C statement with correct syntax has a proper form specified for the compiler As such the compiler accepts the statement and does not generate an error message 2 2 The C Programming Language C was used exclusively on UNIX and on mini computers During t
Download Pdf Manuals
Related Search
Related Contents
「ラーラ松本等」指定管理業務 仕様書 Pour commencer, un peu de vocabulaire Les sigles et Manual DESINFECCIÓN AMBIENTAL D-Link DCS-900 Network IP Camera importante Les huiles essentielles et leur usage en milieu 取扱説明書 - デイトナ Technische Beschreibung rotoScan ROD-4 Copyright © All rights reserved.
Failed to retrieve file