Showing posts with label Data Types and Operators. Show all posts
Showing posts with label Data Types and Operators. Show all posts

Operators

Filed under , on Thursday, February 18, 2010

0

What is Operators
Operators are symbols that act upon data.They represent a particular operation to be performed on the data. The operations performed are:
Mathematical:
o    Add
o    SubtractOperator
o    Multiply
o    Divide
o    Exponentiation
o    Modulus
Comparison:
o    Greater than (>)
o    Less than (<)
o    Greater than or equal to (>=)
o    Less than or equal to (<=)
o    Equal to (= (Basic style) or = = (C style))
o    Not equal to (<>(Basic style) or != (C style))
Logical
o    AND
o    OR
o    NOT
    Consider the following line:
    9 + 2
The above line indicates that the two numbers, 9 and 2, are to be added.
The ‘+’ symbol used in the above example indicates the operation that is to be performed on the two numbers. It is referred to as an operator.
Thus, operators specify the action that is to be performed on the given data.
‘9’ and ‘2’, the numbers to be added are called the operands.
Thus, an operand is the data on which the operator acts upon.



Classification  
Depending on the nature of operation, operators and classified as:
o        Arithmetic operators
o        Comparison operators
o        Logical operators
  
Arithmetic Operators
Operators that denote the mathematical operations are:
o        Add
o        Subtract
o        Multiply
o        Divide
o        Exponentiation
These are referred to as arithmetic operators.
The following table presents arithmetic operators we have used all our lives:

Data Types

Filed under , on Thursday, February 04, 2010

0

Different types of data are stored in variables. Some examples are:
•    Numbers
Whole numbers. For example, 10 or 178993455
    Real numbers. For Example, 15.22 or 15463452.2511
    Positive numbers
    Negative numbers
•    Names. For example, John
•    Logical values. For example, Y or N   
The data that is to be stored in variables is of different types and so it requires different amounts of memory.
A data type decides the amount of memory to be allocated to a variable to store a particular type of data.
    To allocate memory for a particular piece of data we have to:
    Declare a variable of a particular data type.
The term, declaring a variable, means that some memory is allocated and that portion of memory will be referred to by the variable name.
    The general form of declaring a variable is:
    Data Type [Variable Name]        (C style)
    Dim [Variable Name] as Data Type    (Basic style)
Data types, which are commonly used in programming tools can be classified as:
•    Numeric: Stores numeric value.
•    Alphanumeric: Stores descriptive information
These data types can have different names in different tools. For example, a numeric data type is called int in the tool C while Visual Basic refers to it as Integer. Similarly, an alphanumeric data type is named char  in C while in Visual Basic it is named string. In any case, the data stored is the same. The only difference is that the variables used in a tool have to be declared with the name of the data type supported by that tool.

Numeric data   
Numbers of any type constitute numeric data. The numbers may be whole or real.
Numeric data can contain:
•    Only the numeric characters of 0 to 9
•    The decimal point
The most important numeric data types are Integer, Float and Double.
Integer    
The data type, which stores numeric data is one of the basic data types in any programming language. It consists of a sequence of one or more digits.
For example in Visual Basic, to store an integer value in a variable called ‘num’ the declaration would be as follows:
    Dim num as Integer

Variables

Filed under , on Sunday, January 31, 2010

0

When an application is to handle data, it needs some place where it can temporarily store this data. This “place” where the application stores data is called the memory.
An application will handle more than one piece of data. Thus, the application has to allocate memory for each piece of data. In allocating memory there are two factors to be considered:
•    How much memory is to be allocated ?
•    Remembering where in memory is each piece of data stored.
Earlier programmers had to write their programs in the language of the machine that is, in 1s and 0s. If the programmer wanted to temporarily store a value, the exact storage locations inside the memory of the computer had to be assigned. This storage location had to be a specific number or memory address.
Modern day languages enable us to use symbolic names known as variables, to refer to the memory location where a particular value is to be stored.
The type of data decides the amount of memory to be allocated. The names that we assign to variables to store a particular data help us in retrieving this data as and when required.
We are familiar with the use of letters, which represent quantities in a formula. For example, the area of a rectangle is given by:
    Area = A = Length x Breadth = L x B
    The simple interest is given by:
    Interest = I = Principal x Time x Rate / 100 = P x T x R / 100
The letters A, L, B, I, P, T and R are all variables and are short notations that represent various values.
To appreciate the significance of variables, consider the following example:
    The sum of the marks obtained by 5 students is to be displayed.
    The sum can be displayed with the help of the following instruction.
    Display the sum of 24, 56, 72, 36 and 82.
Once the sum is displayed, it is lost from the computer’s memory. Suppose we want to calculate the average of the marks, the sum would have to be recalculated.
A better approach will be to store the result in the computer’s memory, and retrieve it as and when required.
    sum = 24 + 56 + 72 + 36 + 82
Here, sum is a variable that is used to store the sum of the five numbers. To calculate average, it can be done as follows: