Top Banner
Zohaib Soomro
35

C++ decision making

Apr 16, 2017

Download

Software

Zohaib Ahmed
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

Slide 1

Zohaib Soomro

1K-15 PG-52

Decision making in C++

Program PreparationProblem Identification stage.a) Defining the problem.b) Analyzing the problem.

Planning stage.a) Developing the algorithm.b) Flow charting.c) Writing Pseudo code.

Cont..Coding and Testing stage.Writing the program.Testing and Debugging the program.Running the program.

Implementing and Documenting stage.Implementing the program.Documenting the program.

The key to good programming is Planning.By spending more time in the planning phase,it is normally possible to save time in writing,testing and implementing a program.In many cases better planning can reduce total programming time and cost.K-15 PG-525

Developing the AlgorithmAlgorithm is a step-by-step procedure developed to solve a problem before writing an actual program.

Algorithm is a complete procedure or plan that describes the logic of a program.

Flow ChartingThe pictorial form is referred as a flow chart, which is a pictorial representation of an algorithm.

The written form of the algorithm (not in computer language) is called pseudo code. Pseudo code expresses the basic logic structure of an algorithm in a systematic and clear way.

Flow Charting SymbolsFlow line: A line with an arrow head represents the flow of control between various symbols in aflow chart.Terminal symbol:

Input/output Symbol

startStop

Cont..Processing symbol: A rectangular block is used to represent processing symbol. It showsall the calculations.

Decision Symbol:

Decision making in C++Decision making is about deciding the order of execution of statements based on certain conditions or repeat a group of statements until certain specified conditions are met. C++ handles decision-making by supporting the following statements,

ifstatementswitchstatementconditional operator statementgotostatement

Decision making with If statementTheifstatement may be implemented in different forms depending on the complexity of conditions to be tested. The different forms are,

SimpleifstatementIf....elsestatementNestedif....elsestatementelse ifstatement

Simple if statementThe general form of a simpleifstatement is,if (expression{statement-inside;{statement -outside;

If theexpressionis true, then 'statement-inside' it will beexecuted, otherwise 'statement-inside' is skipped andonly 'statement-outside' is executed.

Example :#include< iostream.h>int main( ){int x,y;x=15;y=13;if (x > y ) {cout y ) { cout Case Case Case Case default

OPERATORS USE IN C++ PROGRAMMING

There are many operators used in c language

Arithmetic or Mathematical OperatorsRelational OperatorsLogical Operators

Go to statementAgo tostatement provides an unconditional jump from the goto to a labeled statement in the same function.SYNTAX :The syntax of a go to statement in C++ is:go to label; .. . label: statement;

Wherelabelis an identifier that identifies a labeled statement. A labeled statement is any statement that is preceded by an identifier followed by a colon (:).

Flow chart

Looping in C++Loops : :- repetition of instructions is called loop there are following loop in c language .

How it worksA sequence of statement is executed until a specified condition is true. This sequence of statement to be executed is kept inside the curly braces{ }known as loop body. After every execution of loop body, condition is checked, and if it is found to betruethe loop body is executed again. When condition check comes out to befalse, the loop body will not be executed.

There are three types of loop in C++ whileloopforloopdo-whileloop

While loopwhileloop can be address as anentry controlloop. It is completed in 3 steps.

Variable initialization.( e.g int x=0; )condition( e.g while( x