lesson 1 introduction to programming language. computer comprised of various devices that are...
DESCRIPTION
Computer Program Set of instructions used to operate a computer to perform specific task and produce resultTRANSCRIPT
LESSON 1
Introduction to Programming Language
ComputerComprised of various devices that are referred to as HARDWARE.
The computer programs that run of a computer are referred to SOFTWARE.
Computer ProgramSet of instructions used to operate a computer to perform specific task and produce result
Computer ProgrammingWriting computer program
Programming LanguageLanguage used to create computer programs
Levels of Programming Languages
Machine LanguagesAssembly LanguagesHigh Languages
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.
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
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
What is Compiler Translates the high level
program(source code) into machine code(object code).
High Level Program Compiler Machine Code0,1
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++
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
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
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
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
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
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
Flowchart
Flowchart
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
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
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
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
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
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