Showing posts with label COMPUTER PROGRAMMING GE6151. Show all posts
Showing posts with label COMPUTER PROGRAMMING GE6151. Show all posts

Thursday, October 16, 2014

rvalue in C

1. What is an rvalue?
rvalue can be defined as an expression that can be assigned to an lvalue. The rvalue appears on the right side of an assignment statement.
Unlike an lvalue, an rvalue can be a constant or an expression, as shown here:
int x, y;
x = 1;               /* 1 is an rvalue; x is an lvalue */
y = (x + 1);         /* (x + 1) is an rvalue; y is an lvalue */
An assignment statement must have both an lvalue and an rvalue. Therefore, the following statement would not compile because it is missing an rvalue:
int x; x = void_function_call() /* the function void_function_call() returns nothing */
If the function had returned an integer, it would be considered an rvalue because it evaluates into something that the lvalue, x, can store.

2. Is left-to-right or right-to-left order guaranteed for operator precedence?
The simple answer to this question is neither. The C language does not always evaluate left-to-right or right-to-left. Generally, function calls are evaluated first, followed by complex expressions and then simple expressions.
Additionally, most of today's popular C compilers often rearrange the order in which the expression is evaluated in order to get better optimized code. You therefore should always implicitly define your operator precedence by using parentheses.
For example, consider the following expression:
a = b + c/d / function_call() * 5
The way this expression is to be evaluated is totally ambiguous, and you probably will not get the results you want. Instead, try writing it by using implicit operator precedence:
a = b + (((c/d) / function_call()) * 5)
Using this method, you can be assured that your expression will be evaluated properly and that the compiler will not rearrange operators for optimization purposes.

Wednesday, October 15, 2014

Lvalue in C

1.What is an lvalue?
An lvalue is an expression to which a value can be assigned. The lvalue expression is located on the left side of an assignment statement, whereas an rvalue is located on the right side of an assignment statement. Each assignment statement must have an lvalue and an rvalue. The lvalue expression must reference a storable variable in memory. It cannot be a constant. For instance, the following lines show a few examples of lvalues:
int x;
int* p_int;
x = 1;
*p_int = 5;
The variable x is an integer, which is a storable location in memory. Therefore, the statement x = 1 qualifies xto be an lvalue. Notice the second assignment statement, *p_int = 5. By using the * modifier to reference the area of memory that p_int points to, *p_int is qualified as an lvalue. In contrast, here are a few examples of what would not be considered lvalues:
#define CONST_VAL 10
int x;
/* example 1 */
1 = x;
/* example 2 */
CONST_VAL = 5;
In both statements, the left side of the statement evaluates to a constant value that cannot be changed because constants do not represent storable locations in memory. Therefore, these two assignment statements do not contain lvalues and will be flagged by your compiler as errors.

2. Can an array be an lvalue?
Is an array an expression to which we can assign a value? The answer to this question is no, because an array is composed of several separate array elements that cannot be treated as a whole for assignment purposes. The following statement is therefore illegal:
int x[5], y[5];
x = y;
You could, however, use a for loop to iterate through each element of the array and assign values individually, such as in this example:
int i;
int x[5];
int y[5];
...
for (i=0; i<5; i++)
     x[i] = y[i]
...
Additionally, you might want to copy the whole array all at once. You can do so using a library function such as the memcpy() function, which is shown here:
memcpy(x, y, sizeof(y));
It should be noted here that unlike arrays, structures can be treated as lvalues. Thus, you can assign one structure variable to another structure variable of the same type, such as this:
typedef struct t_name
{
     char last_name[25];
     char first_name[15];
     char middle_init[2];
} NAME;
...
NAME my_name, your_name;
...
your_name = my_name;
...
In the preceding example, the entire contents of the my_name structure were copied into the your_namestructure. This is essentially the same as the following line:
memcpy(your_name, my_name, sizeof(your_name));

Tuesday, October 14, 2014

Goto and Jump in C

 What is the difference between goto and long jmp( ) and setjmp()?
A goto statement implements a local jump of program execution, and the longjmp() and setjmp() functions implement a nonlocal, or far, jump of program execution. Generally, a jump in execution of any kind should be avoided because it is not considered good programming practice to use such statements as goto and longjmpin your program.
A goto statement simply bypasses code in your program and jumps to a predefined position. To use the gotostatement, you give it a labeled position to jump to. This predefined position must be within the same function. You cannot implement gotos between functions. Here is an example of a goto statement:
void bad_programmers_function(void)
{
     int x;
     printf("Excuse me while I count to 5000...\n");
     x = 1;
     while (1)
     {
          printf("%d\n", x);
          if (x == 5000)
               goto all_done;
          else
               x = x + 1;
     }
all_done:
     printf("Whew! That wasn't so bad, was it?\n");
}
This example could have been written much better, avoiding the use of a goto statement. Here is an example of an improved implementation:
void better_function(void)
{
     int x;
     printf("Excuse me while I count to 5000...\n");
     for (x=1; x<=5000; x++)
          printf("%d\n", x);
     printf("Whew! That wasn't so bad, was it?\n");
}
As previously mentioned, the longjmp() and setjmp() functions implement a nonlocal goto. When your program calls setjmp(), the current state of your program is saved in a structure of type jmp_buf. Later, your program can call the longjmp() function to restore the program's state as it was when you called setjmp(). Unlike the goto statement, the longjmp() and setjmp() functions do not need to be implemented in the same function.
However, there is a major drawback to using these functions: your program, when restored to its previously saved state, will lose its references to any dynamically allocated memory between the longjmp() and thesetjmp(). This means you will waste memory for every malloc() or calloc() you have implemented between your longjmp() and setjmp(), and your program will be horribly inefficient. It is highly recommended that you avoid using functions such as longjmp() and setjmp() because they, like the goto statement, are quite often an indication of poor programming practice.
Here is an example of the longjmp() and setjmp() functions:
#include <stdio.h>
#include <setjmp.h>
jmp_buf saved_state;
void main(void);
void call_longjmp(void);
void main(void)
{
     int ret_code;
     printf("The current state of the program is being saved...\n");
     ret_code = setjmp(saved_state);
     if (ret_code == 1)
     {
          printf("The longjmp function has been called.\n");
          printf("The program's previous state has been restored.\n");
          exit(0);
     }
     printf("I am about to call longjmp and\n");
     printf("return to the previous program state...\n");
     call_longjmp();
}
void call_longjmp(void)
{
     longjmp(saved_state, 1);
}

Sunday, October 12, 2014

Comma Operator in C

Other than in a for statement, when is the comma operator used?
The comma operator is commonly used to separate variable declarations, function arguments, and expressions, as well as the elements of a for statement. Look closely at the following program, which shows some of the many ways a comma can be used:

#include <stdio.h>
#include <stdlib.h>
void main(void);
void main()
{
     /* Here, the comma operator is used to separate
        three variable declarations. */
     int i, j, k;
     /* Notice how you can use the comma operator to perform
        multiple initializations on the same line. */
     i = 0, j = 1, k = 2;
     printf("i = %d, j = %d, k = %d\n", i, j, k);
     /* Here, the comma operator is used to execute three expressions
        in one line: assign k to i, increment j, and increment k.
        The value that i receives is always the rightmost expression. */
     i = (j++, k++);
     printf("i = %d, j = %d, k = %d\n", i, j, k);
     /* Here, the while statement uses the comma operator to
        assign the value of i as well as test it. */
     while (i = (rand() % 100), i != 50)
          printf("i is %d, trying again...\n", i);
     printf("\nGuess what? i is 50!\n");
}

Notice the line that reads
i = (j++, k++);
This line actually performs three actions at once. These are the three actions, in order:
1. Assigns the value of k to i. This happens because the left value (lvalue) always evaluates to the rightmost argument. In this case, it evaluates to k. Notice that it does not evaluate to k++, because k++ is a postfix incremental expression, and k is not incremented until the assignment of k to i is made. If the expression had read ++k, the value of ++k would be assigned to i because it is a prefix incremental expression, and it is incremented before the assignment is made.
2. Increments j.
3. Increments k.

Also, notice the strange-looking while statement:

while (i = (rand() % 100), i != 50)
     printf("i is %d, trying again...\n");

Here, the comma operator separates two expressions, each of which is evaluated for each iteration of the whilestatement. The first expression, to the left of the comma, assigns i to a random number from 0 to 99.

The second expression, which is more commonly found in a while statement, is a conditional expression that tests to see whether i is not equal to 50. For each iteration of the while statement, i is assigned a new random number, and the value of i is checked to see that it is not 50. Eventually, i is randomly assigned the value 50, and the while statement terminates.

Saturday, October 11, 2014

Switch Statement

 Is a default case necessary in a switch statement?
No, but it is not a bad idea to put default statements in switch statements for error- or logic-checking purposes. For instance, the following switch statement is perfectly normal:

switch (char_code)
{
     case 'Y':
     case 'y': printf("You answered YES!\n");
               break;
     case 'N':
     case 'n': printf("You answered NO!\n");
               break;
}

Consider, however, what would happen if an unknown character code were passed to this switch statement. The program would not print anything. It would be a good idea, therefore, to insert a default case where this condition would be taken care of:

...
     default:  printf("Unknown response: %d\n", char_code);
               break;
...

Additionally, default cases come in handy for logic checking. For instance, if your switch statement handled a fixed number of conditions and you considered any value outside those conditions to be a logic error, you could insert a default case which would flag that condition. Consider the following example:

void move_cursor(int direction)
{
     switch (direction)
     {
          case UP:     cursor_up();
                       break;
          case DOWN:   cursor_down();
                       break;
          case LEFT:   cursor_left();
                       break;
          case RIGHT:  cursor_right();
                       break;
          default:     printf("Logic error on line number %ld!!!\n",
                               __LINE__);
                       break;
     }
}

Friday, October 10, 2014

C Basics - Interview Questions

 When is a switch statement better than multiple if statements?
A switch statement is generally best to use when you have more than two conditional expressions based on a single variable of numeric type. For instance, rather than the code
if (x == 1)
     printf("x is equal to one.\n");
else if (x == 2)
     printf("x is equal to two.\n");
else if (x == 3)
     printf("x is equal to three.\n");
else
     printf("x is not equal to one, two, or three.\n");
the following code is easier to read and maintain:
switch (x)
{
     case 1:   printf("x is equal to one.\n");
                    break;
     case 2:   printf("x is equal to two.\n");
                    break;
     case 3:   printf("x is equal to three.\n");
                    break;
     default:  printf("x is not equal to one, two, or three.\n");
                    break;
}

Notice that for this method to work, the conditional expression must be based on a variable of numeric type in order to use the switch statement. Also, the conditional expression must be based on a single variable. For instance, even though the following if statement contains more than two conditions, it is not a candidate for using a switch statement because it is based on string comparisons and not numeric comparisons:

char* name = "Lupto";
if (!stricmp(name, "Isaac"))
     printf("Your name means 'Laughter'.\n");
else if (!stricmp(name, "Amy"))
     printf("Your name means 'Beloved'.\n ");
else if (!stricmp(name, "Lloyd"))
     printf("Your name means 'Mysterious'.\n ");
else
     printf("I haven't a clue as to what your name means.\n");

Thursday, October 9, 2014

C Basics

 1.Should variables be stored in local blocks?
The use of local blocks for storing variables is unusual and therefore should be avoided, with only rare exceptions. One of these exceptions would be for debugging purposes, when you might want to declare a local instance of a global variable to test within your function. You also might want to use a local block when you want to make your program more readable in the current context.
Sometimes having the variable declared closer to where it is used makes your program more readable. However, well-written programs usually do not have to resort to declaring variables in this manner, and you should avoid using local blocks.

2. Can the last case of a switch statement skip including the break?
Even though the last case of a switch statement does not require a break statement at the end, you should add break statements to all cases of the switch statement, including the last case. You should do so primarily because your program has a strong chance of being maintained by someone other than you who might add cases but neglect to notice that the last case has no break statement.
This oversight would cause what would formerly be the last case statement to "fall through" to the new statements added to the bottom of the switch statement. Putting a break after each case statement would prevent this possible mishap and make your program more "bulletproof." Besides, most of today's optimizing compilers will optimize out the last break, so there will be no performance degradation if you add it.

Wednesday, October 8, 2014

C Basics - Interview Questions

 What is a local block?
A local block is any portion of a C program that is enclosed by the left brace ({) and the right brace (}). A C function contains left and right braces, and therefore anything between the two braces is contained in a local block. An if statement or a switch statement can also contain braces, so the portion of code between these two braces would be considered a local block.
Additionally, you might want to create your own local block without the aid of a C function or keyword construct. This is perfectly legal. Variables can be declared within local blocks, but they must be declared only at the beginning of a local block. Variables declared in this manner are visible only within the local block. Duplicate variable names declared within a local block take precedence over variables with the same name declared outside the local block. Here is an example of a program that uses local blocks:

#include <stdio.h>
void main(void);
void main()
{
     /* Begin local block for function main() */
     int test_var = 10;
     printf("Test variable before the if statement: %d\n", test_var);
     if (test_var > 5)
     {
          /* Begin local block for "if" statement */
          int test_var = 5;
          printf("Test variable within the if statement: %d\n",
                 test_var);
          {
               /* Begin independent local block (not tied to
                  any function or keyword) */
               int test_var = 0;
               printf(
               "Test variable within the independent local block:%d\n",
               test_var);
          }
          /* End independent local block */
     }
     /* End local block for "if" statement */
     printf("Test variable after the if statement: %d\n", test_var);
}
/* End local block for function main() */
This example program produces the following output:
Test variable before the if statement: 10
Test variable within the if statement: 5
Test variable within the independent local block: 0
Test variable after the if statement: 10
Notice that as each test_var was defined, it took precedence over the previously defined test_var. Also notice that when the if statement local block had ended, the program had reentered the scope of the originaltest_var, and its value was 10.

Monday, September 29, 2014

MANAGING INPUT AND OUTPUT OPERATORS in C

Explain briefly about the input and output function in "C". (MAY 2009/FEB 2009)

printf() is actually a function (procedure) in C that is used for printing variables and text. Where text appears in double quotes “”, it is printed without modification. There are some exceptions however.
This has to do with the \ and % characters. These characters are modifiers, and
for the present the \ followed by the n character represents a newline character.
Example:
#include <stdio.h>
main()

{
printf(“Programming in C is easy.\n”);
printf(“And so is Pascal.\n”);
}
@ Programming in C is easy. And so is Pascal.
FORMATTERS for printf are, Cursor Control Formatters
\n newline
\t tab
\r carriage return
\f form feed
\v vertical tab
2. Scanf ():
Scanf () is a function in C which allows the programmer to accept input from a
keyboard.
Example:
#include <stdio.h>
main() /* program which introduces keyboard input */
{
int number;
printf(“Type in a number \n”);
scanf(“%d”, &number);
printf(“The number you typed was %d\n”, number);
}
FORMATTERS FOR scanf()
The following characters, after the % character, in a scanf argument, have the
following effect.
D read a decimal integer o read an octal value
x read a hexadecimal value h read a short integer
l read a long integer
f read a float value
e read a double value
c read a single character
s read a sequence of characters

[...] Read a character string. The characters inside the brackets

Sunday, September 28, 2014

BRANCHING AND LOOPING in C


6. Write short notes on the following: (JAN 2009)
for loop
while loop
dowhile loop
Switch case  (MAY 2009/FEB 2009/FEB 2010)

1. ITERATION, FOR LOOPS
The basic format of the for statement is,
for( start condition; continue condition; re-evaulation )
program statement;
/* sample program using a for statement */
#include <stdio.h>
main() /* Program introduces the for statement, counts to ten */
{
int count;
for( count = 1; count <= 10; count = count + 1 )
printf(“%d “, count );

printf(“\n”);
}
The program declares an integer variable count. The first part of the for statement for (count = 1; initialized the value of count to 1.
The for loop continues with the condition count <= 10; evaluates as TRUE. As
the variable count has just been initialized to 1, this condition is TRUE and so the
program statement printf(“%d “, count ); is executed, which prints the value of count to the screen, followed by a space character.
Next, the remaining statement of the for is executed count = count + 1); which adds one to the current value of count. Control now passes back to the conditional test, count <= 10; which evaluates as true, so the program statement printf(“%d “, count ); is executed.
Count is incremented again, the condition re-evaluated etc, until count reaches a value of
11.
When this occurs, the conditional test count <= 10; evaluates as FALSE, and the for loop terminates, and program control passes to the statement printf(“\n”); which prints a newline, and then the program terminates, as there are no more statements left to execute

2. THE WHILE STATEMENT
The while provides a mechanism for repeating C statements whilst a condition is
true. Its format is, while( condition ) program statement;
Somewhere within the body of the while loop a statement must alter the value of the condition to allow the loop to finish.
Example:
/* Sample program including while */
#include <stdio.h>
main()
{
int loop = 0;
while( loop <= 10 ) {
printf(“%d\n”, loop);
++loop;
}
}
The above program uses a while loop to repeat the statements
printf(“%d\n”,loop); ++loop; the value of the variable loop is less than or
equal to 10.
3. THE DO WHILE STATEMENT
The do { } while statement allows a loop to continue whilst a condition evaluates as TRUE (non-zero). The loop is executed as least once.
Example:
/* Demonstration of DO...WHILE */
#include <stdio.h>
main()
{
int value, r_digit;
printf(“Enter the number to be reversed.\n”);
scanf(“%d”, &value);
do {
r_digit = value % 10; printf(“%d”, r_digit); value = value / 10;
} while( value != 0 );
printf(“\n”);
}
The above program reverses a number that is entered by the user. It does this by using the modulus % operator to extract the right most digit into the variable r_digit. The original number is then divided by 10, and the operation repeated whilst the number is not equal to 0.

Saturday, September 27, 2014

Decision making statements in C

 Explain about the various decision making statements in "C" language. (JAN 2009/FEB2010)

1. IF STATEMENTS
DECISION MAKING
The if statements allows branching (decision making) depending upon the value or state of variables. This allows statements to be executed or skipped, depending upon decisions.
The basic format is,
if( expression )
program statement;
Example:
if( students < 65 )
++student_count;
In the above example, the variable student_count is incremented by one only if the value of the integer variable students is less than 65. The following program uses an if statement to validate the users input to be in the range 1-10.
#include <stdio.h>
main()
{
int number;
int valid = 0;

while( valid == 0 ) {
printf(“Enter a number between 1 and 10 à”);
scanf(“%d”, &number);
/* assume number is valid */
valid = 1;
if( number < 1 ) {
printf(“Number is below 1. Please re-enter\n”);
valid = 0;
}
if( number > 10 ) {
printf(“Number is above 10. Please re-enter\n”);
valid = 0;
}
}
printf(“The number is %d\n”, number );
}
2. IF ELSE
The general format for these are,
if( condition 1 )
statement1;
else if( condition 2 )
statement2;
else if( condition 3 )
statement3; else statement4;
The else clause allows action to be taken where the condition evaluates as false (zero). The following program uses an if else statement to validate the users input to be in the range 1-10.
Example:
#include <stdio.h>
main()
{
int number;
int valid = 0;
while( valid == 0 ) {
printf(“Enter a number between 1 and 10 à”);
scanf(“%d”, &number);
if( number < 1 ) {
printf(“Number is below 1. Please re-enter\n”);
valid = 0;
}
else if( number > 10 ) {
printf(“Number is above 10. Please re-enter\n”);
valid = 0;
}
else
valid = 1;
}
printf(“The number is %d\n”, number );
}
This program is slightly different from the previous example in that an else clause is used to set the variable valid to 1. In this program, the logic should be easier to follow.

Friday, September 26, 2014

types of operators in "C"

 Describe the various types of operators in „C‟ language along with its priority.

An ex pr e s s I o n is a sequence of operators and operands that specifies computation of a value, or that designates an object or a function, or that generates side effects, or that performs a combination thereof.


1. ARITHMETIC OPERATORS:
The symbols of the arithmetic operators are:-
Example:
#include <stdio.h>
main()
{
int sum = 50; float modulus; modulus = sum % 10;
printf(“The %% of %d by 10 is %f\n”, sum, modulus);
}
PRE/POST INCREMENT/DECREMENT OPERATORS
PRE means do the operation first followed by any assignment operation. POST means do the operation after any assignment operation. Consider the following statements ++count; /* PRE Increment, means add one to count */ count++; /* P OST Increment, means add one to count */
Example:
#include <stdio.h>
main()
{
int count = 0, loop;
loop = ++count; /* same as count = count + 1; loop = count; */
printf(“loop = %d, count = %d\n”, loop, count);
loop = count++; /* same as loop = count; count = count + 1; */
printf(“loop = %d, count = %d\n”, loop, count);
}
If the operator precedes (is on the left hand side) of the variable, the operation is performed first, so the statement
loop = ++count;
really means increment count first, then assign the new value of count to loop.
2. THE RELATIONAL OPERATORS
These allow the comparison of two or more variables.
= = equal to
! = not equal
< less than
< = less than or equal to
> greater than
> = greater than or equal to
Example:
#include <stdio.h>
main() /* Program introduces the for statement, counts to ten */
{
int count;
for( count = 1; count <= 10; count = count + 1 )
printf(“%d “, count );
printf(“\n”);
}

Thursday, September 25, 2014

Data Types in C

 Discuss about the various data types in "C". (MAY 2009)

The four basic data types are
a. INTEGER
These are whole numbers, both positive and negative. Unsigned integers (positive values only) are supported. In addition, there are short and long integers.
The keyword used to define integers is, int An example of an integer value is 32. An example of declaring an integer variable called sum is, int sum;sum = 20;
b. FLOATING POINT
These are numbers which contain fractional parts, both positive and negative. The keyword used to define float variables is,float
An example of a float value is 34.12. An example of declaring a float variable called money is,
float money;

money = 0.12;
c. DOUBLE
These are exponentional numbers, both positive and negative. The keyword used to define double variables is, double An example of a double value is 3.0E2. An example of declaring a double variable called big is, double big; big = 312E+7;
d. CHARACTER
These are single characters. The keyword used to define character variables is, char
An example of a character value is the letter A. An example of declaring a character variable called letter is, char letter; letter = „A‟;
Note the assignment of the character A to the variable letter is done by enclosing the value in single quotes.
#include < stdio.h >
main()
{
int sum;
float money; char letter; double pi;
sum = 10; /* assign integer value */ money = 2.21; /* assign float value */ letter = „A‟; /* assign character value */ pi = 2.01E6; /* assign a double value */ printf(“value of sum = %d\n”, sum );
printf(“value of money = %f\n”, money ); printf(“value of letter = %c\n”, letter ); printf(“value of pi = %e\n”, pi );
}

Sample program output
value of sum = 10
value of money = 2.210000 value of letter = A
value of pi = 2.010000e+06


Wednesday, September 24, 2014

INTRODUCTION TO C

1. Explain in detail about „C‟ declarations and variables.

In C, lowercase and uppercase characters are very important. All commands in C must be lowercase. The C programs starting point is identified by the word main( ). This informs the computer as to where the program actually starts.
The brackets that follow the keyword main indicate that there are no arguments supplied to this program.
The two braces, { and }, signify the begin and end segments of the program. The purpose of the statement include <stdio.h> is to allow the use of the printf statement to provide program
output. Text to be displayed by printf() must be enclosed in double quotes. The program has only one statement printf("Programming in C is easy.\n");
printf() is actually a function (procedure) in C that is used for printing variables and text. Where text appears in double quotes "", it is printed without modification. There are some exceptions however. This has to do with the \ and % characters. These characters are modifier‟s, and for the present the \ followed by the n character represents a newline character. Thus the program prints Programming in C is easy.
and the cursor is set to the beginning of the next line. As we shall see later on, what follows the \ character will determine what is printed, ie, a tab, clear screen, clear line etc. Another important thing to remember is that all C statements are terminated by a semi-colon ;
General rules of „C‟ language:
· program execution begins at main()
· keywords are written in lower-case
· statements are terminated with a semi-colon
· text strings are enclosed in double quotes

· C is case sensitive, use lower-case and try not to capitalize variable names
· \n means position the cursor on the beginning of the next line
· printf() can be used to display text to the screen
· The curly braces {} define the beginning and end of a program block.

BASIC STRUCTURE OF C PROGRAMS
C programs are essentially constructed in the following manner, as a number of well defined sections.
/* HEADER SECTION */
/* Contains name, author, revision number*/
/* INCLUDE SECTION */
/* contains #include statements */
/* CONSTANTS AND TYPES SECTION */
/* contains types and #defines */
/* GLOBAL VARIABLES SECTION */
/* any global variables declared here */
/* FUNCTIONS SECTION */
/* user defined functions */
/* main() SECTION */
int main()
{
}

Tuesday, September 23, 2014

Algorithm & Pseudocode

1. Describe in detail about algorithm? Give example (MAY 2009)
An algorithm is a description of a procedure which terminates with a result. Simple algorithms can be implemented within a function.
Properties of an algorithm
No ambiguity
There should not be any uncertainty about which instruction to execute next. The algorithm should conclude after a finite number of steps.
The algorithm should be general.
Example:
Biggest among two numbers Addition of N numbers Finding Factorial of a number Finding Fibonacci series.

4. Elaborate pseudo code with example. (MAY 2009\FEB 2009) 
Guidelines
Statements should be in simple English
Must produce a solution for the specified problem
It should be concise
Each instruction should be written in separate line and express one action. Capitalize keywords such as READ, PRINT and so on.
Instruction should be written from top to bottom, with one entry and one exit. Should allow easy transition from design to coding in programming language.

Monday, September 22, 2014

flowchart

 Explain flowchart in detail? (FEB 2009/FEB 2010)

A flowchart is a schematic representation of an algorithm or a stepwise process, showing the steps as boxes of various kinds, and their order by connecting these with arrows. Flowcharts are used in designing or documenting a process or program.
A flow chart, or flow diagram, is a graphical representation of a process or system that details the sequencing of steps required to create output. A flowchart is a picture of the separate steps of a process in sequential order.

The benefits of flowcharts are as follows:
a. Communication: Flowcharts are better way of communicating the logic of a system to all concerned.

b. Effective analysis: With the help of flowchart, problem can be analyzed in more effective way.
c. Proper documentation: Program flowcharts serve as a good program documentation, which is needed for various purposes.
d. Efficient Coding: The flowcharts act as a guide or blueprint during the systems analysis and program development phase.
e. Proper Debugging: The flowchart helps in debugging process.
f. Efficient Program Maintenance: The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part.
Advantages
Logic Flowcharts are easy to understand. They provide a graphical representation of actions to be taken.
Logic Flowcharts are well suited for representing logic where there is intermingling among many actions.
Disadvantages
Logic Flowcharts may encourage the use of GoTo statements leading to software design that is unstructured with logic that is difficult to decipher.
Without an automated tool, it is time-consuming to maintain Logic Flowcharts. Logic Flowcharts may be used during detailed logic design to specify a module.
However, the presence of decision boxes may encourage the use of GoTo statements, resulting in software that is not structured. For this reason, Logic Flowcharts may be better used during Structural Design.

Sunday, September 21, 2014

PROBLEM SOLVING

1. Explain the steps involved in developing a program with neat diagram? (FEB2009)
(or)
Brief about planning the computer program?

The Programming Process – Purpose
1. Understand the problem
v Read the problem statement
v Question users
v Inputs required
v Outputs required
v Special formulas
v Talk to users
2. Plan the logic
(a) Visual Design Tools
v Input record chart
v Printer spacing chart
v Hierarchy chart
v Flowchart

(b) Verbal Design Tools
v Narrative Description
v Pseudocode
3. Code the program
v Select an appropriate programming language
v Convert flowchart and/or Pseudocode instructions into programming language statements
4. Test the program
1. Syntax errors
2. Runtime errors
3. Logic errors
4. Test Data Set
5. Implement the program
Buy hardware Publish software Train users
6. Maintain the program
Maintenance programmers
Legacy systems
Up to 85% of IT department budget


Saturday, September 20, 2014

various Input and Output Devices

Elaborate the various Input and Output Devices?

Input/Output devices are required for users to communicate with the computer. In simple terms, input devices bring information INTO the computer and output devices bring information OUT of a computer system. These input/output devices are also known as peripherals since they surround the CPU and memory of a computer system.

Some commonly used Input/Output devices are listed in table below.

(a) Keyboard
It is a text base input device that allows the user to input alphabets, numbers and other characters. It consists of a set of keys mounted on a board. 

Figure 1: The Keyboard


Alphanumeric Keypad
It consists of keys for English alphabets, 0 to 9 numbers, and special characters like + − / * ( ) etc.
Function Keys
There are twelve function keys labeled F1, F2, F3… F12. The functions assigned to these keys differ from one software package to another. These keys are also user programmable keys.
Special-function Keys
These keys have special functions assigned to them and can be used only for those specific purposes. Functions of some of the important keys are defined below.
Enter
It is similar to the „return‟ key of the typewriter and is used to execute a command or program.
Spacebar
It is used to enter a space at the current cursor location.
Backspace
This key is used to move the cursor one position to the left and also delete the character in that position.
Delete
It is used to delete the character at the cursor position.
Insert
Insert key is used to toggle between insert and overwrite mode during data entry.
Shift
This key is used to type capital letters when pressed along with an alphabet key. Also used to type the special characters located on the upper-side of a key that has two characters defined on the same key.
Caps Lock
Cap Lock is used to toggle between the capital lock features. When „on‟, it locks the alphanumeric keypad for capital letters input only.
Tab
Tab is used to move the cursor to the next tab position defined in the document. Also, it is used to insert indentation into a document.
Ctrl
Control key is used in conjunction with other keys to provide additional functionality on the keyboard.
Alt
Also like the control key, Alt key is always used in combination with other keys to perform specific tasks.
Esc
This key is usually used to negate a command. Also used to cancel or abort executing programs.
Numeric Keypad
Numeric keypad is located on the right side of the keyboard and consists of keys having numbers (0 to 9) and mathematical operators (+ − * /) defined on them. This keypad is provided to support quick entry for numeric data.
Cursor Movement Keys
These are arrow keys and are used to move the cursor in the direction indicated by the arrow (up, down, left, right).

(b) Mouse
The mouse is a small device used to point to a particular place on the screen and select in order to perform one or more actions. It can be used to select menu commands, size windows, start programs etc. The most conventional kind of mouse has two buttons on top: the left one being used most frequently.
Mouse Actions
Left Click : Used to select an item.
Double Click : Used to start a program or open a file.
Right Click : Usually used to display a set of commands.
Drag and Drop : It allows you to select and move an item from one location to another. To achieve this place the cursor over an item on the screen, click the left mouse button and while holding the button down move the cursor to where you want to place the item, and then release it.

Figure 2: The Mouse

Friday, September 19, 2014

Memory in Computer System

 Explain about memory in Computer System?
(or)
Write short notes on memory of a computer? (MAY 2009)

The Role of Memory

The term "memory" applies to any electronic component capable of temporarily storing data. There are two main categories of memories:
Internal memory that temporarily memorizes data while programs are running. Internal memory uses micro conductors, i.e. fast specialized electronic circuits. Internal memory corresponds to what we call random access memory (RAM).

Auxiliary memory (also called physical memory or external memory) that stores information over the long term, including after the computer is turned off. Auxiliary memory corresponds to magnetic storage devices such as the hard drive, optical storage devices such as CD-ROMs and DVD-ROMs, as well as read-only memories.

Technical Characteristics
(a) Capacity, representing the global volume of information (in bits) that the memory can store
(b) Access time, corresponding to the time interval between the read/write request and the availability of the data
(c) Cycle time, representing the minimum time interval between two successive accesses
(d) Throughput, which defines the volume of information exchanged per unit of time, expressed in bits per second
(e) Non-volatility, which characterizes the ability of a memory to store data when it is not being supplied with electricity
The ideal memory has a large capacity with restricted access time and cycle time, a high throughput and is non-volatile.

Thursday, September 18, 2014

Secondary storage devices

 Describe briefly about Secondary storage devices? (MAY 2009)

Secondary storage devices, as indicated by the name, save data after it has been saved by the primary storage device, usually referred to as RAM (Random Access Memory). From the moment we start typing a letter in Microsoft Word, for example, and until we click on "Save," your entire work is stored in RAM. However, once you power off your machine, that work is completely erased, and the only copy remaining is on the secondary storage device where we saved it, such as internal or external hard disk drive, optical drives for CDs or DVDs, or USB flash drive.

Internal Hard Disk Drive
The internal hard disk drive is the main secondary storage device that stores all of your data
magnetically, including operating system files and folders, documents, music and video. The hard disk drive is a stack of disks mounted one on top of the other and placed in a sturdy case. They are spinning at high speeds to provide easy and fast access to stored data anywhere on a disk.

External Hard Disk Drive
External hard disk drives are used when the internal drive does not have any free space and
you need to store more data. In addition, it is recommended to always back up all of our data and an external hard drive can be very useful, as they can safely store large amounts of information. They can be connected by either USB connection to a computer and can even be connected with each other in case you need several additional hard drives at the same time.