CHAPTER 1

Introduction (Part 1)
CSC 128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
By: Umi Hanim Mazlan, FSKM

CONTENTS
‡ A Brief History of Computer and Programming Languages ‡ Introduction to Programming
What is a computer program Importance of computer program Importance of good program Relationship between compilers, interpreters, assemblers and programs

Objectives
‡ In this chapter you will :
Learn history of computer Learn about history and evolution of programming language Learn about programming Learn about importance of computer program Learn about the relationship between compilers, interpreters, assembler and program

Computer History ‡ The word computer was first used and recorded in 1613 ‡ Referring to a person who carried out calculations or computations ‡ From the end of 19th century onwards though the word began to take on its more familiar meaning. describing a machine that carries out computations .

Computer History ‡ Early digital computers: Zuse Z3 Atanasoff Berry Computer Collosus Harvard Mark I ± IBM ASCC ENIAC Manchester Small-Scale Experimental Machine EDSAC Manchester Mark 1 CSIRAC .

we must use a computer language Over the years computer languages have evolved form machine language to natural languages.Programming Languages History   To write a program for a computer. 1940s 1950s 1960s 1970s 1980s 1990s .

representing data as 1¶s and 0¶s. . much more user-oriented and allow users to develop programs with fewer commands compared with procedural languages . . ‡ 4th generation ‡ 5th generation .Very high-level language.Natural Language uses human language to give people a more natural connection with computers.Procedural languages.Machine Language is the basic language of the computer. FORTRAN.Programming Languages History ‡ 1st generation (low-level language) ‡ 2nd generation ‡ 3rd generation .Ex: COBOL. . NOMAD . .Ex: SQL. BASIC.Assembly language (low-level language) that allows a computer user to write a program using simple word instead of numbers.High-level language resembles some human language (English) .

Programming Languages Evolution ‡ Early computer were programmed in machine language ‡ To calculate wages = rates * hours in machine language : 100100 010001 100110 010010 100010 010011 //Load //Multiply //Store .

Programming Languages Evolution ‡ Assembly language instructions are mnemonic ‡ Assembler: translates a program written in assembly language into machine language .

wages = rates ‡ hours can be written as: LOAD MULT STOR rate hour wages .Programming Languages Evolution ‡ Using assembly language instructions.

cout cin cout cin << >> << >> ³Insert rates: ´. } . rates. int wages. wages = rates * hours. ³\nInsert hours : ´. cout << ³\nTotal wages :´ <<wages. int hours. return 0. hours.Programming Languages Evolution ‡ Using high level language instructions. wages = rates ‡ hours can be written as: #include <iostream.h> int main() { int rates.

.J. 2001) ‡ Programmable machine designed to follow instructions (Tony Gaddis. Deitel and P.. store data and generate the output ‡ Device capable of performing computations and making decisions at speeds millions and even billions of times faster than human being can (H.What is Computer? ‡ Computer is an electronic device that accept input.M. 2007) . processes data. Deitel.

Basic components of a computer systems Hardware  Device that processes data to create information (ex: input.  It¶s purpose to convert data to useful information . storage and processing devices) Software  Step-by-step instructions that tell the computer how to do its work. output.  It is also called a program.

Excel. ‡Eg. . Operating System APPLICATION SOFTWARE ‡ end user software. ‡Eg. Word. ‡A program that performs a common task to the user. ‡Enables the application software to interact with computer hardware.Basic components of a computer systems SOFTWARE SYSTEM SOFTWARE ‡ provides an environment for user to execute the application software.

Main Hardware Component Categories .

Central Processing Unit Function is to execute instructions. touch screen. such as arithmetic calculations. and movement of data inside the system . comparisons among data. pen/stylus. Ex: mouse. audio input unit ‡ CPU.Main Hardware Component Categories ‡ Input Devices Is usually a keyboard where programs and data are entered into the computer.

The data in primary storage are erased when you turn off a personal computer or you log off from a time-sharing computer ‡ Secondary Storage Devices It is the place where the programs and data are stored permanently .Main Hardware Component Categories ‡ Main memory/Primary Storage Is a place where the programs and data are stored temporarily during processing.

if it is printed on the printer.Main Hardware Component Categories When you turn off the computer. we say we have a hard copy. your programs and data remain in the secondary storage ready f0r the next time you need them Ex: Hard disk ‡ Output Devices Is usually a monitor or a printer where the output will be shown. If the output is shown on the monitor. Ex: monitor. we say we have a soft copy. printer .

g. Monitor. Hard disk. memory PROCESSING ‡Convert input data into information.g.g. ‡E. CPU OUTPUT ‡Generate the useful information using output devices ‡E. keyboard ‡Store the data or information for future use (permanently or temporarily) ‡E. Mouse. printer .Basic Operation in Computer System STORAGE INPUT ‡Whatever data that is inserted into a computer using input devices ‡E.g.

without programmers. >> SO. Ex: C++. C. without programs. VB ‡ Programming is the act of designing/writing and implementing computer programs using the programming languages.Computer Program ‡ Program is a set of instructions that the computer needs to follow to process the data into information. a computer cannot do anything . ‡ Programmer is a person who writes a computer program. ‡ Programming Language contains set of instructions. data and rules that are used to construct a program. no programs.

A skill required for a computer scientist and software engineering. .The Importance of Programming Easy to express tasks from a particular problem domain. Allow user to instruct computer to do a specific task in a certain instances. A skill required to create a successful computer program.

Good Programming Styles ‡ Reliability of Output Good program should produce correct output During testing phase different set of input data is used to ensure the reliability of output ‡ Program¶s Efficiency Good program should be reliable and efficient in the sense that it is produces no errors during execution process Program must achieve its purpose so that the final result can be trusted Use of pseudocode or flowchart to outline the program .

Good Programming Styles ‡ Interactivity Interaction between user and the program is well defined Interactivity is important so that the user knows the processing status User-friendly programs allow user to respond to the instructions correctly and allow them key in valid input ‡ Program readability Readability is concerned with how other person views one¶s program Use of indention and comment increase the level of readability .

Good Programming Styles ‡ Spacing Each instruction begins with new line ‡ Indent Each instruction has indention depends on its structure Makes the structure of the program clearer and easy to read A statement within a statement should be indented to show the user which statement is subordinate of the other .

Good Programming Styles ‡ Comments Help a human reader to understand the program Can be placed anywhere within a program Will not be executed by compiler C++ supports two types of comments x Line Comment x Block Comment .

Good Programming Styles ‡ Comments (Cont«) Line comment x Begin with two slashes (//) x Ex: //This is Line comment Block Comment x Begin with the symbol /* and end with the symbol */ x Use for statements that span across two or more lines x Ex: /* This program calculates the salary of employees */ .

} .Example // Programmer: Umi Hanim Mazlan /* Date : 19 July 2010 Title : Greeting program */ #include <iostream. indent return 0.h> int main() { --> spacing line comment block comment cout<< ³Hello world!\n´.

Program Errors ‡ Also known as bugs ‡ Debugger (software tool) ± trace through a program to find bugs (logic errors) ‡ Can be divided into: Compile-Time errors or syntax error x detect by compiler Run-Time errors or logic x is detected when the program is being running .

) in Line 1 Keyword cout is misspelled in Line 2 Invalid use of symbol (>>) in Line 2 Missing a closing quote( ´ ) in Line 2 .Program Errors (Cont«) ‡ Syntax errors Syntax error is an error in the structure or spelling of a statement Can be detected by compiler ‡ Example 1 2 cout << ³/n There are five syntax errors´ cot >> ³Correct Them. Invalid use of backslash (/) in Line 1 Missing semicolon (.

Program Errors (Cont«) ‡ Logic errors Refer to unexpected or unintentional errors resulted from some flaw in the program¶s logic Compiler cannot fix logic error Some indication of logic errors x x x x No output Unappealing or misaligned output Incorrect numerical results Premature program termination .

562. cout << ³\n the square root of ´ << num << ³ is ´ << sgrt(num). float total = 10. num = -4. average. count = 0. cout << ³Average is ³.0. Assigning invalid values to variable of type integer in Line 1 Attempting to divide by zero in Line 3 Missing numerical output in Line 4 Taking the square root of a negative number in Line 5 .Program Errors (Cont«) Logic errors (Cont«) Example 1 2 3 4 5 int radius = 4. average = total/count.

Compiler. There are Assembler.Language Translator  A program that accepts a human-readable source statements and produces machinereadable instructions. Interpreter. .

COMPILER ‡ a program that translates high-level language into machine language. COBOL INTERPRETER ‡ a program that translates source code of high-level language into machine language.Program Translator (Cont«) SOURCE CODE ‡ a program is a plain text written using any text editor ASSEMBLER ‡ a program that translates the assembly language program into machine language. ‡Eg. ‡Translate the source code once and saves to be reused. C++. ‡Eg. BASIC. PASCAL. ‡Requires less memory and runs faster. . ‡Program is easier to develop. ‡Each instruction is interpreted into machine language.

End of Chapter 1 (Part 1) .

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.