0% found this document useful (0 votes)
57 views17 pages

1a Fop

This document provides an overview of structured programming concepts like control statements, subroutines, and blocks. It also discusses flowcharts, including their purpose and common symbols. Examples are given to demonstrate creating sequential and conditional flowcharts. The evolution of C++ from C is outlined. The C++ standard library is introduced to provide pre-made functions. Finally, the basics of a C++ development environment are explained.

Uploaded by

DISTRACTED ??
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)
57 views17 pages

1a Fop

This document provides an overview of structured programming concepts like control statements, subroutines, and blocks. It also discusses flowcharts, including their purpose and common symbols. Examples are given to demonstrate creating sequential and conditional flowcharts. The evolution of C++ from C is outlined. The C++ standard library is introduced to provide pre-made functions. Finally, the basics of a C++ development environment are explained.

Uploaded by

DISTRACTED ??
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/ 17

Fundamentals of Programming

Lecture 1B
Elements of Structured Programming
❑Control statements
• Flow charts
❑Subroutines- a computer program that is stored only once but can be used
when required at several different points in the program, saves space
❑Blocks- used to enable group of statements to be treated as if they were one
statement

2
Flowcharts
❑A graphical representation of the sequence of operations in an
information system or program
❑Information system flowcharts show how data flows from source
documents through the computer to final distribution to users
❑Program flowcharts show the sequence of instructions

3
Flowcharts
Flowchart shows:
❑shows logic of an algorithm
❑emphasizes individual steps and their interconnections
❑control flow from one action to the next

4
Name Symbol Use in Flowchart
Oval Denotes the beginning or end of the program
Parallelogram Denotes an input operation

Rectangle Denotes a process to be carried out e.g.


addition, subtraction, division etc.
Diamond Denotes a decision (or branch) to be made.
The program should continue along one of two
routes (e.g. IF/THEN/ELSE)
Display Denotes an output operation

Flow Line Denotes the direction of logic flow in the


program

5
Example 1
Draw a flowchart to add four subjects marks of a student

Solution:
Marks = Maths, English, Physics, Chemistry
Add = Maths + English + Physics + Chemistry

6
Start

Solution X= E,M,P,C

Add = E+M+P+C

Print Add

End

The above example of flowchart is sequential flowchart


7
Example 2
Draw a flowchart to take average of four subject marks and display
grade on the basis of it
Solution:
Marks = Maths, English, Physics, Chemistry
Avg = (Maths + English + Physics + Chemistry) / 4
Passing Criteria
Less than 50 Fail
Greater than or equals to 50 Pass

8
Start

X= E,M,P,C

Avg = (E+M+P+C) / 4

Yes
Print Pass if Avg >=50

No

End Print Fail

The above example of flowchart is conditional flowchart


9
Practice Task
Draw a flowchart that will calculate the roots of a quadratic equation
(ax2 + bx +c = 0)
Hint: d=sqrt(𝑏*b - 4ac)
Roots: x1 = (–b + d)/2a
x2 = (–b – d)/2a
❑ Input the coefficients (a,b,c) of the quadratic equation
❑ Calculate d
❑ Calculate X1
❑ Calculate x2
❑ Print x1 and x2

10
Evolution of C++ Language
❑During 1970 Dennis Ritchie created C programming language to
develop the UNIX operating system at Bell Labs
❑C was first implemented in 1972
❑C++ development started in 1979
❑Bjarne Stroustrup developed C++ during his PhD
❑C++ is derived from C
❑C++ was called C with classes
❑C++ supports Object Oriented approach

11
C++ Standard Library
❑Collection of classes and functions
❑Avoid reinventing the wheel
❑If a premade function exists, use it rather than writing your own
program

12
Basics of C++ Environment
❑Edit- program is written using editor and stored on disk (.cpp file)
❑Preprocessor- pre process the code before compilation
❑Compiler- creates an object code and stores it on disk(.o file)
❑Linker- links the object code with the libraries, creates an
executable file and stores it on disk
❑Load- puts the program in memory (RAM)
❑Execute- CPU takes each instruction and executes it

13
14
C++ Program

15
Explanation of C++ Program

16
Books Used to Create Slides

17

You might also like