SlideShare a Scribd company logo
Chapter 1
Introduction to Programming
The best way to start learning a programming language is by
writing a program!!!
What is a program?
• Computer programs, software programs, or
just programs are the instructions that tells
the computer what to do.
• Computer programming (programming or
coding) is the process of writing, testing,
debugging/troubleshooting, and maintaining
the source code of computer programs
Intro
• A computer program consists of two elements:
– Code – action
– Data – characteristics
• Computer programs (also know as source code)
is often written by professionals known as
Computer Programmers. Source code is written
in one of programming languages.
Programming language
• A programming language is an artificial language
that can be used to control the behavior of a
machine, particularly a computer.
• Programming languages, like natural language,
are defined by syntactic and semantic rules which
describe their structure and meaning respectively.
• The syntax of a language describes the possible
combinations of symbols that form a syntactically
correct program.
• The meaning given to a combination of symbols is
handled by semantics.
Programming language
• A main purpose of programming languages is to
provide instructions to a computer.
• Available programming languages come in a
variety of forms and types.
• Programming languages can be divided in to two
major categories:
– Low-level languages
– High-level languages
Low-level Languages
Machine language
It is the lowest level programming language in which all instructions and
data are written in a binary machine code, i.e. 0s and 1s.
Computers only understand one language and that is binary language or
the language of 1s and 0s.
•For example:
00101010 000000000001 000000000010
10011001 000000000010 000000000011
In the initial years of computer programming, all the instructions were
given in binary form. Although the computer easily understood these
programs, it proved too difficult for a normal human being to remember
all the instructions in the form of 0s and 1s.
Therefore, computers remained mystery to a common person until other
languages such as assembly language was developed, which were easier
to learn and understand.
Low-level language
Assembly language
 correspondences symbolic instructions and executable machine codes
and was created to use letters (called mnemonics) to each machine
language instructions to make it easier to remember or write.
For example:
 ADD A, B – adds two numbers in memory location A and B
However, no matter how close assembly language is to machine code,
computers still cannot understand it.
The assembly language must be translated to machine code by a separate
program called assembler.
The machine instruction created by the assembler from the original
program (source code) is called object code. Thus assembly languages are
unique to a specific computer (machine).
High-level Languages
• Use naturally understandable languages
• IDE’s are used for rapid development like C+
+, .Net environment
• they permitted a programmer to ignore many
low-level details of the computer's hardware.
• closer the syntax, rules, and mnemonics to
"natural language“.
• High-level languages are more English-like and,
therefore, make it easier for programmers to
"think" in the programming language.
High-level language
• High-level languages also require translation to
machine language before execution.
• This translation is accomplished by either a
compiler or an interpreter.
– Compilers translate the entire source code program before
execution.
– Interpreters translate source code programs one line at a
time. Interpreters are more interactive than compilers.
• E.g, FORTRAN (FORmula TRANslator), BASIC
(Bingers All Purpose Symbolic Instruction Code),
PASCAL, C, C++, Java.
Problem Solving Techniques
• Computer solves varieties of problems that can be
expressed in a finite number of steps leading to a
precisely defined goal by writing different programs.
• A program is not needed only to solve a problem but
also it should be reliable, (maintainable) portable and
efficient.
• In computer programming two facts are given more
weight:
– The first part focuses on defining the problem and logical
procedures to follow in solving it.
– The second introduces the means by which programmers
communicate those procedures to the computer system so
that it can be executed.
Cont’d
 There are system analysis and design tools, particularly
flowchart and structure chart, that can be used to define
the problem in terms of the steps to its solution.
 The programmer uses programming language to
communicate the logic of the solution to the computer.
 Before a program is written, the programmer must clearly
understand what data are to be used, the desired result, and
the procedure to be used to produce the result.
 The procedure, or solution, selected is referred to as an
algorithm.
 An algorithm is defined as a step-by-step sequence of
instructions that must terminate and describe how the data
is to be processed to produce the desired outputs.
Algorithms
• Simply, Algorithm is a sequence of instructions.
• An algorithm is the plan for writing a program.
• Algorithms are a fundamental part of computing.
• The steps required for solving a problem are listed by
using an algorithm tool.
Algorithm tools make program solutions:
– more clear,
– more understandable,
– easier to remember.
• Algorithms are written according to rules so that other
programmers are also able to read and understand the
solution easily.
Algorithms
An algorithm must satisfy the following requirements:
Unambiguousness: i.e. it must not be ambiguous. Every step
in an algorithm must be clear as to what it is supposed to do and
how many times it is expected to be executed.
Generality: i.e. it should have to be general, not to be specific.
Correctness: it must be correct and must solve the problem for
which it is designed.
Finiteness: it must execute its steps and terminate in finite
time.
Tools of Algorithms
Pseudocodes is English like language for representing the solution
to a problem.
•Pseudo code is independent of any programming language. Pseudo
code (or a flow chart) is the first step in the process of planning the
solution to a problem (also called developing an algorithm).
•Pseudo code is a compact and informal high-level description of a
computer algorithm that uses the structural conventions of
programming languages, but typically omits details such as
subroutines, variables declarations and system-specific syntax.
•The purpose of using pseudocode is that it may be easier for humans
to read than conventional programming languages
•No standard for pseudocode syntax exists, as a program in
pseudocode is not an executable program.
Example: 1
#1. Write a program that obtains two integer
numbers from the user. It will print out the sum of
those numbers.
Pseudo code:
– Prompt the user to enter the first integer
– Prompt the user to enter a second integer
– Compute the sum of the two user inputs
– Display an output prompt that explains the answer as
the sum
– Display the result
Example: 2
#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.
Pseudo code:
- Input a set of 4 marks
- Calculate their average by summing and dividing by 4
- if average is below 50
Print “FAIL”
else
Print “PASS”
Example: 2
#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.
Detailed Algorithm
Step 1: Input M1,M2,M3,M4
Step 2: GRADE = (M1+M2+M3+M4)/4
Step 3: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif
Flowcharts
• A flowchart is a graphical way of representing
the solution to a problem
• The advantage of flowchart is it doesn’t depend
on any particular programming language, so that
it can used, to translate an algorithm to more
than one programming language.
• Flowchart uses different symbols (geometrical
shapes) to represent different processes.
programming language(C++) chapter-one contd.ppt
Example 1:
• Draw flow chart of an algorithm to add two
numbers and display their result.
• Algorithm description
– Read two numbers (A and B)
– Add A and B
– Assign the sum of A and B to C
– Display the result ( c)
programming language(C++) chapter-one contd.ppt
Example: 2
Example 3
• Write an pseudo code and draw a flow chart to check a number
is negative or not.
• Algorithm description.
1. Start
2. Read a number x
3. If x is less than zero then
Write “Negative”
Else
Write “Not Negative”
4. stop
Example 4
• Algorithm description (Pseudo code)
1. Start
2. Initialize Sum to 0 and Counter to 1
2.1 If the Counter is less than or equal to 50
• Add Counter to Sum
• Increase Counter by 1
• Repeat step 2.1
2.2 Else
• Exit Loop
3. Write Sum
4. Stop
Write the algorithm description (Pseudo code) and Draw flow chart of an
algorithm to find the following sum.
Sum = 1+2+3+…. + 50
programming language(C++) chapter-one contd.ppt
Write an algorithm and draw a flowchart that will read the two
sides of a rectangle and calculate its area.
Pseudocode
-Input the width (W) and Length
(L) of a rectangle
-Calculate the area (A) by
multiplying L with W
- Print A
Algorithm
Step 1: Input W,L
Step 2: A = L x W
Step 3: Print A
Example 5
Write an algorithm and draw a flowchart to calculate 2 to the power
of 4.
Algorithm:
Step 1: Base = 2
Step 2: Product = Base
Step 3: Product = Product * Base
Step 4: Product = Product * Base
Step 5: Product = Product * Base
Step 6: Print Product
Example 6
What happens if you want to calculate 2 to the power of 1000?
Quiz
1. Write an algorithm description (Pseudo code) and draw a flow
chart to check a number is even or odd.
Pseudocode
-Read input of a number
-If number mod = 0
-Print "Number is Even"
-Else
-Print "Number is Odd"
Quiz
1. Swap the contents of two variables using a
third variable.
Exercises
For each of the problems below, develop a flow chart
1) Receive a number and determine whether it is odd or even.
2) Obtain two numbers from the keyboard, and determine and display which (if either) is
the larger of the two numbers.
3) Receive 3 numbers and display them in ascending order from smallest to largest
4) Add the numbers from 1 to 100 and display the sum
5) Add the even numbers between 0 and any positive integer number given by the user.
6) Find the average of two numbers given by the user.
7) Find the average, maximum, minimum, and sum of three numbers given by the user.
8) Find the area of a circle where the radius is provided by the user.
9) Swap the contents of two variables using a third variable.
10) Swap the content of two variables without using a third variable.
11) Read an integer value from the keyboard and display a message indicating if this
number is odd or even.
12) Read 10 integers from the keyboard in the range 0 - 100, and count how many of
them are larger than 50, and display this result.
13) Take an integer from the user and display the factorial of that number
Assignment
31
Show pseudo code, algorithm and flowchart for each of the following questions
1: Write a program that calculates the sum of two input numbers and display the result.
2: Write a program to calculate the area of a circle and display the result. Use the formula: A=πr2
where Pi is approximately equal to 3.1416.
3: Write a program that computes the average of three input quizzes, and then display the result.
4: Write a program that converts the input Fahrenheit degree into its Celsius degree equivalent. Use
the formula: C= (5/9)*F-32.
5: Create a program to compute the volume of a sphere. Use the formula: V= (4/3)* πr3
where is pi
equal to 3.1416 approximately. The r3
is the radius. Display result.
6: Write a program that converts the input Celsius degree into its equivalent Fahrenheit degree. Use
the formula: F= (9/5) * C+32.
7: Write and algorithm and draw a flowchart to read an employee name , overtime hours worked ,
hours absent and determine the bonus payment
Use formula bonus = 50 if (overtime – 1/3 absent )>50
= 30 if (overtime – 1/3 absent )>30
= 0 if (overtime – 1/3 absent <30
due date : next week’s this class
Thanks!
Ad

More Related Content

Similar to programming language(C++) chapter-one contd.ppt (20)

Cp 111 lecture 2
Cp 111 lecture 2Cp 111 lecture 2
Cp 111 lecture 2
HafidhyMasoud
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
Sangheethaa Sukumaran
 
01CHAP_1.PPT
01CHAP_1.PPT01CHAP_1.PPT
01CHAP_1.PPT
ManoRanjani30
 
Ic lecture8
Ic lecture8 Ic lecture8
Ic lecture8
AttaullahRahimoon
 
Introduction to programming c
Introduction to programming cIntroduction to programming c
Introduction to programming c
Md. Rakibuzzaman Khan Pathan
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
Gaditek
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
Gaditek
 
Algorithms and flow charts
Algorithms and flow chartsAlgorithms and flow charts
Algorithms and flow charts
Chinnu Edwin
 
INTRODUCTION TO C++, Chapter 1
INTRODUCTION TO C++, Chapter 1INTRODUCTION TO C++, Chapter 1
INTRODUCTION TO C++, Chapter 1
Mubarek Kurt
 
Programming C ppt for learning foundations
Programming C ppt for learning foundationsProgramming C ppt for learning foundations
Programming C ppt for learning foundations
ssuser65733f
 
Chapter 4 computer language
Chapter 4 computer languageChapter 4 computer language
Chapter 4 computer language
Azimjon Khamdamov
 
Fundamentals of programming with C++
Fundamentals of programming with C++Fundamentals of programming with C++
Fundamentals of programming with C++
Seble Nigussie
 
introduction to problem solving and programming
introduction to problem solving and programmingintroduction to problem solving and programming
introduction to problem solving and programming
chaudhariresham6
 
Programming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptxProgramming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptx
TeddyDaka
 
Mcs lec2
Mcs lec2Mcs lec2
Mcs lec2
Faiza Gull
 
Fundamental programming Nota Topic 1.pptx
Fundamental programming Nota Topic 1.pptxFundamental programming Nota Topic 1.pptx
Fundamental programming Nota Topic 1.pptx
UmmuNazieha
 
1.Overview of Programming.pptx
1.Overview of Programming.pptx1.Overview of Programming.pptx
1.Overview of Programming.pptx
Vishwas459764
 
Lecture 6.pptx
Lecture 6.pptxLecture 6.pptx
Lecture 6.pptx
ShimoFcis
 
Introduction to programming language (basic)
Introduction to programming language (basic)Introduction to programming language (basic)
Introduction to programming language (basic)
nharsh2308
 
introduction to computer programming CPPL1.ppt
introduction to computer programming CPPL1.pptintroduction to computer programming CPPL1.ppt
introduction to computer programming CPPL1.ppt
biniyamtiktok
 
Introduction to computer programming
Introduction to computer programmingIntroduction to computer programming
Introduction to computer programming
Sangheethaa Sukumaran
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
Gaditek
 
Programming Paradigm & Languages
Programming Paradigm & LanguagesProgramming Paradigm & Languages
Programming Paradigm & Languages
Gaditek
 
Algorithms and flow charts
Algorithms and flow chartsAlgorithms and flow charts
Algorithms and flow charts
Chinnu Edwin
 
INTRODUCTION TO C++, Chapter 1
INTRODUCTION TO C++, Chapter 1INTRODUCTION TO C++, Chapter 1
INTRODUCTION TO C++, Chapter 1
Mubarek Kurt
 
Programming C ppt for learning foundations
Programming C ppt for learning foundationsProgramming C ppt for learning foundations
Programming C ppt for learning foundations
ssuser65733f
 
Fundamentals of programming with C++
Fundamentals of programming with C++Fundamentals of programming with C++
Fundamentals of programming with C++
Seble Nigussie
 
introduction to problem solving and programming
introduction to problem solving and programmingintroduction to problem solving and programming
introduction to problem solving and programming
chaudhariresham6
 
Programming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptxProgramming requirements for beginning in software engineering.pptx
Programming requirements for beginning in software engineering.pptx
TeddyDaka
 
Fundamental programming Nota Topic 1.pptx
Fundamental programming Nota Topic 1.pptxFundamental programming Nota Topic 1.pptx
Fundamental programming Nota Topic 1.pptx
UmmuNazieha
 
1.Overview of Programming.pptx
1.Overview of Programming.pptx1.Overview of Programming.pptx
1.Overview of Programming.pptx
Vishwas459764
 
Lecture 6.pptx
Lecture 6.pptxLecture 6.pptx
Lecture 6.pptx
ShimoFcis
 
Introduction to programming language (basic)
Introduction to programming language (basic)Introduction to programming language (basic)
Introduction to programming language (basic)
nharsh2308
 
introduction to computer programming CPPL1.ppt
introduction to computer programming CPPL1.pptintroduction to computer programming CPPL1.ppt
introduction to computer programming CPPL1.ppt
biniyamtiktok
 

Recently uploaded (20)

Codingo Ltd. - Introduction - Mobile application, web, custom software develo...
Codingo Ltd. - Introduction - Mobile application, web, custom software develo...Codingo Ltd. - Introduction - Mobile application, web, custom software develo...
Codingo Ltd. - Introduction - Mobile application, web, custom software develo...
Codingo
 
How I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetryHow I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetry
Cees Bos
 
Applying AI in Marketo: Practical Strategies and Implementation
Applying AI in Marketo: Practical Strategies and ImplementationApplying AI in Marketo: Practical Strategies and Implementation
Applying AI in Marketo: Practical Strategies and Implementation
BradBedford3
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
Welcome to QA Summit 2025.
Welcome to QA Summit 2025.Welcome to QA Summit 2025.
Welcome to QA Summit 2025.
QA Summit
 
Comprehensive Incident Management System for Enhanced Safety Reporting
Comprehensive Incident Management System for Enhanced Safety ReportingComprehensive Incident Management System for Enhanced Safety Reporting
Comprehensive Incident Management System for Enhanced Safety Reporting
EHA Soft Solutions
 
Programs as Values - Write code and don't get lost
Programs as Values - Write code and don't get lostPrograms as Values - Write code and don't get lost
Programs as Values - Write code and don't get lost
Pierangelo Cecchetto
 
Why CoTester Is the AI Testing Tool QA Teams Can’t Ignore
Why CoTester Is the AI Testing Tool QA Teams Can’t IgnoreWhy CoTester Is the AI Testing Tool QA Teams Can’t Ignore
Why CoTester Is the AI Testing Tool QA Teams Can’t Ignore
Shubham Joshi
 
iTop VPN With Crack Lifetime Activation Key
iTop VPN With Crack Lifetime Activation KeyiTop VPN With Crack Lifetime Activation Key
iTop VPN With Crack Lifetime Activation Key
raheemk1122g
 
NYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdfNYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdf
AUGNYC
 
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.pptPassive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
IES VE
 
How to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryErrorHow to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryError
Tier1 app
 
Lumion Pro Crack + 2025 Activation Key Free Code
Lumion Pro Crack + 2025 Activation Key Free CodeLumion Pro Crack + 2025 Activation Key Free Code
Lumion Pro Crack + 2025 Activation Key Free Code
raheemk1122g
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
User interface and User experience Modernization.pptx
User interface and User experience  Modernization.pptxUser interface and User experience  Modernization.pptx
User interface and User experience Modernization.pptx
MustafaAlshekly1
 
Do not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your causeDo not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your cause
Fexle Services Pvt. Ltd.
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by AjathMobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Ajath Infotech Technologies LLC
 
Best HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRMBest HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRM
accordHRM
 
Codingo Ltd. - Introduction - Mobile application, web, custom software develo...
Codingo Ltd. - Introduction - Mobile application, web, custom software develo...Codingo Ltd. - Introduction - Mobile application, web, custom software develo...
Codingo Ltd. - Introduction - Mobile application, web, custom software develo...
Codingo
 
How I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetryHow I solved production issues with OpenTelemetry
How I solved production issues with OpenTelemetry
Cees Bos
 
Applying AI in Marketo: Practical Strategies and Implementation
Applying AI in Marketo: Practical Strategies and ImplementationApplying AI in Marketo: Practical Strategies and Implementation
Applying AI in Marketo: Practical Strategies and Implementation
BradBedford3
 
AEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural MeetingAEM User Group DACH - 2025 Inaugural Meeting
AEM User Group DACH - 2025 Inaugural Meeting
jennaf3
 
Download 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-ActivatedDownload 4k Video Downloader Crack Pre-Activated
Download 4k Video Downloader Crack Pre-Activated
Web Designer
 
Welcome to QA Summit 2025.
Welcome to QA Summit 2025.Welcome to QA Summit 2025.
Welcome to QA Summit 2025.
QA Summit
 
Comprehensive Incident Management System for Enhanced Safety Reporting
Comprehensive Incident Management System for Enhanced Safety ReportingComprehensive Incident Management System for Enhanced Safety Reporting
Comprehensive Incident Management System for Enhanced Safety Reporting
EHA Soft Solutions
 
Programs as Values - Write code and don't get lost
Programs as Values - Write code and don't get lostPrograms as Values - Write code and don't get lost
Programs as Values - Write code and don't get lost
Pierangelo Cecchetto
 
Why CoTester Is the AI Testing Tool QA Teams Can’t Ignore
Why CoTester Is the AI Testing Tool QA Teams Can’t IgnoreWhy CoTester Is the AI Testing Tool QA Teams Can’t Ignore
Why CoTester Is the AI Testing Tool QA Teams Can’t Ignore
Shubham Joshi
 
iTop VPN With Crack Lifetime Activation Key
iTop VPN With Crack Lifetime Activation KeyiTop VPN With Crack Lifetime Activation Key
iTop VPN With Crack Lifetime Activation Key
raheemk1122g
 
NYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdfNYC ACE 08-May-2025-Combined Presentation.pdf
NYC ACE 08-May-2025-Combined Presentation.pdf
AUGNYC
 
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.pptPassive House Canada Conference 2025 Presentation [Final]_v4.ppt
Passive House Canada Conference 2025 Presentation [Final]_v4.ppt
IES VE
 
How to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryErrorHow to Troubleshoot 9 Types of OutOfMemoryError
How to Troubleshoot 9 Types of OutOfMemoryError
Tier1 app
 
Lumion Pro Crack + 2025 Activation Key Free Code
Lumion Pro Crack + 2025 Activation Key Free CodeLumion Pro Crack + 2025 Activation Key Free Code
Lumion Pro Crack + 2025 Activation Key Free Code
raheemk1122g
 
Unit Two - Java Architecture and OOPS
Unit Two  -   Java Architecture and OOPSUnit Two  -   Java Architecture and OOPS
Unit Two - Java Architecture and OOPS
Nabin Dhakal
 
User interface and User experience Modernization.pptx
User interface and User experience  Modernization.pptxUser interface and User experience  Modernization.pptx
User interface and User experience Modernization.pptx
MustafaAlshekly1
 
Do not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your causeDo not let staffing shortages and limited fiscal view hamper your cause
Do not let staffing shortages and limited fiscal view hamper your cause
Fexle Services Pvt. Ltd.
 
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studiesTroubleshooting JVM Outages – 3 Fortune 500 case studies
Troubleshooting JVM Outages – 3 Fortune 500 case studies
Tier1 app
 
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by AjathMobile Application Developer Dubai | Custom App Solutions by Ajath
Mobile Application Developer Dubai | Custom App Solutions by Ajath
Ajath Infotech Technologies LLC
 
Best HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRMBest HR and Payroll Software in Bangladesh - accordHRM
Best HR and Payroll Software in Bangladesh - accordHRM
accordHRM
 
Ad

programming language(C++) chapter-one contd.ppt

  • 1. Chapter 1 Introduction to Programming The best way to start learning a programming language is by writing a program!!!
  • 2. What is a program? • Computer programs, software programs, or just programs are the instructions that tells the computer what to do. • Computer programming (programming or coding) is the process of writing, testing, debugging/troubleshooting, and maintaining the source code of computer programs
  • 3. Intro • A computer program consists of two elements: – Code – action – Data – characteristics • Computer programs (also know as source code) is often written by professionals known as Computer Programmers. Source code is written in one of programming languages.
  • 4. Programming language • A programming language is an artificial language that can be used to control the behavior of a machine, particularly a computer. • Programming languages, like natural language, are defined by syntactic and semantic rules which describe their structure and meaning respectively. • The syntax of a language describes the possible combinations of symbols that form a syntactically correct program. • The meaning given to a combination of symbols is handled by semantics.
  • 5. Programming language • A main purpose of programming languages is to provide instructions to a computer. • Available programming languages come in a variety of forms and types. • Programming languages can be divided in to two major categories: – Low-level languages – High-level languages
  • 6. Low-level Languages Machine language It is the lowest level programming language in which all instructions and data are written in a binary machine code, i.e. 0s and 1s. Computers only understand one language and that is binary language or the language of 1s and 0s. •For example: 00101010 000000000001 000000000010 10011001 000000000010 000000000011 In the initial years of computer programming, all the instructions were given in binary form. Although the computer easily understood these programs, it proved too difficult for a normal human being to remember all the instructions in the form of 0s and 1s. Therefore, computers remained mystery to a common person until other languages such as assembly language was developed, which were easier to learn and understand.
  • 7. Low-level language Assembly language  correspondences symbolic instructions and executable machine codes and was created to use letters (called mnemonics) to each machine language instructions to make it easier to remember or write. For example:  ADD A, B – adds two numbers in memory location A and B However, no matter how close assembly language is to machine code, computers still cannot understand it. The assembly language must be translated to machine code by a separate program called assembler. The machine instruction created by the assembler from the original program (source code) is called object code. Thus assembly languages are unique to a specific computer (machine).
  • 8. High-level Languages • Use naturally understandable languages • IDE’s are used for rapid development like C+ +, .Net environment • they permitted a programmer to ignore many low-level details of the computer's hardware. • closer the syntax, rules, and mnemonics to "natural language“. • High-level languages are more English-like and, therefore, make it easier for programmers to "think" in the programming language.
  • 9. High-level language • High-level languages also require translation to machine language before execution. • This translation is accomplished by either a compiler or an interpreter. – Compilers translate the entire source code program before execution. – Interpreters translate source code programs one line at a time. Interpreters are more interactive than compilers. • E.g, FORTRAN (FORmula TRANslator), BASIC (Bingers All Purpose Symbolic Instruction Code), PASCAL, C, C++, Java.
  • 10. Problem Solving Techniques • Computer solves varieties of problems that can be expressed in a finite number of steps leading to a precisely defined goal by writing different programs. • A program is not needed only to solve a problem but also it should be reliable, (maintainable) portable and efficient. • In computer programming two facts are given more weight: – The first part focuses on defining the problem and logical procedures to follow in solving it. – The second introduces the means by which programmers communicate those procedures to the computer system so that it can be executed.
  • 11. Cont’d  There are system analysis and design tools, particularly flowchart and structure chart, that can be used to define the problem in terms of the steps to its solution.  The programmer uses programming language to communicate the logic of the solution to the computer.  Before a program is written, the programmer must clearly understand what data are to be used, the desired result, and the procedure to be used to produce the result.  The procedure, or solution, selected is referred to as an algorithm.  An algorithm is defined as a step-by-step sequence of instructions that must terminate and describe how the data is to be processed to produce the desired outputs.
  • 12. Algorithms • Simply, Algorithm is a sequence of instructions. • An algorithm is the plan for writing a program. • Algorithms are a fundamental part of computing. • The steps required for solving a problem are listed by using an algorithm tool. Algorithm tools make program solutions: – more clear, – more understandable, – easier to remember. • Algorithms are written according to rules so that other programmers are also able to read and understand the solution easily.
  • 13. Algorithms An algorithm must satisfy the following requirements: Unambiguousness: i.e. it must not be ambiguous. Every step in an algorithm must be clear as to what it is supposed to do and how many times it is expected to be executed. Generality: i.e. it should have to be general, not to be specific. Correctness: it must be correct and must solve the problem for which it is designed. Finiteness: it must execute its steps and terminate in finite time.
  • 14. Tools of Algorithms Pseudocodes is English like language for representing the solution to a problem. •Pseudo code is independent of any programming language. Pseudo code (or a flow chart) is the first step in the process of planning the solution to a problem (also called developing an algorithm). •Pseudo code is a compact and informal high-level description of a computer algorithm that uses the structural conventions of programming languages, but typically omits details such as subroutines, variables declarations and system-specific syntax. •The purpose of using pseudocode is that it may be easier for humans to read than conventional programming languages •No standard for pseudocode syntax exists, as a program in pseudocode is not an executable program.
  • 15. Example: 1 #1. Write a program that obtains two integer numbers from the user. It will print out the sum of those numbers. Pseudo code: – Prompt the user to enter the first integer – Prompt the user to enter a second integer – Compute the sum of the two user inputs – Display an output prompt that explains the answer as the sum – Display the result
  • 16. Example: 2 #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. Pseudo code: - Input a set of 4 marks - Calculate their average by summing and dividing by 4 - if average is below 50 Print “FAIL” else Print “PASS”
  • 17. Example: 2 #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. Detailed Algorithm Step 1: Input M1,M2,M3,M4 Step 2: GRADE = (M1+M2+M3+M4)/4 Step 3: if (GRADE < 50) then Print “FAIL” else Print “PASS” endif
  • 18. Flowcharts • A flowchart is a graphical way of representing the solution to a problem • The advantage of flowchart is it doesn’t depend on any particular programming language, so that it can used, to translate an algorithm to more than one programming language. • Flowchart uses different symbols (geometrical shapes) to represent different processes.
  • 20. Example 1: • Draw flow chart of an algorithm to add two numbers and display their result. • Algorithm description – Read two numbers (A and B) – Add A and B – Assign the sum of A and B to C – Display the result ( c)
  • 23. Example 3 • Write an pseudo code and draw a flow chart to check a number is negative or not. • Algorithm description. 1. Start 2. Read a number x 3. If x is less than zero then Write “Negative” Else Write “Not Negative” 4. stop
  • 24. Example 4 • Algorithm description (Pseudo code) 1. Start 2. Initialize Sum to 0 and Counter to 1 2.1 If the Counter is less than or equal to 50 • Add Counter to Sum • Increase Counter by 1 • Repeat step 2.1 2.2 Else • Exit Loop 3. Write Sum 4. Stop Write the algorithm description (Pseudo code) and Draw flow chart of an algorithm to find the following sum. Sum = 1+2+3+…. + 50
  • 26. Write an algorithm and draw a flowchart that will read the two sides of a rectangle and calculate its area. Pseudocode -Input the width (W) and Length (L) of a rectangle -Calculate the area (A) by multiplying L with W - Print A Algorithm Step 1: Input W,L Step 2: A = L x W Step 3: Print A Example 5
  • 27. Write an algorithm and draw a flowchart to calculate 2 to the power of 4. Algorithm: Step 1: Base = 2 Step 2: Product = Base Step 3: Product = Product * Base Step 4: Product = Product * Base Step 5: Product = Product * Base Step 6: Print Product Example 6 What happens if you want to calculate 2 to the power of 1000?
  • 28. Quiz 1. Write an algorithm description (Pseudo code) and draw a flow chart to check a number is even or odd. Pseudocode -Read input of a number -If number mod = 0 -Print "Number is Even" -Else -Print "Number is Odd"
  • 29. Quiz 1. Swap the contents of two variables using a third variable.
  • 30. Exercises For each of the problems below, develop a flow chart 1) Receive a number and determine whether it is odd or even. 2) Obtain two numbers from the keyboard, and determine and display which (if either) is the larger of the two numbers. 3) Receive 3 numbers and display them in ascending order from smallest to largest 4) Add the numbers from 1 to 100 and display the sum 5) Add the even numbers between 0 and any positive integer number given by the user. 6) Find the average of two numbers given by the user. 7) Find the average, maximum, minimum, and sum of three numbers given by the user. 8) Find the area of a circle where the radius is provided by the user. 9) Swap the contents of two variables using a third variable. 10) Swap the content of two variables without using a third variable. 11) Read an integer value from the keyboard and display a message indicating if this number is odd or even. 12) Read 10 integers from the keyboard in the range 0 - 100, and count how many of them are larger than 50, and display this result. 13) Take an integer from the user and display the factorial of that number
  • 31. Assignment 31 Show pseudo code, algorithm and flowchart for each of the following questions 1: Write a program that calculates the sum of two input numbers and display the result. 2: Write a program to calculate the area of a circle and display the result. Use the formula: A=πr2 where Pi is approximately equal to 3.1416. 3: Write a program that computes the average of three input quizzes, and then display the result. 4: Write a program that converts the input Fahrenheit degree into its Celsius degree equivalent. Use the formula: C= (5/9)*F-32. 5: Create a program to compute the volume of a sphere. Use the formula: V= (4/3)* πr3 where is pi equal to 3.1416 approximately. The r3 is the radius. Display result. 6: Write a program that converts the input Celsius degree into its equivalent Fahrenheit degree. Use the formula: F= (9/5) * C+32. 7: Write and algorithm and draw a flowchart to read an employee name , overtime hours worked , hours absent and determine the bonus payment Use formula bonus = 50 if (overtime – 1/3 absent )>50 = 30 if (overtime – 1/3 absent )>30 = 0 if (overtime – 1/3 absent <30 due date : next week’s this class
  翻译: