BITG 1113: Introduction To Computers And Programming Language LECTURE 1 LECTURE 1 1
Learning Outcomes At the end of this lecture, you should be able to: tell the purpose of computer programs. describe the hardware and software components of a computer system. tell about the language of a computer. describe the evolution of programming languages. list high-level programming languages. LECTURE 1 2
Learning Outcomes (cont.) At the end of this lecture, you should be able to: tell about the history of C++ language. recognize a C++ program. explain how a C++ program is processed and tested. explain what compiler, linker and loader are and what they do. explain the different types of program errors. recognize the Professional Ethics for Computer Programmers. LECTURE 1 3
Why Program? Computer programmable machine designed to follow instructions. Program a set of instructions for a computer to follow. Programmer person who writes instructions (program) to make computer perform a task. SO, without programmers, no program; without program, a computer cannot do anything. LECTURE 1 4
Computer Components Computer is an electronic device, with two major components. Computer Hardware Software LECTURE 1 5
Computer Hardware Hardware refers to the physical parts of the computer that have mass (they can be touched). Hardware for a typical computer system include the following FIVE main categories : 1. Central Processing Unit (CPU) 2. Main Memory / Primary Storage / Internal Memory 3. Secondary Storage / Auxiliary Storage / External Memory 4. Input Devices 5. Output Devices LECTURE 1 6
Main Hardware Component Categories LECTURE 1 7
Central Processing Unit (CPU) Processor; Brain of the computer. Comprised of: Control Unit (CU) Retrieves, decodes and executes program instructions from RAM Coordinates activities of all other parts of computer Arithmetic & Logic Unit (ALU) Hardware optimized for high-speed numeric calculation Hardware designed for true/false, yes/no decisions LECTURE 1 8
CPU Organization LECTURE 1 9
Main Memory Main memory stores instructions and data while a program is running. It is volatile. Main memory is erased when program terminates or computer is turned off. Also called Random Access Memory (RAM) Consists of long list of memory locations Each contains zeros and ones Can change during program execution Each memory location is called a byte. It has eight bits. Binary Digit or Bit : A digit that can only be zero or one. Data and instructions (programs) are kept as binary digits. Address : A unique number that identifies a memory location. LECTURE 1 10
LECTURE 1 11
Main Memory Some data is too large for a single byte. Most integers and real numbers are too large. Next few consecutive bytes can store the additional bits for larger data. Address refers to the first byte. LECTURE 1 12
Main Memory LECTURE 1 13
Secondary Storage Secondary memory stores instructions and data between sessions Non-volatile: data is preserved when program is not running, or computer is turned off. Comes in a variety of media: magnetic: floppy disk drive (FDD), hard disk drive (HDD), magnetic tape drive optical: Compact Disc (CD), Digital Video Disc (DVD) flash memory : USB Flash drive LECTURE 1 14
Input Devices Devices that are sources to get input. Input is the information sent to the computer from the outside. Input consists of: A program Some data Many devices can provide INPUT: Keyboard, mouse, scanner, digital camera, microphone, barcode reader, joystick HDD, FDD, flash drive, magnetic tape, CD-ROM LECTURE 1 15
Output Devices Devices that send output. Output is information from the computer to the outside world. Many devices can be used for OUTPUT: Computer monitor, printer, projector, speaker, headphone, plotter HDD, FDD, flash drive, magnetic tape, CD-RW, DVD-RW LECTURE 1 16
LECTURE 1 17
Computer Software Software: refers to program that resides and executes electronically on the hardware. Software is divided into 2 categories Software System Software Application Software LECTURE 1 18
System Software Normally supplied by the manufacturer of the computer. Software that manages computer hardware resources, and the programs that run on them. Basic types of system software: BIOS, operating systems, utility programs, software development tools. The operating system is the most important type of system software. Without it, a user cannot run an application program on their computer, unless the application program is self booting. LECTURE 1 19
Operating System The operating system: Allows us to communicate with the computer Is a program Allocates the computer s resources Responds to user requests to run other programs Common operating systems include: UNIX Linux DOS Windows Macintosh VMS LECTURE 1 20
Application Software Programs that provide services (problem solution) to the user. Designed to perform a specific task (e.g. : course registration system, banking system) OR a generalpurpose task (e.g. : word processing, games). May be acquired by purchasing off-the-shelf or by designing for own purpose (custom made). Off-the-shelf : Prewritten and ready to use. For general-purpose task. Custom made : Written by in-house, consulting firm or software house. For specific task. LECTURE 1 21
Where are the application and system software? LECTURE 1 22
The Language of a Computer Machine language: language of a computer. Consists of binary digits (bits); sequences of 0s and 1s. 0 (signal off), 1 (signal on) Example : 1011010000000101 LECTURE 1 23
History Of Computer Languages Computer language evolution The only language understood by a computer is machine language LECTURE 1 24
History Of Computer Languages (cont.) 1. Machine Language Computer only understand this language. Series of 1 s and 0 s (binary numbers), such as 1011010000000101 Difficult to write. Low level language LECTURE 1 25
History Of Computer Languages (cont.) Early computers were programmed in machine language To calculate wages = rates * hours in machine language: 100100 010001 //Load 100110 010010 //Multiply 100010 010011 //Store LECTURE 1 26
History Of Computer Languages (cont.) 2. Symbolic/Assembly Language Unique to particular computer. Use mnemonics symbols. E.g. MUL Multiply Easier to understand. LECTURE 1 27
History Of Computer Languages (cont.) Using assembly language instructions, wages = rates x hours can be written as: LOAD rate MULT hours STOR wages Must be translated to machine language (zeros and ones) for the CPU to execute a program written in assembly language. LECTURE 1 28
History Of Computer Languages (cont.) 3. High-Level Language Are designed to be easy to read and write. Programmers use this language to write programs. Compiler: translates a program written in a high-level language to machine language Portable to many different computers. E.g. COBOL, FORTRAN, Visual Basic, Pascal, C, C++, C#, Java, Lisp, Ada The equation wages = rate x hours can be written in C++ as: wages = rate * hours; LECTURE 1 29
Some Well-Known High-Level Programming Languages LECTURE 1 30
History Of Computer Languages (cont.) 4. Natural Language Like our natural language (such as English, French, or Chinese) Its use is still quite limited. LECTURE 1 31
Programs and Programming Languages Types of languages: High-level: closer to human language Low-level: used for communication with computer hardware directly. Often written in binary machine code (0 s/1 s) directly. LECTURE 1 32
C++ evolved from C C++ History C++ designed by Bjarne Stroustrup at Bell Laboratories in early 1980s Overcame several shortcomings of C Incorporated object oriented programming C remains a subset of C++ C++ programs were not always portable from one compiler to another In mid-1998, ANSI/ISO C++ language standards were approved LECTURE 1 33
A simple C++ program begins this way #include <iostream> using namespace std; int main() { And ends this way } A Sample of C++ Program return 0; LECTURE 1 34
Example of a C++ Program #include <iostream> using namespace std; int main() { cout << "My first C++ program." << endl; cout << "The sum of 2 and 3 = " << 5 << endl; cout << "7 + 8 = " << 7 + 8 << endl; return 0; } Output of a sample Run : My first C++ program. The sum of 2 and 3 = 5 7 + 8 = 15 LECTURE 1 35
Program Development A computer understands a program only if the program is coded in its machine language. Programmer have to write the program and turn it into an executable code (machine language). Programmer have to understand the problem -> break into actions (write program)-> execute by the computer. LECTURE 1 36
From a High-level Program to an Executable Code Involves these processes: a) Editing : To create or edit file containing the program (source code) with a text editor. b) Compiling : The process involves the compiler. The compiler is actually two separate programs : preprocessor and translator. Firstly, preprocessor is run to convert source file directives (instructions that begin with #) to source code program statements. Secondly, the translator checks that the program obeys the rule. If all the rules are being obeyed, the translator convert the source code into machine language (object code). The two steps, are often performed by command COMPILE. Syntax errors detected will prevent execution of the following process. c) Linking : Run linker to connect system library functions code to the object code, producing an executable code. Performed by command BUILD. LECTURE 1 37
From a High-level Program to an Executable Code Programmer Programmer Code Programmer Code Executable Code LECTURE 1 38
Program Development (cont.) Then, after that to produce the result (output) of the program, there are another 2 processes : Loading : Loader loads the executable code/program into the main memory (RAM) Executing: The last step is to execute (run) the program to see the output of the program. These 2 processes are often performed by a single command DEBUG. LECTURE 1 39
Processing a C++ Program LECTURE 1 40
Testing and Debugging Bug A mistake in a program Debugging A process of eliminating mistakes in programs Term used when a moth caused a failed relay on the Harvard Mark 1 computer. Grace Hopper and other programmers taped the moth in logbook stating: First actual case of a bug being found. LECTURE 1 41
Program Errors Syntax errors Violation of the grammar rules of the language Discovered by the compiler Error messages may not always show correct location of errors Run-time errors Error conditions detected by the computer at run-time Logic errors Errors in the program s algorithm Most difficult to diagnose Computer does not recognize this error LECTURE 1 42
Integrated Development Environments (IDEs) An integrated development environment, or IDE, combine all the tools needed to write, compile, and debug a program into a single software application. Examples are Microsoft Visual C++, Borland C++ Builder, CodeWarrior, etc. LECTURE 1 43
Integrated Development Environments (IDEs) LECTURE 1 44
Professional Ethics for Computer Programmers Privacy and Misuse of Data Computer Hacking Plagiarism and Software Piracy Misuse of a Computer Resource -the end- 45 LECTURE 1