Presentation is loading. Please wait.

Presentation is loading. Please wait.

1. Introduction to Computers and Programming Language FTMK, UTeM – Sem 1 2013/2014 1.

Similar presentations


Presentation on theme: "1. Introduction to Computers and Programming Language FTMK, UTeM – Sem 1 2013/2014 1."— Presentation transcript:

1 1. Introduction to Computers and Programming Language FTMK, UTeM – Sem 1 2013/2014 1

2  At the end of this lecture, you should be able to  explain the use of computer programs  describe what is computer, computer system components (hardware and software)  describe what is programs and programming language  explain the programming process 2

3 Computer – programmable machine designed to follow instructions Program – instructions in computer memory to make it do something Programmer – person who writes instructions (programs) to make computer perform a task SO, without programmers, no programs; without programs, a computer cannot do anything 3

4 1. Central Processing Unit (CPU) 2. Main Memory 3. Secondary Memory / Storage 4. Input Devices 5. Output Devices 4

5 5

6 Comprised of:  Control Unit  Retrieves and decodes program instructions  Coordinates activities of all other parts of computer  Arithmetic & Logic Unit  Hardware optimized for high-speed numeric calculation  Hardware designed for true/false, yes/no decisions 6

7 7 Figure 1-2

8 Cycle through:  Fetch: get the next program instruction from main memory  Decode: interpret the instruction and generate a signal  Execute: route the signal to the appropriate component to perform an operation 1-8

9  Holds both program instructions and data  It is volatile. Main memory is erased when program terminates or computer is turned off  Also called Random Access Memory (RAM)  Organized as follows:  bit: smallest piece of memory. Has values 0 (off, false) or 1 (on, true)  byte: 8 consecutive bits. Bytes have addresses. 9

10  Addresses – Each byte in memory is identified by a unique number known as an address.  Bit  Smallest piece of memory  Stands for binary digit  Has values 0 (off) or 1 (on)  Byte  Is 8 consecutive bits  Word  Usually 4 consecutive bytes  Has an address 10 0 1 1 0 0 1 1 1 8 bits 1 byte

11 11 In Figure 1-3, the number 149 is stored in the byte with the address 16, and the number 72 is stored at address 23.

12  Non-volatile: data retained when program is not running or computer is turned off  Comes in a variety of media:  magnetic: floppy disk, zip disk, hard drive  optical: CD-ROM  Flash drives, connected to the USB port 12

13  Devices that send information to the computer from outside  Many devices can provide input:  Keyboard, mouse, scanner, digital camera, microphone  Disk drives and CD-ROM 13

14  Output is information sent from a computer program to the outside world.  The output is sent to an output device  Many devices can be used for output:  Computer monitor and printer  Floppy, zip disk drives  Writable CD drives 14

15  Operating system software  programs that manage the computer hardware and the programs that run on the computer  how many programs can run at once?  Single tasking - one program at a time (MS-DOS)  Multitasking – multiple programs at a time (UNIX, Windows XP/Vista/7)  how many people can use computer at the same time?  Single user – MS-DOS, early versions of Windows  Multiuser - UNIX  Application software  programs that provide services to the user. Ex: word processing, games, programs to solve specific problems 1-15

16  A program is a set of instructions that the computer follows to perform a task  Programming Language is a language used to write programs  Types of languages  Low-level: used for communication with computer hardware directly.  High-level: closer to human language 16

17 A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer. Programming languages can be used to create programs that specify the behavior of a machine, to express algorithms. Many programming languages have their syntax and semantics. 17

18 1st Generation: (1950-60) machine language. 2nd Generation: (1961-75) assembly language. 3rd Generation: (1976-92) high-level programming languages, such as C, C++, and Java. 4th Generation: (1993-2005) typical high-level programming languages closer to human languages. 5th Generation: (2005-..) used for artificial intelligence and neural networks. 18

19 A first-generation programming language is a machine-level programming language. No translator was used to compile or assemble the first-generation language. The main benefit of first-generation programming language is that the code a user writes can run very fast and efficiently. It is a lot more difficult to learn than higher generational programming languages, and it is far more difficult to edit if errors occur. 19

20 Machine language is an example of 1st G Language. Sometimes referred to as machine code or object code. It is a collection of binary digits or bits that the computer reads and interprets. 20

21 Second-generation programming language is a generational way to categorize assembly languages. Second-generation programming languages have the following properties: The code can be read and written by a programmer. To run on a computer it must be converted into a machine readable form, a process called assembly. The language is specific to a particular processor family and environment. 21

22 It is an example of 2nd G Language. Assembly languages are a family of low-level languages for programming computers. It implements a symbolic representation of the numeric machine codes. Other constants needed to program a particular CPU architecture. 22

23 Assembler Assembler creates object code by translating assembly instruction mnemonics into opcodes, and by resolving symbolic names for memory locations and other entities. Assemblers are generally simpler to write than compilers for high-level languages. 23

24 The introduction of the compiler in 1952 spurred the development of third-generation computer languages. These languages enable a programmer to create program files using commands that are similar to spoken English. Third-level computer languages have become the major means of communication between the digital computer and its user. Such as BASIC, C, FORTAN and Pascal. 24

25 High-level language 3rd G Languages are High-level Languages. After a program is written in one of the high-level languages, it must be either compiled or interpreted. 25

26 A Compiler program rewrites the program into machine language that the CPU can understand. This is done all at once and the program is saved in this new form. A compiled program is generally considerably larger than the original. An Interpreter program translates the program statements into machine language one line at a time as the program is running. An interpreted program will be smaller than a compiled one but will take longer to execute. 26

27 A fourth-generation programming language (1970s-1990) (abbreviated 4GL) is a programming language or programming environment designed with a specific purpose in mind, such as the development of commercial business software. In the evolution of computing, the 4GL followed the 3GL in an upward trend toward higher abstraction and statement power. The 4GL was followed by efforts to define and use a 5GL. 27

28 3GL development methods can be slow and error- prone. Some applications could be developed more rapidly by adding a higher-level programming language and methodology which would generate the equivalent of very complicated 3GL instructions with fewer errors. All 4GLs are designed to reduce :  programming effort,  the time it takes to develop software and  the cost of software development. 28

29 Fourth-generation languages have often been compared to domain-specific programming languages (DSLs). For example, a typical 4GL command is FIND ALL RECORDS WHERE NAME IS "SMITH" 29

30 Table-driven (codeless) programming, usually running with runtime framework and libraries. Instead of using code. Report generators take a description of the data format and the report to generate and from that they either generate the required report directly or they generate a program to generate the report. Data management 4GLs such as SAS, SPSS and Stata provide sophisticated coding commands for data manipulation, file reshaping, case selection and data documentation in the preparation of data for statistical analysis and reporting. 30

31 FoxPro PowerBuilder SQL Report Builder Oracle Reports Graph Talk MATLAB CSS 31

32 Database query languages Query languages are computer languages used to make queries into databases and information systems. Query languages can be classified according to whether they are database query languages or information retrieval query languages. SQL is a well known query language for relational databases. XQuery is a query language for XML data sources. 32

33 Fifth generation computing devices, based on artificial intelligence, are still in development, though there are some applications, such as voice recognition, that are being used today. The use of parallel processing and superconductors is helping to make artificial intelligence a reality. The goal of fifth-generation computing is to develop devices that respond to natural language input and are capable of learning and self-organization. 33

34 Examples : Artificial intelligence : The branch of computer science concerned with making computers behave like humans. There are several programming languages that are known as AI languages because they are used almost exclusively for AI applications. The two most common are LISP and Prolog. 34

35 Examples : Neural network A type of artificial intelligence that attempts to imitate the way a human brain works. A neural network works by creating connections between processing elements, the computer equivalent of neurons. Neural networks are currently used prominently in voice recognition systems, image recognition systems, industrial robotics, medical imaging, data mining and aerospace applications. 35

36 36 Example Algorithm for Calculating Gross Pay. We start with an algorithm, which is a set of well-defined steps.

37 a) Create file containing the program with a text editor or Integrated Development Environment (IDE) b) Run preprocessor to convert source file directives to source code program statements. c) Run compiler to convert source program into machine instructions. d) Run linker to connect hardware-specific code to machine instructions, producing an executable file.  Steps b–d are often performed by a single command or button click.  Errors detected at any step will prevent execution of following steps. 37

38 38 Source Code Preprocessor Modified Source Code Compiler Object Code Linker Executable Code

39  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. 39

40 40

41  Common elements in programming languages:  Key Words  Programmer-Defined Identifiers  Operators  Punctuation  Syntax 41

42 #include using namespace std; int main() { double num1 = 5, num2, sum; num2 = 12; sum = num1 + num2; cout << "The sum is " << sum; return 0; }

43  Also known as reserved words  Have a special meaning in C++  Can not be used for another purpose  Written using lowercase letters  Examples in program (shown in green) : using namespace std; int main()

44  Names made up by the programmer  Not part of the C++ language  Used to represent various things, such as variables (memory locations)  Example in program (shown in green) : double num1

45  Used to perform operations on data  Many types of operators  Arithmetic: +, -, *, /  Assignment: =  Examples in program (shown in green) : num2 = 12; sum = num1 + num2;

46  Characters that mark the end of a statement, or that separate items in a list  Example in program (shown in green) : double num1 = 5, num2, sum; num2 = 12;

47 In a source file, A line is all of the characters entered before a carriage return. Blank lines improve the readability of a program. Here are four sample lines. Line 3 is blank: double num1 = 5, num2, sum; num2 = 12; sum = num1 + num2;

48 In a source file, A statement is an instruction to the computer to perform an action. A statement may contain keywords, operators, programmer-defined identifiers, and punctuation. A statement may fit on one line, or it may occupy multiple lines. Here is a single statement that uses two lines: double num1 = 5, num2, sum;

49 Three steps that a program typically performs: 1) Gather input data:  from keyboard  from files on disk drives 2) Process the input data 3) Display the results as output:  send it to the screen  write to a file 49

50 // sample C++ program #include using namespace std; int main() { cout << "Hello, there!"; return 0; } 50 The Parts of a C++ Program comment preprocessor directive which namespace to use beginning of function named main beginning of block for main output statement send 0 back to operating system end of block for main

51 2-51 StatementPurpose // sample C++ program comment #include preprocessor directive using namespace std; which namespace to use int main() beginning of function named main { beginning of block for main cout << "Hello, there!"; output statement return 0; send 0 back to the operating system } end of block for main

52 2-52 CharacterNameDescription // Double SlashBegins a comment # Pound SignBegins preprocessor directive Open, Close BracketsEncloses filename used in #include directive ( ) Open, Close ParenthesesUsed when naming function { } Open, Close BracesEncloses a group of statements " Open, Close Quote MarksEncloses string of characters ; SemicolonEnds a programming statement

53  C++ is case-sensitive. Uppercase and lowercase characters are different characters. ‘ Main ’ is not the same as ‘ main ’.  Every { must have a corresponding }, and vice- versa. 2-53

54  Displays information on computer screen  Use << to send information to cout cout << "Hello, there!";  Can use << to send multiple items to cout cout << "Hello, " << "there!"; Or cout << "Hello, "; cout << "there!"; 2-54

55  To get multiple lines of output on screen - Use endl cout << "Hello, there!" << endl; - Use \n in an output string cout << "Hello, there!\n"; 2-55

56  Inserts the contents of another file into the program  Is a preprocessor directive  Not part of the C++ language  Not seen by compiler  Example: #include 2-56 No ; here

57 Older-style C++ programs Use.h at end of header files #include Do not use using namespace convention May not compile with a standard C++ compiler 2-57

58  Tony Gaddis, Starting out with C++  www.wittyengineers.com 58


Download ppt "1. Introduction to Computers and Programming Language FTMK, UTeM – Sem 1 2013/2014 1."

Similar presentations


Ads by Google