Friday, September 18, 2015

State Diagram

State Diagrams: State Diagrams State diagrams are created during the analysis and design phase to describe the behaviour of nontrivial objects. State diagrams are good for describing the behaviour of one object across several use cases and are used to identify object attributes and to refine the behaviour description of an object.
There are three major components of a state diagram:
State:
A state is a condition in which an object can be at some point during its lifetime, for some finite period of. State diagrams describe all the possible states a particular object can get into and how the objects state changes as a result of external events that reach the object.
States are represented by the values of the attributes of an object.
A state represents a stage in the behaviour pattern of an object, and in a state diagram it is possible to have initial states and final states.
An initial state, also called a creation state, is the one that an object is in when it is first created, whereas a final state is one in which no transitions lead out of.
. In a state diagram:
• A state is represented by a rounded rectangle.
 • A start state is represented by a solid circle.
• A final state is represented by a solid circle with another open circle around it.
Transition
A transition is a progression from one state to another and will be triggered by an event that is either internal or external to the object.
Transitions are the result of the invocation of a method that causes an important change in state.
 A transition is a change of an object from one state (the source state) to another (the target state) triggered by events, conditions, or time. Transitions are represented by an arrow connecting two states.
Transitions can also be labeled with guards (a Boolean expression which evaluates to true or false) inside square brackets, such as [trade accepted]. A guarded transition occurs only if the guard resolves to true. Only one transition can be taken out of a given state. If more than one guard condition is true, only one transition will fire. The choice of transition to fire is nondeterministic if no priority rule is given
The arrows in state diagram represent transitions, progressions from one state to another.
Event: Is something that occurs at a point of time.
Events are internal or external factors influencing the system.
Event causes the transitions

State diagrams are used to model states and also events operating on the system. 







Wednesday, September 9, 2015

Translators(MCA I)

Translators
Assembler
An assembler translates assembly language into machine code. Assembly language consists of mnemonics for machine opcodes so assemblers perform a 1:1 translation from mnemonic to a direct instruction. For example:
LDA #4 converts to 0001001000100100
Conversely, one instruction in a high level language will translate to one or more instructions at machine level.
Advantages of using an Assembler:
·         Very fast in translating assembly language to machine code as 1 to 1 relationship
·         Assembly code is often very efficient (and therefore fast) because it is a low level language
·         Assembly code is fairly easy to understand due to the use of English-like mnemonics

Disadvantages of using Assembler:
·         Assembly language is written for a certain instruction set and/or processor
·         Assembly tends to be optimised for the hardware it's designed for, meaning it is often incompatible with different hardware
·         Lots of assembly code is needed to do relatively simple tasks, and complex programs require lots of programming time

Compiler
Compiler is a computer program that translates code written in a high level language to a lower level language, object/machine code. The most common reason for translating source code is to create an executable program (converting from a high level language into machine language).
Advantages of using a compiler
·         Source code is not included, therefore compiled code is more secure than interpreted code
·         Tends to produce faster code than interpreting source code
·         Produces an executable file, and therefore the program can be run without need of the source code

Disadvantages of using a compiler
 Object code needs to be produced before a final executable file, this can be a slow process
 The source code must be 100% correct for the executable file to be produced

Interpreter
An interpreter program executes other programs directly, running through program code and executing it line-by-line. As it analyses every line, an interpreter is slower than running compiled code but it can take less time to interpret program code than to compile and then run it — this is very useful when prototyping and testing code. Interpreters are written for multiple platforms, this means code written once can be run immediately on different systems without having to recompile for each. Examples of this include flash based web programs that will run on your PC, MAC, games console and Mobile phone.
Advantages of using an Interpreter
·         Easier to debug(check errors) than a compiler
·         Easier to create multi-platform code, as each different platform would have an interpreter to run the same code
·         Useful for prototyping software and testing basic program logic
Disadvantages of using an Interpreter
·         Source code is required for the program to be executed, and this source code can be read making it insecure
·         Interpreters are generally slower than compiled programs due to the per-line translation method


Computer Language(MCA 1)

Language:Just as humans use language to communicate, and different regions have different languages, computers also have their own languages that are specific to them.
Different kinds of languages have been developed to perform different types of work on the computer. Basically, languages can be divided into two categories according to how the computer understands them.
Two Basic Types of Computer Language
·         Low-Level Languages: A language that corresponds directly to a specific machine
·         High-Level Languages: Any language that is independent of the machine

Low-Level Languages

Low-level computer languages are either machine codes or are very close them. A computer cannot understand instructions given to it in high-level languages or in English. It can only understand and execute instructions given in the form of machine language i.e. binary. There are two types of low-level languages:
·         Machine Language: a language that is directly interpreted into the hardware
·         Assembly Language: a slightly more user-friendly language that directly corresponds to machine language
1.   Machine Language
Machine language is the lowest and most elementary level of programming language and was the first type of programming language to be developed. Machine language is basically the only language that a computer can understand and it is usually written in hex.
In fact, a manufacturer designs a computer to obey just one language, its machine code, which is represented inside the computer by a string of binary digits (bits) 0 and 1. The symbol 0 stands for the absence of an electric pulse and the 1 stands for the presence of an electric pulse. Since a computer is capable of recognizing electric signals, it understands machine language.
Advantages:
·        Machine language makes fast and efficient use of the computer.
·        Machine language makes fast and efficient use of the computer.
·        Machine language makes fast and efficient use of the computer.
·        It requires no translator to translate the code. It is directly understood by the computer.
Disadvantages
·        All operation codes have to be remembered.
·        All memory addresses have to be remembered.
·        It is hard to amend or find errors in a program written in the machine language.

2.   Assembly Language
Assembly language was developed to overcome some of the many inconveniences of machine language. This is another low-level but very important language in which operation codes and operands are given in the form of alphanumeric symbols instead of 0’s and l’s.
These alphanumeric symbols are known as mnemonic codes and can combine in a maximum of five-letter combinations e.g. ADD for addition, SUB for subtraction, START, LABEL etc. Because of this feature, assembly language is also known as ‘Symbolic Programming Language.'
This language is also very difficult and needs a lot of practice to master it because there is only a little English support in this language. Mostly assembly language is used to help in compiler orientations. The instructions of the assembly language are converted to machine codes by a language translator and then they are executed by the computer.
Advantages:
·        Assembly language is easier to understand and use as compared to machine language
·        It is easy to locate and correct errors.
·        It is easily modified.
Disadvantages:
·        Like machine language, it is also machine dependent/specific.
·        Since it is machine dependent, the programmer also needs to understand the hardware.

High-Level Languages

High-level computer languages use formats that are similar to English. The purpose of developing high-level languages was to enable people to write programs easily, in their own native language environment (English).
High-level languages are basically symbolic languages that use English words and/or mathematical symbols rather than mnemonic codes. Each instruction in the high-level language is translated into many machine language instructions that the computer can understand.
Advantages:
·        High-level languages are user-friendly
·        They are similar to English and use English vocabulary and well-known symbols
·        They are easier to learn.
·        They are easier to maintain
·        They are problem-oriented rather than 'machine'-based
·        A program written in a high-level language can be translated into many machine languages and can run on any computer for which there exists an appropriate translator
·        The language is independent of the machine on which it is used i.e. programs developed in a high-level language can be run on any computer text
Disadvantages:
·        A high-level language has to be translated into the machine language by a translator, which takes up time
·        The object code generated by a translator might be inefficient compared to an equivalent assembly language program




MCA I: Assignment 1

Q1. Write a note on history of C language.
Q2. Define the term of translators. What are the different types of translators?
Q3. Write a note on the following:
A.      Low Level language
B.      Middle Level Language
C.      High Level Language
Q4. What are the different types of operators? What do you mean by precedence and associativity of an operator? Explain the use of each using examples.
[ +,         -,             *,           /,            %,         
 =,           <,           <=,        >,            >=,         ==,         !=,         
?:,          
sizeof()
++,         --


Q5. Write a short note on Keyword, Data Type & Variable.

Thursday, September 3, 2015

sizeof operator in C (MCA I)

sizeof operator

  1. sizeof operator is used to calcualte the size of data type or variables.
  2. sizeof operator can be nested.
  3. sizeof operator will return the size in integer format.
  4. sizeof operator syntax looks more like a function but it is considered as an operator in c programming

Example of sizeof() operator

Size of Variables

#include<stdio.h>

int main() {

   int ivar = 100;
   char cvar = 'a';
   float fvar = 10.10;

   printf("%d", sizeof(ivar));
   printf("%d", sizeof(cvar));
   printf("%d", sizeof(fvar));
   return 0;
}

Operators in C Language(MCA I)

C Programming Operators :


4.1
4.2
Operator
Meaning
Example
+
Addition Operator
160 + 20 = 180
-
Subtraction Operator
60 – 10 = 50
*
Multiplication Operator
20 * 4 = 80
/
Division Operator
20 / 5 = 4
%
Modulo Operator
20 % 7 = 6
In C Programming , Unary operators are having higher priority than the other operators. Unary Operators are executed before the execution of the other operators. Increment and Decrement are the examples of the Unary operator in C.
4.3
1.      Increment operator is used to increment the current value of variable by adding integer 1.
2.     Increment operator can be applied to only variables.
3.     Increment operator is denoted by ++.

A. Pre Increment Operator

Pre-increment operator is used to increment the value of variable before using in the expression. In the Pre-Increment value is first incremented and then used inside the expression.
b = ++y;
In this example suppose the value of variable ‘y’ is 5 then value of variable ‘b’ will be 6 because the value of ‘y’ gets modified before using it in a expression.

B. Post Increment Operator

Post-increment operator is used to increment the value of variable as soon as after executing expression completely in which post increment is used. In the Post-Increment value is first used in a expression and then incremented.
b = x++;
In this example suppose the value of variable ‘x’ is 5 then value of variable ‘b’ will be 5 because old value of ‘x’ is used.
4.4
We have seen increment operator in C Programming which increments the value of the variable by 1. Similarly C Supports one more unary operator i.e decrement operator which behaves like increment operator but only difference is that it decreases the value of variable by 1.
4.5
Operator
Meaning
> 
Greater than
>=
Greater than or equal to
<=
Less than or equal to
< 
Less than
4.6
Whenever we use if statement then we can use relational operator which tells us the result of the comparison, so if we want to compare more than one conditions then we need to use logical operators. Suppose we need to execute certain block of code if and only if two conditions are satisfied then we can use Logical Operator in C Programming.
Operator
Name of the Operator
&&
And Operator
||
Or Operator
!
Not Operator


4.8

Conditional Operators [ ?: ] : Ternary Operator Statement in C

1.      They are also called as Ternary Operator .
2.     They also called as ?: operator
3.     Ternary Operators takes on 3 Arguments

Syntax :

expression 1 ? expression 2 : expression 3
where
·         expression1 is Condition
·         expression2 is Statement Followed if Condition is True
·         expression2 is Statement Followed if Condition is False