0% found this document useful (0 votes)
6 views

CH-1[Programming using c++] upd 1

The document provides an overview of computers, programming terminology, and programming languages, detailing the functions of computers and the roles of programmers. It explains the concepts of algorithms, problem-solving techniques, and the System Development Life Cycle (SDLC), along with the importance of high-level and low-level programming languages. Additionally, it covers the phases of C++ program development, including editing, preprocessing, compiling, linking, loading, and execution.

Uploaded by

Muaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

CH-1[Programming using c++] upd 1

The document provides an overview of computers, programming terminology, and programming languages, detailing the functions of computers and the roles of programmers. It explains the concepts of algorithms, problem-solving techniques, and the System Development Life Cycle (SDLC), along with the importance of high-level and low-level programming languages. Additionally, it covers the phases of C++ program development, including editing, preprocessing, compiling, linking, loading, and execution.

Uploaded by

Muaz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

What is computer

0 Is an electronic device that converts data into information through a set of step by step
operations
0 Is machine capable of solving problems and manipulating data
0 It accepts data, processes the data by doing some mathematical and logical operations
and gives us the desired output
0 Computer can be defined in terms of its functions.
0 It can
0 accept data
0 store data,
0 process data as desired, and
0 retrieve the stored data as and when required and
0 print the result in desired format
2
Computer programming Terminologies
0 programmer: is a person who creates programs that solve a problem using the computer
0 Program: is a sequence of steps that a computer understands and executes.
0 Bug: is an error in a program.
0 Debugging: is the process of removing errors, testing and revising a programs to make sure
that it performs as expected.
0 Programming language: is an environment/notation used to write instructions into a
computer.
0 a set of rules that provides a way of telling a computer what operations to perform.
0 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.

3
Programming languages
0 Hundreds of computer languages are in use today. These may be divided into three
general types:
0 Machine languages - Low-Level Languages
0 is the "natural language/mother tongue” of a computer
0 is often referred to as object code - generated by a compiler or an assembler after translating high-
level or assembly language programs.
0 consist of strings of numbers (ultimately reduced to 1s and 0s) that instruct computers to perform
their most elementary operations one at a time.
0 are machine dependent (i.e., a particular machine language can be used on only one type of
computer).
0 bulky for humans
0 Assembly languages - Low-Level Languages
0 is machine dependent
0 High-level languages
0 machine independent language levels
4
Assembly languages
0 Machine-language programming was simply too slow, tedious and error-prone for
most programmers.
0 Instead of using the strings of numbers (1s and 0s) that computers could directly
understand, programmers began
0 using English-like abbreviations to represent elementary operations.
0 These abbreviations formed the basis of assembly languages. Translator programs called
assemblers were/ is developed to convert assembly-language programs to machine
language. Example
0 MOV AX, 5 ; Move the value 5 into register AX
0 ADD AX, 3 ; Add 3 to AX
0 INT 21h ; Call an interrupt (DOS function)
0 Although such code is clearer to humans,
0 it is incomprehensible to computers until translated to machine language.
5
High-level languages
0 To speed the programming process,
0 high-level languages were developed in which single statements could be written to
accomplish substantial tasks.
0 Translator programs called compilers convert high-level language programs into
machine language.
0 High-level languages allow programmers to write instructions that look almost like
every day English and contain commonly used mathematical notations.
0 A payroll program : grossPay = basePay + overTimePay;
0 are preferable to machine and assembly language.
0 C, C++, Microsoft's .NET, Python, Java, JavaScript, C#, PHP, Ruby, Go, Swift, Kotlin, Dart,
Lisp, Pascal, Fortran, COBOL, BASIC

6
What skill do we need to be a programmer?

0 Programming language skill


0 Problem solving skill
0 Algorithm development skill

7
Problem solving techniques
0 is the process of transforming the description of a problem into the solution
0 by using our knowledge of the problem domain and by relying on our ability to select and
use appropriate problem-solving strategies, techniques, and tools.
0 The program we design in any programming language to solve a problem need to be:
0 Reliable: the program should always do what it is expected to do and handle all types of
exception.
0 Maintainable: the program should be in a way that it could be modified and upgraded
when the need arises.
0 Portable: It needs to be possible to adapt the software written for one type of computer to
another with minimum modification.
0 Efficient: the program should be designed to make optimal use of time, space and other
resources of the computer.

8
System Development Life Cycle (SDLC)

0 The Systems Development Life Cycle (SDLC) is a conceptual model used in project
management that describes the stages involved in a computer system development
project from an initial feasibility study through maintenance of the completed
application. The phases of SDLC are discussed below briefly.
0 Software development life cycle (SDLC) is a structured process that is used to design,
develop, and test good-quality software. SDLC, or software development life cycle, is a
methodology that defines the entire procedure of software development step-by-step.
0 The goal of the SDLC life cycle model is to deliver high-quality, maintainable software
that meets the user’s requirements. SDLC in software engineering models outlines the
plan for each stage so that each stage of the software development model can perform
its task efficiently to deliver the software at a low cost within a given time frame that
meets users’ requirements.

9
0 Planning and System analysis- scop, objective, resource
0 Defining –functional and none functional requirements
0 System design
0 Implementation
0 Testing and Maintenance
0 Deployment

10
11
What is an Algorithm?
0 An algorithm is a set of well-defined instructions to solve a particular problem.
0 It takes a set of input and produces a desired output. For example,
0 A programming algorithm is a procedure or formula used for solving a problem.
0 It is a sequence of specified actions in which these actions describe how to do something,
and your computer will do it exactly that way every time.
0 properties: Sequence, Unambiguous, Input, Output, Finite

12
0 Note: An algorithm doesn’t depend on any particular programming language, so that
we can translate an algorithm to more than one programming language.
0 There are two commonly used techniques (tools) to implement an algorithm.
0 These are flowcharts and Pseudo-code.
0 Generally, flowcharts work well for small problems but Pseudo-code is used for larger
problems.

13
1. Pseudocode
➢It’s the cooked up representation of an algorithm. Often at times, algorithms are
represented with the help of pseudo codes as they can be interpreted by
programmers no matter what their programming background or knowledge is.
➢Pseudo code, as the name suggests, is a false code or a representation of code which
can be understood by even a layman with some school level programming
knowledge
Adding two numbers
#Declare variables num1, num2, and sum
num1 = 0
num2 = 0
sum = 0
# Read values for num1 and num2
read num1
read num2
# Calculate the sum of num1 and num2
sum = num1 + num2
# Display the sum
print sum
14
Ex2. Check Even or odd
0 BEGIN
0 PRINT "Enter a number:"
0 READ number
0 IF number MOD 2 == 0 THEN
0 PRINT "The number is EVEN"
0 ELSE
0 PRINT "The number is ODD"
0 ENDIF
0 END

15
Ex3. Add the numbers from 1 to 100 and display the sum

0 BEGIN
0 SET sum = 0
0 FOR number FROM 1 TO 100 DO
0 sum = sum + number
0 ENDFOR
0 PRINT "The sum of numbers from 1 to 100 is:", sum
0 END

16
2. Modeling a programs logic using flow chart
0 Algorithm could be designed using many techniques and tools.
0 One tool of designing algorithm is by using flowcharts.
0 Flowchart is a graphical way of expressing the steps needed to solve a problem.
0 is a schematic representation of an algorithm or a process.
0 uses different symbols (geometrical shapes) to represent different processes.

17
Symbol Name use

Terminal Indicates beginning and end of a program

Calculation or assigning of a value to a variable


,especially during initialization
Process

Input/output Input/output to program

Program decision. Allow alternate courses of action


based on a condition. A decision indicates a question
that can be answered yes or no (T or F)
Decision
Indicates one symbol is connected to another
Connector
To connect symbols and indicate the sequence of
Arrow /Flow lines operations
18
0 The program logic has three structures used to design a program: sequence, decision,
and repetition.
0 Sequence: A series of actions are performed in sequence
0 Draw flow chart to add two numbers and display their result.
0 Example1: Draw a flow-chart that can calculate and print the average of three numbers: 5, 8,10
0 Example2: Draw a flow-chart that can calculate and print the average of three numbers, accept
the numbers from user/ keyboard
0 Exercise 1: Draw a flowchart that can calculate and print the square and cube of a number: given
the number are 4.
0 Exercise 2: Draw a flowchart that can calculate and print the square and cube of a number:
accept a number from user/ keyboard
0 Selection:
0 Iteration

19
20
21
0 Selection (decision/ branching) Structure
0 One action is taken out of two possible actions, depending on a condition.
0 The diamond symbol indicates a yes/no question. If the answer to the question is yes, the
flow follows yes path. If the answer is no, the flow follows another path
0 In the flowchart segment below, the question “is x < y?” is asked. If the answer is no, then
process A is performed. If the answer is yes, then process B is performed.

NO YES if (x < y)
x < y? process A;
else
Process A
Process B process B;

22
0 Example: While purchasing certain items, a discount of 10% is offered if the quantity purchased is more than
1000. If quantity and price per item are input through the keyboard, write a program to calculate the total
expenses.

Exercise 1: Write an algorithm using flow chart and pseudo code to check whether a
number is even or odd. 23
Iteration(loop/ repetition)Structure
0 An iteration structure represents part of the program that repeats the same code and
produces different outputs based at each loop on the given condition.
0 The loop repeats as long as the condition is true and the loop terminates when the
condition becomes false.
0 The action performed by an iteration structure must eventually cause the loop to
terminate. Otherwise, an infinite loop is created.
0 In this flowchart segment, x is never changed. Once the loop starts, it will never end.
0 QUESTION: How can this flowchart be modified so that no longer an infinite loop?

24
ANSWER to the above question: By adding an action
within the iteration that changes the value of x
YES

x < y? Display x

YES

x < y? Display x Add 1 to x

Exercise 1: - Write the algorithmic description and draw a flow chart to find the following sum.
Sum = 1+2+3+…. + 50
Solution …..?
Exercise 2: Draw a flowchart that can list down all numbers between 10 and 20, including 10 and 20’.
Solution …..?

25
Exercise:
0 For each of the problems below, develop a flow chart
0 Receive a number from the keyboard and determine whether it is odd or even
0 Obtain two numbers from the keyboard, and determine and display which (if either) is the larger of the two numbers.
0 Add the numbers from 1 to 100 and display the sum

26
Typical C++ Development Environment

❖ C++ as a language generally consist of two parts: a program development environment and the
C++ Standard Library.
❖ To reach with a working program, C++ programs typically go through six phases: edit, preprocess,
compile, link, load and execute.
✓ Phase 1: Creating a Program
❖ Phase 1 consists of editing a file with an editor program (normally known as simply an editor).
❖ You type a C++ program (typically referred to as source code) using the editor.
✓ Phases 2 and 3: Preprocessing and Compiling a C++ Program
❖ In phase 2, the programmer gives the command to compile the program.
❖ In a C++ system, a preprocessor program executes automatically before the compiler's translation
phase begins
❖ The most common preprocessor directives are the #include preprocessor directive and #define
preprocessor directive and there are also others.

27
✓ Phase 4: Linking
❖ The object code produced by the C++ compiler typically contains "holes" due to these missing parts.
❖ A linker links the object code with the code for the missing functions to produce an executable
image (with no missing pieces).
❖ If the program compiles and links correctly, an executable image is produced.

✓ Phase 5: Loading
❖ Before a program can be executed, it must first be placed in memory.
❖ This is done by the loader, which takes the executable image from disk and transfers it to memory.
❖ Phase 6: Execution
❖ Finally, the computer, under the control of its CPU, executes the program one instruction / task at a
time.

28
Thank you!

29

You might also like