Wednesday, May 12, 2010

Recursion – Life Cycle- what you give that come back

In computer often, we have to use a recursive function. Often it is easy to perform a routine by using a recursive function than using a loop.

Recursive Function: is one that calls itself. A main function cannot be use as a recursive function. Must have a base function from which we call the recursive function and after at one point control will back to the same function.

Not all programming languages support recursion. Want to use Iteration (Loops) or Recursion it is dilemma, please follow these and take you decision :

  • Iteration is faster and occupies less memory.

  • In some problems will be easier using recursion.

  • All Recursive function may always be replace by iteration.

  • Converting Recursive function to iteration is called “unrolling”.

Advantage of Recursion

  • Expressive Power

  • Shorter code in recursion than iterative.

  • Problems it is more appropriate.


Disadvantage of Recursion

  • Slower than Iteration

  • Big programs will be very difficult to debug.

  • Use of more memory space

I will give a few Programs that use recursive function. Remember that every recursive function needs a logical escape route, otherwise system will hang.

In first program, I am giving you a factorial of ‘N’ number. I am using Integer declaration; it will work up to a smaller number only for big value use long or double. Also, check for negative values.




//Factrial using Recursion - C
#include <stdio.h>
#include <conio.h>
//sending n-1 and when value of n=1 the resul return to main function
static int fact(int n) //Recursive function
{
if(n<=1)
{
return n;// return to main program
}
else
{
return n*fact(n-1);// calling self
}
}

void main()
{
int n,f;
clrscr();
printf("Enter a No. : ");
scanf("%d",&n);
f=fact(n);
printf("Factorial of %d = %d ",n,f);
getch();
}



//Fibonacci Series - C
#include <stdio.h>
#include <conio.h>

int fibo(int n,int a,int b)
{
int c;
if(n<=1)
{
return 0;
}
else
{
c=a+b;
printf(" %d ",c);
return fibo(n-1,b,c);
}
}
//this main function we are not printing anything
void main()
{
int n;
clrscr();
printf("Enter a No. : ");
scanf("%d",&n);
n=fibo(n,1,0); // 1 and 0 the value of a and b
getch();
}


//Factrial using Recursion - Java

import java.io.*;
public class Rfactorial
{
//sending n-1 and when value of n=1 the resul return to main function
static int Rfact(int n) //Recursive function
{
if(n<=1)
{
return n; // return to main program
}
else
{
return n*Rfact(n-1); // calling self
}
}

public static void main(String args[])throws IOException
{
int n,f;
BufferedReader Br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a No. : ");
n=Integer.parseInt(Br.readLine());
f=Rfact(n);
System.out.println("Factorial of "+n+" = "+f);
}
}



//Fibonacci Series - Java

import java.io.*;
public class Rfibo
{
static int fibo(int n,int a,int b)
{
int c;
if(n<=1)
{
return 0;
}
else
{
c=a+b;
System.out.print(c+" ");
return fibo(n-1,b,c);
}
}
//here in main function we are not printing anything
public static void main(String args[])throws IOException
{
int n;
BufferedReader Br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a No. : ");
n=Integer.parseInt(Br.readLine());
n=fibo(n,1,0); // 1 and 0 the value of a and b
}
}


!!!Flying to Fiji Island and say you Moce Mada but in reply you have to say Vinaka!!!

Thursday, April 22, 2010

Arrays - that only moves between Rows and Columns

We already know that a variable cannot store more than one data at a time. Whenever we store a data in a variable it overwrite the old one. So if we want to store a same type of data and more than one we have no choice that we have to declare multiple variable. It is possible for small amount of data but not more, so here we need an array. Array is a variable with capability to store multiple data with an unique location can be compared with a cupboard with many racks.

What are Arrays?

To store similar types of data under a common variable name, instead of declaring N number of variables for the N number of data, we use an array. An array is a collection of similar type of variables under a common variable. Thus we can have a collection or Array of integers, floats, characters (which are known as strings), but remember that all elements of any given array must be of the same type, i.e. we cannot have an array of numbers some of which are int and some float etc. Either all should be int or all should be float or all should be char. The different components of an array are called the Array Elements. Arrays also known as subscripted variable

How to Declare an Array:

Like all other variables, an array needs to be declared first before it can be used. The declaration consists of stating the type of data-type used in the array, the name of the array and the number of elements in the array.

Data Type Array_Variable[ number of elements ] ;

Example :

(C or C++) : int age[20]; float salary[20]; char name[20];
In C/C++, char array indicate a String.
Java : int a[]=new int[20]; String name[]=new String[20];
Basic : dim n(10), a$(10)

Suppose we declare an array if integer with 5 elements, N[5] then

N[0]
N[1]
N[2]
N[3]
N[4]
Here N is variable and [0] to [4] is subscript or element location. When we input data in N[0] to N[4] location we can recall back in any point in that particular program. Above array also known as single dimensional array. We can initialize the array with a list of values.

Example :

(C or C++) : int age[4]={23,45,67,89};
char name[20]={"Anil","Sunil"};
Java : int a[]={1,5,6,7};
String name[]={1,5,6,7};

Initialization can be done when we use a fixed numbers of known data but there is no shortcut method to initialize large number of elements. Enter in data in an Array and printing back. Some example of Input and display the array elements.

C C++


#include<stdio.h>
#include <iostream.h>
#include<conio.h>

void main()
{
int N[5],i;
printf("\nEnter 5 Nos "); // cout<<"Enter 5 Nos. ";
for(i=0;i<5;i++)
{
scanf("%d",&N[i]); // cin>>N[i];
}
printf("\nNos in Array"); // cout<<"Nos in Array ";
for(i=0;i<5;i++)
{
printf("%d ",N[i]); // cout<<N[i];
}
getch();
}

Java


import java.io.*;
class Arrays
{
public static void main(String args[])throws IOException
{
BufferedReader Br=new BufferedReader(new InputStreamReader(System.in));
int N[]=new int[5], i;
System.out.print("Enter 5 Numbers : ");
for(i=0;i<5;i++)
{
N[i]=Integer.parseInt(Br.readLine());
}
System.out.print("\nNumbers in Array : ");
for(i=0;i<5;i++)
{
System.out.print(N[i]+" ");
}
}
}

Multi dimensional Arrays:

Where Single Dimensional Arrays has one column and multiple rows, multi-dimensional arrays has multiple rows as well as multiple columns. Milti-dimensional data structure also known as matrices. A multi-dimensional array with 3 rows and 3 columns is shown. There are two array subscripts. One subscript denotes the row & the other the column.

N[0][0]N[0][1]N[0][2]
N[1][0]N[1][1]N[1][2]
N[2][0]N[2][1]N[2][2]
data_type array_variable[row_size][column_size];
The declaration of two dimension arrays is as follows:
(C/C++) : int N[4][5] ;
Java : int N[][]=new int[4][5];

Here m is declared as a matrix having 4 rows( subscript from 0 to 3) and 5 columns subscript 0 through 4). The first element of the matrix is N[0][0] and the last row last column is N[3]4]. When a matrix declared with same numbers of rows and column, is known as square matrix. The initialization is done row by row. Initializes the elements (C/C++)

int N[2][3]={5,1,2,3,4,5};
int N[][]={{2,3,4},{4,5,6}};

Some example of Input and display the multi-dimensional array elements.

C C++


#include<stdio.h>
#include <iostream.h>
#include<conio.h>

void main()
{
int N[3][4],i,j;
printf("\nEnter 12 Nos "); // cout<<"Enter 12 Nos. ";
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
scanf("%d",&N[i][j]); // cin>>N[i][j];
}
}
printf("\nNos in Array"); // cout<<"Nos in Array ";
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
printf("%d ",N[i][j]); // cout<<N[i][j];
}
}
getch();
}

Java


import java.io.*;
class Arrays
{
public static void main(String args[])throws IOException
{
BufferedReader Br=new BufferedReader(new InputStreamReader(System.in));
int N[][]=new int[3][4], i,j;
System.out.print("Enter 5 Numbers : ");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
N[i][j]=Integer.parseInt(Br.readLine());
}
}
System.out.print("\nNumbers in Array : ");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
System.out.print(N[i][j]+" ");
}
}
}
}


!!!Its too hot around here, take you all the way to Canada and for time being
say you Matcaci!!!

Thursday, March 25, 2010

Operators - This operation is not painful

Operators – An operator is a symbol or letter, which makes the computer perform specific operation in a programming statement.

Assignment Operator =Assigns a value to a variable or property.
variable = value
variable : Any variable or any writable property.
value : Any numeric or string literal, constant, or expression.

Remarks
The name on the left side of the equal sign can be a simple scalar variableor an element of an array. Properties on the left side of the equal sign can only be those properties that are
writable at run time.

Arithmetic Operator - Operators that perform numeric calculations known as arithmetic operators are: + (addition), – (subtraction), * (multiplication), / (division) and % (modulus).

Relational Operator - An operator that manipulates numeric and other values to produce a logical result. The relational operators are <, <=, >, >=, = = and !=.

Unary Operator - The unary assignment operators, use two operand instead of one, for the increment (++) and decrement (– –) operators. Its also call
increment/decrement operator. a++, a--, a+=10.

Unary-Operator : one of & * + – ~ !

Ternary Operator – Can be used to replace certain of if – else-if statement. Its require three operands to work on. It represent by the ? and : symbols. Expression1?Expression2:Expression3. e.g. tax = salary>10000?salary*0.05 : 0; (if variable salary stored more than 10000 then tax variable will calculated 5% of salary otherwise tax will be).

Logical Operator - An operator that produces a logical result (true or false); sometimes called a Boolean operator. The logical operators are used for expression grouping, NOT or ! (negation), AND (Creates a Boolean behavior that represents the logical AND of the given behaviors. The behavior's value is true when both b1 and b2 are true; otherwise, it is false. OR (Creates a Boolean behavior that represents the logical OR of the given behaviors. The behavior's value is true when either b1 or b2 are true; otherwise it isfalse).

Binary Operator – This operator do the binary operations between two or more variables. Also known as bits operator. The bitwise operators perform bitwise-AND (&), bitwise-exclusive-OR (^), and bitwise-inclusive-OR (|) operations. E.g. 101 & 100 = 100 (Multiplication). 101 ! 100 = 101 (Addition). 101 ^100 = 001(If one bit is 0 and the other bit is 1, the corresponding result bit is set to 1. Otherwise, the corresponding result bit is set to 0). Right shift  >>; Left shift << (The value of a right-shift expression e1 >> e2 is e1 / 2e2, and the value of a left-shift expression e1 << e2 is e1 * 2e2).

One thing I can assure you that these operators will never ditch you. So, use these and if want anything can leave a comment or mail me back.

!!!Once more time has come to say you  Tofa, see you next week.!!!

Thursday, March 18, 2010

Built-in-Functions (String) – Enjoy it!

Let us plunge to another episode of functions, I know it is boring; at the same time it is most handy when you want to finish a program with lots of mathematical formula. Last week I have gone through a few numerical functions and the way functions help us for converting one data type to other. Today mainly I will discuss about string function, which only valid to string type data. String handling is not an easy job and you will find many functions available for this, but often while you write a program, you will be asked to write your own functions only and prohibited from using some of the string function. So, how to do this I will come to this when we talk about programming. String functions in Java return value is string but some return integer also. In java java.lang is default package so you do not need any extra package to be import but in C/C++ you require "string.h".

Note : Str - is the String argument you have to pass and Num is a Number of character and pos is the position.

DescriptionBasicC/C++Java
Find the length of a string value
len(Str$)

strlen(Str)

Str.length()
Extract a character from the said string from given
position

mid$(Str$,pos,num)

str(pos)

Str.charAt(pos)
Check equality between two string and return a
Boolean value/

Str1.equals(Stri2)
Check equality between two string ignoring he case
difference and return a Boolean value.

Str1.equalsIgnorecase(Str2)
Compare between two string( relevant to the ASCII
values of each character), if both equal it return 0, if String1 is
smaller than String2 then it will return -1 and if String1 is bigger
than String2 then it will return 1.

strcmp(Str1,Str2)
strcmpi(Str1,Str2)
(strcmpi() - for ignoring
case)

Str1.compareTo(Str2)
Extract all the string from given position till end.

String.substring(int)
Extract all the string from starting position up to
left of end position.

mid$(Str$,pos,num)
left$(Str$,num)
right$(Str$,num)
Using any loop from 0 position till
length of the string, we can extract character by character
Str1.substring(int,int) -
Join String2 to the right of String1Str1$+Str2$strcat(Str1,Str2)
Str1.concat(Str1)
This can be done by:
String1=String1+ String2.
Returns the index within this string of the first
occurrence of the specified character.

Str.indexOf(char/string)
Returns the index within this string of the first
occurrence of the specified character, starting the search at the
specified index.

Str.indexOf(char/string,
int)
Returns the index within this string of the last
occurrence of the specified character.

Str.lastIndexof(char/String)
Tests if this string starts with the specified
prefix.

Str.startswith(String)
Tests if this string ends with the specified suffix.
Str.endsWith(String)
Removes white space from both ends of this string.
Str.trim()
Returns a new string resulting from replacing all
occurrences of oldChar in this string with newChar.

Str.replace(char, char)
Str.replace(Str1, Str2)
Converts this String to lowercase / Converts this
String to upper case.
strlwr(Str) / strupr(Str)Str.toLowerCase() / Str.toUpperCase()
Converts this string to a new character array.Str.toCharArray()
In java we also having StringBuffer, so giving you some idea of this class-

A string buffer implements a changeable sequence of characters. String buffers are safe for use by multiple threads. The methods are
synchronized where necessary so that all the operations on any particular
instance behave as if they occur in some serial order. String buffers are used by the compiler to
implement the binary string concatenation operator +. For example, the code:

x = "a" + "4" +"c";

is compiled to the equivalent of:

x = new StringBuffer().append("a").append(4).append("c").toString()

Functions under StringBuffer
DescriptionJava
Constructs a string buffer with no
characters in it and an initial capacity specified by the length
argument.

StringBuffer()

Constructs a string buffer with no
characters in it and an initial capacity of 16 characters.

StringBuffer(int)
Constructs a string buffer so that it
represents the same sequence of characters as the string argument.

StringBuffer(String)
Appends the string representation of the
boolean argument to the string buffer.

append(boolean)
Appends the string representation of the
char argument to this string buffer.

append(char)
Appends the string representation of the
char array argument to this string buffer.

append(char[])
Appends the string representation of a
subarray of the char array argument to this string buffer.
append(char[], int, int)
Appends the string representation of the
int, float or double argument to this string buffer.

append(int) /append(float) /append(double)
Returns the current capacity of the
String buffer.

capacity()
Returns the character at a specific
index in this string buffer.

charAt(int)
Inserts the string representation of the
char argument into this string buffer.

insert(int, char) **
Inserts the string representation of the
char array argument into this string buffer.

insert(int, char[])
Returns the length (character count) of
this string buffer.

length()
Characters are copied from this string
buffer into the destination character array.

getChars(int, int, char[], int)
Sets the length of this String buffer.
setLength(int)
The character at the specified index of
this string buffer is set to ch.
setCharAt(int, char)
The character sequence contained in this string
buffer is replaced by the reverse of the sequence.
reverse()
Converts to a string representing the data in this
string buffer.
toString()
** Insert can be used as append for numeric too.

Here is a example, how we can use string buffer
System.out.println("StringBuffer insert and append example!");

StringBuffer sb = new StringBuffer(0);

System.out.println(sb.insert(0, "vinod"));

int len = sb.length();

System.out.println(sb.insert(len, "Deepak"));

System.out.println(sb.insert(6, "Raj"));

System.out.println(sb.append("Mohit"));



Database packages also provide some date and database functions, while writing about database I certainly cover those functions. I also remind you that if you feel anything left out then can suggest me, your suggestion will be always welcome.
!!!I know most of the students are busy with their respective examination and hardly have time to join this function, so Aburz for all.!!!

Thursday, March 11, 2010

Built-in-Functions (Maths) – Enjoy it!

Readymade with zero price tag and unlimited access, that is how I can describe a built-in-function. All programming languages having certain amount of built-in-function, which written as subroutine or function to solve a certain requirement, while writing a program you can, call these functions by sending arguments that required or with no arguments.

It is not that we cannot solve these, but when it is available, we just use it. Built-in-functions come in different types depending upon data types – Numeric, Date, String, Database etc. I will cover this topic in two weeks and with a few which we use frequently.

Numeric or math function to solve a mathematic routine like square root and other. Many math functions in Java return value is double type but you can take help of  type casting to get it in integer. In java java.lang is default package so you do not need any extra package to be import but in C or C++, you have to include "math.h" but for min() and max() in C/C++ you require
"stdlib.h" or often "complex.h"
Note : Num - is the numeric argument you have to pass.

Description

Basic

C & C++

Java

Returns the square root of a double value.

sqr(num)

sqrt(num)

Math.sqrt(num)

Returns the absolute value of a double value.

abs(num)

abs(num)

Math.abs(num)

Returns of value of the first argument raised to the power of the second
argument.

pow(num,num)

Math.pow(num,num)

Returns the smaller of two Numeric values.

min(num,num)

Math.min(num,num)

Returns the larger of two Numeric values.

max(num,num)

Math.max(num,num)

Returns the trigonometric sine, cosine and tangent of an angle where
argument should be in radian.

sin(num)
cos(num)
tan(num)

sin(num)
cos(num)
tan(num)

Math.sin(num)
Math.cos(num)
Math.tan(num)

Returns the exponential number  (i.e., 2.718...) raised to the
power of a double value.

exp(num)

exp(num)

Math.exp(num)

Returns the smallest (closest to negative infinity) double value that is
not less than the argument and is equal to a mathematical integer. 
ceil(12.5) = 13,
ceil(-12.5) = -12

cint(num)

ceil(num)

Math.ceil(num)

Returns the largest (closest to positive infinity) double value that is
not greater than the argument and is equal to a mathematical integer.
floor(12.5) = 12,
floor(-12.5) = -13.

fix(num)

floor(num)

Math.floor(num)

Returns a random number between 0.0 and 1.0

rnd(num)

random()

Math.random()

Return a double number that represents the closest integer to the double
parameter. rint(2323.43) =23.0, rint(2323.83) =23.0

 
Conversion - while writing a program we often have to change a data type to another. In C/C++, you need to include "stdlib.h". Here some example

Description

Basic

C & C++

Java

Integer to String

str$(num)

itoa(num,string,10) *

Integer.toString(num)

float to String
 -
do -

fcvt(num,ndigit,&dec,&sign)

Float.toString(num)

double to String
 -
do -

Double.toString(num)

String to Integer

val(string)

Integer.parseInt(String)

String to Float
 -
do -

Float.parseInt(String)

String to Double
 -
do -

Double.parseInt(String)
* 10 is the radix or base value, indicate that String value should be converted in Decimal. Binary (2), Octal (8) and in Hexadecimal (16).

Now these days Fortran and Pascal can be seen anywhere in the scenario, but some engineering Colleges having Fortran in their 3rd semester, so few Mathematical function for these programming languages are given below :

Description

Fortran

Pascal

Returns the square root of a double value.

sqrt(num)

sqrt(num)

Returns the absolute value of a double value.

abs(num)

abs(num)

Returns of value of the first argument raised to the power of the second
argument.

sqr(num,num)

Returns the trigonometric sine, cosine and tangent of an angle where
argument should be in radian.

sin(num)
cos(num)
tan(num)

sin(num)
cos(num)
tan(num)

Returns the exponential number  (i.e., 2.718...) raised to the
power of a double value.

exp(num)

exp(num)

This returns a real number whose value is the integer part of the real
value x. For example, Int(8.3), give you 8

int(num)

Int(num)

Modulus eg. mod(8,5) will give you remainder 3.

mod(num,num)

Next week coming with String functions. One thing I like to tell you, I often write my own packages for certain things and call my home made built-in functions, as I always like the challenge, but give you a tip too -
!!!Do not take too many challenges while appearing for exam, as exam itself is too challenging, happy finally time to say you Allez ciao!!!

Thursday, March 4, 2010

Methods or User Defined function- Sleek and beautiful

Methods in many programming languages are actually the Functions or Subroutines, are often referred to as 'methods'. Different programming languages provide different idea how a User Defined Function should invoked. Some programming language instead of UDF it is called as Subroutine. These are both refer to as Methods or User defined functions (UDF).

Function - a function is a sequence of commands or programming code that returns a value. A function that is available through a simple reference and specification of arguments in a given higher-level programming language. Also known as built-in procedure; intrinsic procedure; standard function.

Subroutine - a SUB is a sequence of commands or programming code, but it does NOT return a value. Subroutine used in Visual Basic, Visual Foxpro.

In Object Oriented Programming languages - A method is an object's abilities. Methods or functions are the modules from which java program is built. Method can be declared with -

access-specifier, modifier, type, method-name (parameter list), where access specifer is optional. Methods also known as functions. access-specifier – private/ public/protected.

Note that Interface method visibility is public by default. You do not need to specify the access modifier it will default to public. For clarity it is considered a good practice to put the

public keyword. The same way all member variables defined in the Interface by default will become static final once inherited in a class.

Access modifiers
You surely would have noticed by now, the words public, protected and private at the beginning of class's method declarations used, these keywords are called the access modifiers.

protected keyword is a modifier that can be used in the declaration of methods or variables. A protected variable or method is only visible within its class, within its subclasses, or within the class package.

private keyword is a modifier that can be used in the declaration of methods or variables. Using the private modifier in the declaration for either of these types hides the methods and variables so they cannot be directly referenced outside of the class they're declared in. One exception to this rule is that private methods or variables declared within a class can also be used by inner classes.

public keyword is a modifier that can be used in the declaration of classes and interfaces. The public keyword can also be used as a modifier in the declaration of methods and variables. Classes or interfaces declared as public are visible everywhere. Methods and variables declared as public are visible everywhere their corresponding classes are visible.

(Note that the protected, public, private keyword cannot be used in the declaration of local variables.)

type – Type is compulsory for a method declaration. Type declaration indicates that what types of values going to be returned.

void (no return) or int / float / double / Boolean / char / String –(if a function return a value it not compulsory to accept a parameter form caller method).

parameter list are variables or objects that receive the value of argument.

Function Call by value – When a simple type passed to a method, as a copy of the argument is being made and passed to the function is known as call by value, any changes made to the parameter inside the function do not affect the original. A functions parameter list also known as signature.

void test()
{
int a=10,b=20;
int s=sum(a, b);
}

Function call by reference – When an object, address of a variable or a pointer is passed as an argument to a method it is called call by reference. A reference to an argument is passed as parameter, the value of the argument is not passed. This method is called call by reference in java.

class testing
{
int a, b;
void test()
{
a=10,b=20;
testing t=new testing();
int s=sum(t);
}
}

Pure function – Pure function or accessor methods return information to the caller about a state of an object without changing the state.

Impure function – Pure function or mutator methods return information to the caller about a state of an object by changing the state.

actual parameter—the actual value that is passed into the method by a caller. Actual arguments (those supplied by the caller) are evaluated. Caller – sum(a, b)

formal parameter—the identifier used in a method to stand for the value that is passed into the method by a caller. Receiver – int sum(int x, int y)

Message passing - "The process by which an object sends data to another object or asks the other object to invoke a method. Also known to some programming languages as interfacing

static - The static keyword is used as a modifier for methods and variables. When the static keyword appears in a method or variable declaration, it means that there will be only one copy of the method or variable that each class object may reference, regardless of the number of instances of the containing class that are created.

Examples
Basic

1 DEF fnf (t) = 1.5 * t ^ 2 + 3.2 * t ^ 2 + 2.3 * x + 4.1 :'Function
10 CLS
20 x = 1
30 WHILE x < 2.5 40 y = fnf(x) : ' Function calling 50 PRINT y 60 x = x + .5 70 WEND 80 END

C / C++
//main program
void main()
{
int c;
c=sum(a,b);
printf(“%d”,c);
}

//sum functions
int sum(int a,int b)
{
return a+b;
}
Java //main program
public class
{
public static void main(String args[])
{
int c;
c=sum(a,b);
System.out.println(c);
}

//sum functions
int sum(int a,int b)
{
return a+b;
}

Hope you have a helluva of time attending this function, next week come back with Built-in Functions.

!!!These functions are really very heavily built, that’s why very helpful too, till then Sizobonana!!!

Thursday, February 25, 2010

Constant and Some programming Rules - Haunted me Constantly

Last week we gone through Data Type, today we will discuss about constant and some programming rules.
Constant: A numeric or string value that does not change. Constant expressions combine constants and operators, but no variables, and evaluate to the same value every time. If you are storing a constant value of any type, like- n=10, a numeric constant and integer type or s=”Foxing the Fox”, a string constant.

In BASIC when you store a string constant you have to mention the variable with a dollar ($) sign, s$=”Foxing the Fox”, a string constant.

Numbers, a decimal point and a negative sign all can be stored in a numeric variable, for string values can consists alphabets, numbers and symbols. Where boolean could have TRUE and FALSE.

Constant always come in the right side of the equal sign and variable in left side.
A=10
B=20
A=B


Mathematically above statement wrong but in computer we are just telling that the  B is a constant and value of A will replace by the value of B, but  B remain unchanged. Therefore, A becomes 20 and B remains 20.

C++, Java and C# provide the ability to declare a variable whose value specified at compile time and cannot be change at runtime. Java uses the  final field modifier to declare such a variable, while c++ and C# uses the  const keyword.

Rules for different Programming languages


Every programming language having its own Syntax (Grammar), rules and guidelines. Like old days in BASIC (GW-Basic) we have to bind a program with line number for each statement and line number should be in ascending order
10 a=10
20 b=20


Further when Bill Gates gave us Qbasic, line numbers were optional but only to be given when one use transfer control to other statement than the next one. Same follows for FORTRAN too.

Let us move to ‘C’, it is a process oriented programming language, where main control remain inside main() function, confuesd?

void main()
{
Statement;
Statement;
Child_function();
Statement;
}

Where child_function() is a method or procedure where you can do certain routine and at the end you return to main() function to the next statement.

Enter the OOPs, relax life is more easy than before, if you understand it. Object-Oriented Programming (OOP): A system of programming that permits an abstract, modular typing hierarchy, and features polymorphism, inheritance, and encapsulation.

First, let us ask – What is abstract?

Abstraction : Identifying the distinguishing characteristics of a class or object without having to process all the information about the class or object. When you create a class — for example, a set of table  navigation buttons — you can use it as a single entity instead of keeping track of the individual components and how they interact. Represent essential features of a system without getting involvement with the complexity of the entire system.

Let me clear above point, as if you are using a watch and using as single unit. You do not have to bother how and what makes it work.

Inheritance is where in some cases, a class will have "subclasses," more specialized versions of a class. Subclasses inherit attributes and behaviors from their parent (super) classes, and can introduce their own.

Encapsulation Conceals the exact details of how a particular class works from objects that use its code or send messages to it. Encapsulation is achieved by specifying which classes may use the members of an object. The result is that each object exposes to any class a certain interface — those members accessible to that class.

Polymorphism is an object-oriented programming term. The ability to have methods with the same name, but different content, for related classes. The procedure to use is determined at run time by the class of the object. Function overloading, constructor overload is one of the example.

What is an object? Object means an instance. An object is a software bundle of variables related methods. An object is a particular instance of a class. The set of values of the attributes of a particular object is called its state.

What is a class? class is a model that defines the variables and the methods that common to all objects of a certain kind. A class is an abstract type. A class defines the abstract characteristics of an object, including its attributes, fields or properties and also its behaviors or methods or features. For example, the class Dog would consist of quality shared by all dogs, for example breed, fur colour etc.

Syntax
public class mySpace()
{
//Global variable declaration
public static void main(String args[])
{
//Body of the program
}
}
It is not easy to write about all programming languages, I just tried to write those are in demand. Next week coming with user defined function(UDF)/method.
!!!So, do not expect a blast as these functions are very boring, for time being Bonne journée.!!!