lesson 1 introduction to programming language. computer comprised of various devices that are...

25
LESSON 1 Introduction to Programming Language

Upload: ferdinand-horton

Post on 18-Jan-2018

221 views

Category:

Documents


0 download

DESCRIPTION

Computer Program  Set of instructions used to operate a computer to perform specific task and produce result

TRANSCRIPT

Page 1: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

LESSON 1

Introduction to Programming Language

Page 2: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

ComputerComprised of various devices that are referred to as HARDWARE.

The computer programs that run of a computer are referred to SOFTWARE.

Page 3: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

Computer ProgramSet of instructions used to operate a computer to perform specific task and produce result

Page 4: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

Computer ProgrammingWriting computer program

Page 5: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

Programming LanguageLanguage used to create computer programs

Page 6: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

Levels of Programming Languages

Machine LanguagesAssembly LanguagesHigh Languages

Page 7: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

Machine Language

Lowest level of computer languages

Only language that computer can understand.

Consist entirely of 1s and 0s. Easily understood by computers

but difficult to read by people.

Page 8: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

Assembly LanguageUses symbolic names and operands instead of 1s and Os e.g. MOV and ADD

Needs ASSEMBLER to translate instruction to machine level language

Page 9: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

High-Level Languages English like language instructions

so it is easier to learn, use and debug the program.

Example FORTRAN, COBOL, BASIC, PASCAL, C,

C++ and JAVA It needs the help of COMPILER to

be understood by the computer

Page 10: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

What is Compiler Translates the high level

program(source code) into machine code(object code).

High Level Program Compiler Machine Code0,1

Page 11: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

History of C++ In 1970s, at Bell Laboratories, Dennis

Ritchie and Brian Kernighan designed the C programming language.

Most of C is a subset of C++ C++ was developed by Dr. Bjarne

Stroustrup in 1985 at AT&T Bell Labs New Jersey, USA.

Initially called as “C with classes” but was change to C++

Page 12: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

An ALGORITHM is a detailed sequence of simple steps that are needed to solve a problem.

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.

Algorithm

Page 13: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

1. Start 2. Accept num1, num2 3. sum = num1+num2 4. Display sum 5. Stop

Write an algorithm to find sum of two numbers.

Sample 1

Page 14: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

1. Start 2. Accept q1, q2, q3 3. total = q1 + q2 + q3 4. average = total / 3 5. Display total, average 6. Stop

Write an algorithm find the total and average of three quizzes.

Sample 2

Page 15: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

Write an algorithm to determine a student’s final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks.

Sample 3

Page 16: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

Sample 3

Step 1: StartStep 2: Input M1, M2, M3, M4 Step 3: GRADE = (M1+M2+M3+M4)/4 Step 4: if (GRADE < 50) then Print “FAIL”

else Print “PASS” Step 5: Stop

Page 17: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

A flowchart is a design tool used to graphically represent the logic in a solution. It is a pictorial representation or graphical representation of the algorithm.

Flowchart

Page 18: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

Flowchart

Page 19: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

Flowchart

Page 20: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

Write a flowchart to find sum of two numbers

Sample 1

1. Start 2. Accept num1, num2 3. sum = num1+num2 4. Display sum 5. Stop

Page 21: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

Exercises Question 1. Write an algorithm and draw

the flowchart to read money in US dollar and convert to Omani rials. rials = dollar * 2.50

Answer1. Start2. Accept dollar3. Rials = dollar * 2.504. Display rials5. Stop

start

Accept dollar

rials = dollars * 2.50

Display rials

stop

Page 22: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

Exercises Question 2. Write an algorithm and draw

the flowchart to calculate area of square and rectangle. Square Area = side * side Rectangle Area = length * width

Answer1. Start2. Accept side, length, width3. Square Area = side * side4. Rectangle Area = length *

width5. Display square and

rectangle area6. Stop

start

Accept side, length, width

Square area = side * sideRectangle area = length *

widthDisplay square and rectangle

areastop

Page 23: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

Exercises Question 3. Write an algorithm and draw

the flowchart to determine if a number is positive or negative.

Answer1. Start2. Accept number3. If number<0 then

Print “negative” else

Print “positive”4. Stop

start

Accept side, length, width

Print “Positive”

stop

Print “Negative

If number

<0 NOYES

Page 24: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

Exercises Question 2. Write an algorithm and draw

the flowchart to calculate area of square and rectangle. Square Area = side * side Rectangle Area = length * width

Answer1. Start2. Accept side, length, width3. Square Area = side * side4. Rectangle Area = length *

width5. Display square and

rectangle area6. Stop

start

Accept side, length, width

Square area = side * sideRectangle area = length *

widthDisplay square and rectangle

areastop

Page 25: LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that

Exercises Question 2. Write an algorithm and draw

the flowchart to calculate area of square and rectangle. Square Area = side * side Rectangle Area = length * width

Answer1. Start2. Accept side, length, width3. Square Area = side * side4. Rectangle Area = length *

width5. Display square and

rectangle area6. Stop

start

Accept side, length, width

Square area = side * sideRectangle area = length *

widthDisplay square and rectangle

areastop