Problem Solving and Program Design in C Chap. 1 Overview of Computers and Programming Chow-Sing Lin
Computers Computer Technology is everywhere!! – Virtually every aspect of your life depends on computers. The computer program’s role in this technology is essential – Without a list of instructions to follow, the computer is virtually useless. One of the most versatile programming languages available today the C language Dr. Chow-Sing LinProgram Design I - CH12
Electronic Computers Then and Now The First Computer built in 1930s by Dr. John Atanasoff and Dr. Clifford Berry at Iowa State University. (ABC) – Atanasoff-Berry-Computer (ABC) – Used in nuclear physics with mathematical computations Dr. Chow-Sing LinProgram Design I - CH13
ABC Dr. Chow-Sing LinProgram Design I - CH14
ENIAC The first large-scale, general-purpose electronic digital computer – ENIAC – Electronic Numerical Integrator and Computer – Built in 1946 at the Univ. of Pennsylvania with funding from the U.S. army. – Used to compute ballistics tables, predict the weather, make atomic energy calculations – Weight :30 tons; Space: 30 x 50 ft 2 Used vacuum tubes as their basic electronic component. Dr. Chow-Sing LinProgram Design I - CH15
ENIAC Dr. Chow-Sing LinProgram Design I - CH16
Electronic Technology advance Technological advances in the design and manufacture of electronic components led to new generations of computers – Smaller, faster, and less expensive Nowadays, the entire circuitry of a computer processor can be packaged in a single electronic component, microprocessor chip Dr. Chow-Sing LinProgram Design I - CH17
Dr. Chow-Sing LinProgram Design I - CH18 Figure 1.1 The Intel Atom processor chip contains the full circuitry of a central processing unit in an integrated circuit whose small size and low power requirements make it suitable for use in mobile internet devices. (Intel Corporation Pressroom Photo Archives)
Computer Category Modern computers are categorized according to their size and performance – Personal computers Used by a single person at a time – Mainframes Large real-time transaction processing systems – Supercomputers The largest capacity and fastest mainframes Intensive computation applications Dr. Chow-Sing LinProgram Design I - CH19
Dr. Chow-Sing LinProgram Design I - CH Figure 1.2 (a) Notebook Computer (HP Pavilion dv5©, Courtesy of Hewlett-Packard). (b) Palmtop Computer (iPhone 3G©, Courtesy of Apple, Inc.) (c) Desktop Computer (iMac©, Courtesy of Apple, Inc.)
Elements of Computer System Hardware – Perform the necessary computations Central processing unit, monitor, keyboard, mouse, printer, speakers Processing data represented only by 0 and 1 (binary numbers) Software – Programs to solve problems with a computer by providing it with lists of instructions to perform Dr. Chow-Sing LinProgram Design I - CH111
Computer Hardware Main Memory Secondary Memory – Hard disks, floppy disk, DVDs, …. Central Processing Unit Input Devices – Keyboards, mouses, touch pads, …. Output Devices – Monitors, printers, and speakers Dr. Chow-Sing LinProgram Design I - CH112
Component of a Computer Dr. Chow-Sing LinProgram Design I - CH113
Memory Imagine the memory of a computer as an ordered sequence of storage locations memory cells To store and access information, the computer use an unique address to identify the individual cell. Data and programs are stored in the memory cells – Stored program concept: a program’s instruction must be stored in main memory before they can be executed. Dr. Chow-Sing LinProgram Design I - CH114
Memory Layout Dr. Chow-Sing LinProgram Design I - CH115 Figure Memory Cells in Main Memory
Byte and Bit 0 and 1 one bit 8 bits 1 byte one character Dr. Chow-Sing LinProgram Design I - CH116
Main Memory RAM(random access memory) – Temporary storage of programs and data – Volatile memory Everything in RAM will be lost when the computer is switched off ROM(read-only memory) – Store read-only information permanently within the computer – Not volatile – Store start-up instructions and other critical instructions Dr. Chow-Sing LinProgram Design I - CH117
Secondary Memory Computer systems provide storage in addition to main memory for two reasons: 1.Computers need storage permanent or semi- permanent so that information can retained during a power loss or when the computer is turn off. 2.Systems typically store more information than will fit in memory. Hard disk, DVD, magnetic tape, ….. Dr. Chow-Sing LinProgram Design I - CH118
Central Processing Unit Play two roles – Coordinating all computer operations – Performing arithmetic and logical operations on data To Process a program stored in main memory, – the CPU retrieves (fetch) each instruction in sequence, interprets the instruction, and then retrieves any data needed to carry out that instruction. – Execute, and store the result back to memory Dr. Chow-Sing LinProgram Design I - CH119
Computer Network Link computers together to communicate with one another Dr. Chow-Sing LinProgram Design I - CH120 LAN, Local Area NetworkWAN, Wide Area Network
Operating System A middleware (program) between computer hardware and users – Loading the operating system into memory is called booting the computer Operating System is responsible for – Communicate with the computer users – Managing allocation of memory, processor time, and other resources for tasks – Collecting input from other input devices (mouse..) – Conveying program out to other output devices (screen..) – Access/writing data from/to secondary storage Dr. Chow-Sing LinProgram Design I - CH121
Application Software Application software is running on top of the operating system – Microsoft office – Google Chrome – Photoshop – ….. Dr. Chow-Sing LinProgram Design I - CH122
Computer Languages Machine language – Binary code , , …. – hardly readable by human – CPU dependent Assembly language – More readable, but still hard to learn CLA, ADD A, STA A, …. – One assembly instruction corresponding to one machine language Dr. Chow-Sing LinProgram Design I - CH123
Table 1.3 A machine language program fragment and its assembly language equivalent Memory AddressesMachine Language Instructions Assembly Language Instructions CLA ADD A ADD B STA A HLT ?A ? ?B ? Dr. Chow-Sing LinProgram Design I - CH124
Computer language (cont’) Write code, run any platform CPU- independent high-level language High-level language – Combine algebraic expressions and symbols taken from English Table 1.3 can be replaced by a single high-level language a = a + b ; C, C++, Java, php, C#, Python, …… Dr. Chow-Sing LinProgram Design I - CH125
Computer language(cont’) High-level language must be translated into the target computer machine language Source file object file executable file RUN Dr. Chow-Sing LinProgram Design I - CH126
Dr. Chow-Sing LinProgram Design I - CH127 Figure 1.12 Entering, Translating, and Running a High-Level Language Program
Figure 1.13 Flow of Information During Program Execution Dr. Chow-Sing LinProgram Design I - CH128
The Software Development Method 1.Specify the problem requirement – State the problem clearly and unambiguously and to gain a clear understanding of what is required for its solution. 2.Analyze the problem – Identify the problem Input Output Additional requirement and constraints on the solution Dr. Chow-Sing LinProgram Design I - CH129
The Software Development Method (cont’) 3.Design the algorithm to solve the problem – Develop a list of steps called an algorithm to solve the problem and to then verify that the algorithm solves the problem as intended. – Writing the algorithm is often the most difficult part of the problem-solving process. – List the major steps, and then refine. – Desk check!! 4.Implement the algorithm – Converting each algorithm step into one or more statements in a programming language, such as C. Dr. Chow-Sing LinProgram Design I - CH130
The Software Development Method (cont’) 5.Test and verify the completed program – Testing the completed program to verify that it works as desired. – Run the program several times using different sets of data to ensure its correctness in every aspects. 6.Maintain and update the program – Modifying a program to remove previously undetected errors – keep it up-to-date as government regulations or company policies change. Dr. Chow-Sing LinProgram Design I - CH131
Failure is part of the process !! Debugging !! Dr. Chow-Sing LinProgram Design I - CH132
Dr. Chow-Sing LinProgram Design I - CH133 Figure 1.14 Miles-to-Kilometers Conversion Program
Be sure to read the Chapter Review at the end of each chapter and understand the listed topics ! Do as many implementation exercises as possible ! Dr. Chow-Sing LinProgram Design I - CH134