Module 1.1 PDF

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 28

Master of Computer Applications

Name of the Course : Problem Solving using C

Module.1. Algorithms and Flowcharts

Course Co-ordinator: Prof. S. P. Sreeja


Course Code: 18MCA11
➢C is a popular general purpose
programming language, designed and
developed by Dennis Ritchie @ Bell Labs
in 1972

➢C is a middle level computer language


which combines the features of high
level & functionality like assembly level
language.

2
 C is a structured language which
allows variety of programs in small
modules. It is easy for debugging,
testing & maintaining if the language is
a structured one.

 Developed by the committee ANSI


(American National Standard Institute)
Standard in the year 1983 & Marketed
in the year 1990.

3
 Program – a set of detailed, step-by-step
instructions that directs the computer to
process data into information.
 Programming is combination of art and
science, because you may code a program
however you like as long as you follow the
language’s rules.
 Programming language – a set of rules (syntax)
and commands that provides a way of telling
the computer what operations to perform.
 Programmer – designs algorithm and converts
it into computer instructions and tests
programs as developed.

4
 Six main steps
1. Defining the problem
2. Planning the solution
3. Coding the program
4. Testing the program
5. Documenting the program
6. Implementing the program

5
 Design the algorithm
 An algorithm is a finite series of
logical steps required to solve a
particular problem.

6
 An algorithm is a step-by-step description of the solution to a
problem. It is defined as an ordered sequence of well-defined
and effective operations which, when carried out for a given set
of initial conditions, produce output, and terminate in a finite
time.

 The term “ordered sequence” specifies, after the completion of


each step in the algorithm, the next step must be
unambiguously defined.
 An algorithm must be:
• Definite
• Finite
• Precise and Effective

7
 We use algorithms almost daily in our lives
without realizing it
 For example

an instruction manual
a cooking recipe
a knitting pattern

8
Aim: To write a C program for adding two
numbers

1)Start the program


2)Declare the variables a, b and c
3)Read the values of a, b
4)c= a +b
5)Write the value of c
6)Stop the program

*
 A flowchart is a pictorial representation of an
algorithm or logical steps.
 Each step is represented by a symbol and the
arrows indicate the flow and order of the
steps.
 The shape of the symbol indicates the type of
operation that is to occur.
 Flowcharts may help the more visual students
learn and understand logic.

10
11
Begin or End Input or Output

Processing Decision

Branch or Direction of Flow


12
*
 Flow control is the order in which
statements are executed.
 There are four control structures.
1. Sequence Control
2. Selection Control
Also referred to as branching (if and if-else)
3. Case Control (similar to selection)
4. Repetition Control (loops)

14
Begin

Input
price, qty

subtotal =
price * qty;

Output
subtotal

End
15
Input
Weight

True
If weight < 10 Handling = 1.00

False

Handling = 3.00

Output Handling
16
17
18
 Pseudocode is a mixture of programming
code and English like statements.

 Used when designing algorithms.

 When designing, we don’t necessarily need


to be concerned about specific function
names. We want to concentrate on the
design.

19
 Translate solution algorithms into a
programming language
 Enter program code into programming
development tool using correct syntax
 Include comments in program
 Use good structure so you don’t
 create spaghetti code

20
Testing the Program
⚫ Remove syntax and logic errors
⚫ Syntax error - when code violates language rules, errors
are displayed by the programming development tool.
⚫ Logic error – when program does not generated expected
output when using the test data. Error must be found by
programmer.

21
 Programmer name and date
 A narrative description of the
program
 Include comments within the source
code
 Flowcharts and/or pseudocode
 Layouts of input and output records
 Testing procedures

22
Implementing & Maintaining
⚫ Programs may be part of a system
implementation or single program
implementation.
⚫ Training, user manuals, technology upgrades,
and conversions must be taken into consideration
during implementation.
⚫ Programs may be enhanced to add new features
or functionality

23
A compiler translates all of the
source code into object code,
an executable program. During
this translation process, a
program listing of any syntax
errors is produced.

An interpreter translates one


line of the source code at a
time. Interpreters run programs
more slowly than compilers, but
they are helpful programs for
finding syntax errors, because
they are interactive.

24
 Procedural Programming
◦ Programmer must provide step-by-step instructions, telling the
computer what to do and how to do it.
◦ Logic begins at the top and flows down.
◦ Non-procedural language, such as SQL in a relational database, the
programmer specifies what is needed, and the language
determines how by using the data dictionary.
 Event Programming
◦ A program listens for and reacts to events such as mouse click on a
button.
 Object-Oriented Programming (OOP)
◦ Use classes to build programs.
◦ A class definition includes properties (data) and methods
(procedures) to manipulate the properties.
◦ Classes are used to declare objects that are considered an instance
of the class.

25
 BASIC (Beginners’ All-purpose Symbolic Instruction Code –
1960s)
 COBOL (Common Business Oriented Language 1960s)
 C - Used to develop UNIX in 1970s;
runs on most operating system now
 C++ - A better C, Object oriented; (1980s)
 Java - Similar to C++;
Became popular because of web development – applets,
Programs run on multiple platforms (Win, Unix, Mac),
Originally named Oak (1991) and renamed to Java in 1995
 Visual Basic – Microsoft created language so that graphical
user interfaces could be created for their new operating
system – Windows (1990s)
 C# (c-sharp) – Microsoft’s newest language (2002);
syntax is similar to Java, but uses the same library items as
VB.

26
 Sum of 2 numbers
 Calculate Simple and compound interest
 Convert Celcius into Fahrenheit and Vice
Versa
 Find out the area of a triangle
 Find out the largest of 2 numbers
 Find out whether the given number is ODD or
EVEN
 Find the factorial of a number

27
➢ Simple & Compound
SI = ((p*r*n)/100);
q = 1+(r/100);
CI=p*pow(q,n)-p;

➢ Celsius to Fahrenheit and vice versa


fahrenheit = (1.8 * celsius) + 32;
celsius = (fahrenheit-32) / 1.8;

➢ area of a triangle
s = (a + b + c) / 2;
area = sqrt(s * (s - a) * (s - b) * (s - c));

28

You might also like