[Android General] mhrsolanki2020:
Chapter 3

FlowCharts(...Continued)​

I hope you have done the exercises and have checked the answers and rectified yourself if you were wrong.

Still i would like to discuss the 4th Problem of the Exercise as i Had some purpose for giving that sum.

So when you were doing the flow chart , you would have encountered a problem.

Lets not go to flow chart directly, lets talk on it as if it were a math problem .

Add the two numbers and subtract the addition with their product: (considering the two numbers are 2 and 3)

Let the two numbers be a and b.
a=2
b=3
a + b = 5
a x b = 6
(a x b) - (a + b) = 1

NOTE:

You know there are variables in maths?? like x = 2 or x= 7 or y = 10 etc etc..

Ever thought why they are called variables??

It is because their values keep on changing in other words "The value of x VARIATE"

Just Keep it in mind, i would ask you to recollect it after done with this 4th Flowchart Problem

​

Doesnt it seem too long and boring to write(m talking about (a x b) - (a + b) )?

That's where the flowcharts and all the computer programming languages have a plus point . You will realize it in a minute..

See the flow chart:

See the names underlined with red ink. Sum , Product and Answer.

(referring the flowchart with the above mathematical representation)

Here, when a+b is calculated , the answer is stored in "Sum"

ie:

Sum= a + b

Similarly, when a x b is calculated , the answer is stored in "Product"

ie:

Product = a x b

When Product(ie a x b) is subtracted to Sum(ie a+b) it is stored in "Answer"

ie:

Answer = Product - Sum

Recollect the note above, about the variables and read bellow.

What is a Variable?

-> Variable is a vessel that holds a Value . Where as this value is known as constant.

Eg: x , y , z , a , b , c etc etc

What is Constant?

-> Constant is that value that is stored in a Variable.

Eg, 1 , 2 , 3 , 4 , 5 , 6 etc etc

In all the flow chart above,

These were the variables you used:

Number 1

Number 2

Sum

Product

Answer

You can use the Variable Number 1 again and the value of Number 1 in a different flow chart would be different . Hence it is a variable.

But in any flow chart the value of "1" will remain "1" only.. it wont ever be like 1 = 2.

Hope you are getting my point.

This variable is not just for Flow Chart. Learn Any programing , the knowledge of what is variable and constants is necessary , its like the most basic thing .

So to Sum up and give a summary of variables and constants,

A variable is something like a vessel , a vessel that holds the constants. Constants are the values that are stored in vessel which is nothing but a Variable.

We will talk on this later again when we start the c programming.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

As in maths , Constants are limited to numbers. For eg , X = 10 , Y = 15 etc etc

But this is not the case with flowchart , In flowchart you can even write a word or a sentence in a variable.

Eg,

Day = " Wednesday"

Month = " October"

Name = " Mihir"

Birthdate = "1st January 0000"

Mobile no = " 123456789"

Pi = "3.148"

Etc etc...

So as you can widely distinguish , variables in FlowCharts are of 2 Types,

1) Character Variable, Eg, Name = "XDA"

2) Numeric Variable(also known as Integer variables , as Integer contains all the numbers ) , Eg, Num = " 12345"

So when you make flow chart you have to Define all the variables you use if they are number? or they are Character?

See the flow chart below to understand how.

As you can see everything is new in this flowchart.

This is the way we represent a program in a better way in flowchart.

Let me explain to you all of its components.

All of which is written in green above, is like a system command sort of a thing.

And all the red color text are variables.

And all of the blue color things are Operators ( mean + , - , x , = etc, we will talk all about operators in next chapter)

System:

START starts the program

NUMERIC defines that the following variables are Integers/numbers and is written always in processing box. (this process is called DECLARATION we will talk about it in a while).

ACCEPT Accepts constants from the user and stores it in the Variable, always written in input box.

DISPLAY Displays the constants stored in the variable.

STOP Stop/terminates the flowchart/program

Meaning of Declaration!

=> When you want to use a variable, lets suppose u want a variable Num1 , Then you first have to tell the computer that:

"Hey bro, i am using a variable named Num1 in my program which is a numeric variable"

which in flowchart is written as :

[COLOR="SeaGreen"][B]NUMERIC[/B][/COLOR] [B][COLOR="Red"]nNum1[/COLOR][/B]

As you can see that we are talking to the computer and telling that we are using the variable of this name , it is AS good AS a process?

Hence, it is written in a Processing Box.

As you can see i am prefixing all the numeric variables with n , and you might be wondering , what is this crazy guy talking ?

Basically,

All the variables are prefixed to show what type of variable it is when we use them .

meaning, when we use a numeric variable , we prefix it with n, when we use a character variable we prefix it with c

You can name the variable what ever you like , a, b ,c sum , interest , principle,Name, blah blah etc etc.. anything you like cuz when you will write it in flow chart it will be like nSum, nInterest, nPrinciple , cName. So u will know that Sum ,interest & Principle are numeric variables and Name is a Character variable. Hope now you understand whats the use of prefixing n and c in variable name.

Lets talk about the above flow chart step wise now(referring the numbers in the image above):

After the program starts,

1. There is a Process box. As you know it declares (recollect, declaration means to tell computer that you are using this variable) the variable, hence it is in the process box. In this box the Variables are declared as Numeric and hence are prefixed with n .

2. There is a Input box. What do we do in input box? we take input , and hence there is a proper word defined for it . Accept , and we then write all the variables that we want the values of , from the user.

3. There is a processing box, It adds the two numbers and then stores the value in the Variable Sum which is numeric ( nSum) (it will be clear when i teach you operators in next chapter)

4. There is a Output box, its purpose is to DISPLAY , hence we write Display and then we write all the variables in the Output box that we want to display.

and the program terminates..

======================================================================

Dont give up, let the things sink in. It will take time , you will learn! Trust your self :)

======================================================================

I would like to advice you to read this again. As you will get a better understanding of it now. And i have added some things in it so dont skip it.

======================================================================

Input:

The Input symbol is used when the user has to input something , in other words it denotes that user will input at this point of program.

eg: the program is about multiplying the two numbers, so the program will ask the user to input two numbers to multiply in this box, 2 and 4

When you want to accept the values from user , you write it in an Input Box. lets suppose you want to Add two numbers , for that you need Three Variables, One variable for storing The first number, second variable for storing the second number , third variable for storing the value of the addition of two variables. And lets name these variables now, nNum1,nNum2 and nSum. So how will you write it in input box?

This way

"Accept nNum1 and nNum2"

Processing:

The Processing symbol is used to show that there will be some processing in the program now.

eg: after the two numbers are accepted, the process of multiplication is shown in this box. 2 * 4

Two things that can be in processes :

The first process box is above, it is used to declare variable with its type,

lets consider the same above example , then u wud write it

"Numeric nNum1, nNum2 and nNum3"

And then you need to add those numbers? correct so you would add it in another processing box like this:

"nSum = nNum1 + nNum2 "

Output:

The result after processing is done, ie after the two numbers are multiplied , the output is given to the user by this symbol.

eg: 2 * 4 = 8

The main purpose of Output box is to show the output.

See the pic below

As we want to display , so we write "Display" in this box. Suppose you want to display Sum calculated above, you would do it this way:

"Display nSum".

We can also write what ever we want in double inverted comas.

Eg

Display "Hie this is Mihir"

You can even append a variable after it, the constant stored in that variable will be displayed,

Lets suppose there is a variable nNum , in which the Mobile number of a user is saved and the number is 123456789, then you can display it this way:

Display "Your Mobile number is" nNum

This will display , Your Mobile number is 123456789

Decision:

Some times , its essential for the program to make decisions, this can be achieved with the use of this symbol

eg: If you want the user to input two numbers two multiply, but both the numbers should be less then 5, here u can check if the user has given input as per that , if yes then the program will execute(do the work) the way u code for yes, if no then you have to code a different set of code or re run the program.

Here checking statement means to check something. Eg nSum < 10 or nSum > 10 , nNum <100 etc etc (as of now it consists only of Single Check statement , like you can just see if its a variable is less that 100 and similar things . You cant compare it with two things like a variable is greater than 50 but is less than 100. As of now i cant. We first have to understand operators, after done with operators , we will come back here and talk about it.)

If you were to check if the nSum is less than 100 you would write:

"Is nSum<100 ?"

======================================================================================

Plz read the output box again i have added something. This is for the users who have read the post yest. And i have edited it just now.

======================================================================================

A flow chart for registration.

i guess you can now understand this flowchart above , and i need not explain it to you. :)

======================================================================================