Monday, September 24, 2018

Variable naming convention

Programming languages may have different rules for naming variables

  1. The programming language may be case sensitive.Eg. Add,ADD,add are 3 different variables.
  2. The name of the variable may be indicative of the value it holds.Eg.If you are storing sum of 3 numbers then 'sum' variable will be appropriate name.sum=10+20+30;
  3. Every variable must have a unique name in a program.
  4. Variable names must begin with an alphabet.
  5. THe first character of variable must be followed by letters,digits and can also include special characters as 'underscore'.
  6. Avoid using letter O which may be confused with 0.

Saturday, September 22, 2018

Naming of a variable



A=L X B

where
 A=Area,
B=Breadth
and L=Length of rectangle

To display sum of 3 numbers

algorithm statement would be :

Display the sum of 10,20,30

In programming language same thing will be written as :

sum=10+20+30

Internally,the variable sum is stored in the computer's memory.



Friday, September 21, 2018

Can variables be used in low level languages

Earlier machine language or assembly language was used for writing programs.In such languages,if you need to store data,then the exact storage location inside the memory of the computer has to be assigned.This storage location refers to a specific memory address,which is represented in terms of hexadecimal numbers such as 006FF,112ED.
If you have to store 100 different values,then you have to remember the address of 100 different memoryblocations where the values are stored.This becomes tedious and to avoid this high-level languages are used.
High level languages allow you to use symbolic names known as variables,to refer to the memory location where a particular value is to be stored.

Hierarchy from machine language to high level language



A Diagram depicting the working of a programming language in a computer, meaning after we write code on a computer in a programming language following happens inside computer.





Hardware
|
\/
Machine Language
|
\/
Assembly Language
|
\/
High Level  Language
|
\/
Fortran,C,Pascal



Hierarchy from machine language to high level language



Machine Language:
They send instructions in the form of 0's and 1's which only the machine can understand.

Assembly language:
It contains symbolic machine language instructions.These are called mnemonics.It is little bit english.

High Level Language:
It contains a set of insructions which are simple english like,like spoken languages and are easy to understand and use.C,C++,Pascal,Basic are some exaplesof high level languages in which english words are used as instructions.

The figure shows how computer's hardware,machine language,assembly language and high level language are related to each other.

Variables

Variable is a container used for temporary storage of data.

According to wikipedia,

In computer programming, a variable or scalar is a storage location (identified by a memory address).

Why are variables required?

This can be understood by an example:

If there is a number say 1233344588777669900 which has to be used in multiple calculations,then one way would be to key in the number each time it is required.
The second method would be to use M+ key available in calculator.The momemt we press M+ key,the specified number gets stored in the calculator's memory and can be recalled whenever required by pressing the MR key.
The same appliesto data used in a program.The data,which is repeatedly used has to be temporarily stored in a variable so that it can be accessed when required.

How much memory does variable require?

The amount of memory required to store an integer(number eg.6) is 2 bytes and character eg 'a' is 1 byte. 

Memory allocation is done by programming language not by user.

Flowchart symbols




Flowchart symbols
Flowchart symbols:what they mean?


Oval:Start or end of program.

Parallelogram: Input or output operation.

Rectangle:Decision making & branching.

Circle:Joining of 2 parts of program on same page.

Arrows:Flow lines.





Example of lamp:


Introduction-Algorithm

Algorithm is concise list of steps in english language in short sentences required in solving a problem.

Eg:

1. Check if a given number is even or odd

Algorithm :

1.Start
2. Accept the number.
3.Divide the number by 2
4.If the remainder of the division is zero,then the number is even.
5.Otherwise the number is odd.
6. End

2.Name the fruit.

Algorithm:

1. Start
2.Accept the character.
3.Print"enter alphabet a,b or c"
4. If a is entered,print apple.
5If b is entered ,print banana.
6. If c is entered,print cane.
7.End

3.Tell whether it is a leap year or not.

Algorithm:

1.Start.
2.Accept the year.
3.Print"enter any year.If n mod (%)4==0 or n%400==0) where n is the year.
4.Print "Leap year"
5.Otherwise,print "year is not a leap year.".
6.End



Introduction-Program in general

Suppose we have to add :

10+20

We see there is a plus sign between the numbers.We can understand that it is a sum of addition but the computer can't.It has no brains.To make computer understand this statement we will have to give a set of instructions.This set of instructions is called programming.
:

So,we can say:

A program is a set of instructions which,when executed cause the machine to behave in a predetermined manner.


Programs are written to solve problems.But before writing the program,you should solve the problem by yourself somewhere in rough.
When you have solved the program,just write the main steps somewhere in rough.
This is a rough sketch  of your program.
Thus,the method of solving the problem,it's main steps will make the statements of your program.

In short:

1.Studythe problem.
2.Gather information to solve the problem.
3.Write the main steps to solve the particular problem.
4.Check your result with your book.

In a program,this method of solving the particular program will apply to all such problems.