Thursday, September 25, 2008

PROGRAMMING (*M.N. Sison*)

PROGRAMMING
n \n – is a line char used to move the cursor to the next linen
‘ ‘ – single quote is used for single character / letter.n
“ “ – double quote is used for two or more charactern
{ - open curly brace signifies beginn } – close curly brace signifies endn & - address of operatorn * - indirection operator / pointer


Structure of a simple C program
#include
#define directive
main()
{variable declaration section;
____________________________________________}
Commonly used include files in C language
.n alloc.h – declares memory management functions
.n conio.h – declares various functions used in calling IBM-PC ROM BIOS
.n ctype.h – contains information used by the calssification and character convertion macros.n math.h – declares prototype for the math functions
.n stdio.h – defines types and macros needed for standard I/O
.n string.h – declares several string manipulation and memory manipulation routines.
Types of Conditional Statement
The If Statement
The If-Else Statement
The Nested-If Statement
The If-Else-If Ladder
The Switch Statement
The Nested Switch Statement
The general form of the If statement is:
if ( expression)
statement;
The general form of the If statement with block statement is:
if ( expression)
{
statement_sequence;
}
The general form of the if-else statement is:
If (expression)
statement_1;
else
statement_2;
The general form of the if-else statement with block of statement is:
If (expression)
{
statement_sequence;
}
else
{
statement_sequence;
}
The general form of the if-else-if ladder statement is:
if ( expression_1)
statement_1;
else if (expression_2)
statement_2;
else if (expression_3;
statement_3;
:
:
else
statement_else;
The general form of the switch statement is:
switch (variable)
{
case constant1:
statement sequence_1;
break;case constant2:
statement_sequence_2;
break;
:
:
default:
statement_sequence_default;
}
The general form of the nested switch statement is:
switch (variable)
{
case constant:{
switch (variable)
{
case constant1:
statement sequence_1;
break;
case constant2:
statement_sequence_2;
break;
}
break;
}
case constant2:
statement sequence;
break;
default:
statement sequence;
}

Tuesday, September 23, 2008

PROGRAMMING-(paraiso)

This week we learned about:
  • The Structure of a Simple C Program
  • The Input or Output Statements
  • The Conditional Statements

THE STRUCTURE OF A SIMPLE C PROGRAM


#include
#define directive
main()
{
variable declaration section;
______________________
______________________
}

  • #include directive – contains information needed by the program to ensure the correct operation of C’s Standard library functions.
  • n#define directive – used to shorten the keywords in the program.
  • Variable declaration section – it is the place where you declare your variables.
  • Body of the program – start by typing main() and the { and }. All statements should be written inside the braces.


**C is a case sensitive program, therefore use lowercase letters only.


Commonly used include files in C language

  1. alloc.h – declares memory management functions.
  2. conio.h – declares various functions used in calling IBM-PC ROM BIOS.
  3. ctype.h – contains information used by the calssification and character convertion macros.
  4. nmath.h – declares prototype for the math functions.
  5. nstdio.h – defines types and macros needed for standard I/O.
  6. string.h – declares several string manipulation and memory manipulation routines.

Important Symbols:

a.) \n – is a line char used to move the cursor to the next line

b.) ‘ ‘ – single quote is used for single character / letter.

c.) “ “ – double quote is used for two or more character

d.) { - open curly brace signifies begin

e.) } – close curly brace signifies end

f.) & - address of operator

g.) * - indirection operator / pointer

INPUT AND OUTPUT STATEMENTS

Input Statement- A statement used to input a single character or a sequence of characters from the keyboard.

Types:

  • getch- A function used to input a single character from the keyboard without echoing the character on the monitor.

* Syntax: getch();
Example: ch = getch();

  • Getche- A function used to input a single character from the keyboard, the character pressed echoed on the monitor, line the READLN in PASCAL

* Syntax: getche();
Example: ch = getche();

  • getchar - A function used to input a single character from the keyboard, the character pressed echoed on the monitor terminated by pressing Enter key.

* Syntax: getchar();
Example: ch = getchar();

  • scanf - A function used to input a single character or sequence of characters from the keyboard, it needs the control string codes in able to recognized. Spaces are not accepted upon inputting. Terminated by pressing spacebar.

*Syntax: gets();
Example: gets(ch);

Output Statement- A statement used to display the argument list or string on the monitor.

Types:

  • printf - A function used to display the argument list on the monitor.
    It sometimes needs the control string codes to help display the remaining argument on the screen.

    *Syntax: printf(“control string codes”, argument list)
    Example: printf(“Hello, %d, you are % years old.”, name, age);
  • putchar - A function used to display the argument list or string on the monitor. It is like overwriting a character.

* Syntax: putchar();
Example:putchar(tolower(ch));

  • puts - A function used to display the argument list or string on the monitor. It does not need the help of the control string codes.

* Syntax: puts();
Example: puts(“hello”);


Format String and Escape Sequence

** All format specifiers start with a percent sign (%) and are followed by a single letter indicating the type of data and how data are to be formatted.


List of Commonly Used format specifiers

  • %c – used for single char in C
  • scanf(“%c”, &ch); printf(“%c”, ch);
  • %d – decimal number (whole number)
  • scanf(“%d”,&num); printf(“%d”,num);
  • %e – scientific notation / exponential form
  • scanf(“%e”, &result); printf(“%e”, result);
  • %f – number with floating or decimal point
  • scanf(“%f”,&pesos); printf(“%f”,pesos);
  • %o – octal number
  • scanf(“%o”, &valuet); printf(“%o”, value);
  • %s– string of characters
  • scanf(“%s”,&str); printf(“%s”,str);
  • %u – unsigned number
  • scanf(“%u”, &value); printf(“%u”, value);
  • %x– hexadecimal numbers
  • scanf(“%x”,&value); printf(“%x”,value);
  • %X – capital number for hexadecimal number
  • scanf(“%X”, &nos); printf(“%X”, nos);
  • %%– print a percent sign
  • scanf(“%%”,&value); printf(“%%”,value);


List of Commonly used escape sequence

  • \\ - prints backslash
  • \’ – prints single quotes
  • \” – prints double quotes
  • \? – prints question mark
  • \n - newline

GOTOXY- A function gotoxy is used to send the cursor to the specified location.


*Syntax: gotoxy(x,y);
Example: gotoxy(5,10);

NOTE:

** A format specifier %.2f can be used to limit the output being displayed into two decimal places only.

CONDITIONAL STATEMENTS

> Are statements that check an expression then may or may not execute a statement or group of statement depending on the result of the condition.

Types:

  • The If Statement
  • The If-Else Statement
  • The Nested-If Statement
  • The If-Else-If Ladder
  • The Switch Statement
  • The Nested Switch Statement

The If Statement


**The general form of the If statement with block statement is:


if ( expression)
{
statement_sequence;
}


**In an if statement, if the expression evaluates to TRUE (1), the statement or the block of statements that forms the target of the if statement will be executed. Otherwise, the program will ignore the statement or the block of statements.


The If-Else statement

**The general form of the if-else statement is:


If (expression)
statement_1;
else
statement_2;

  • Where:
    –If and else are reserved words
    –Expression is relational or Boolean expression that evaluates to a TRUE (1) or False (0) value.
    –Statement_1 and statement_2 may either be a single C statement or a block of c statements.


** The general form of the if-else statement with block of statement is:


If (expression)
{ statement_sequence;
}
else
{
statement_sequence;
}

  • If an if-else statement, if the expression is TRUE (1), the statement or block of statement after the if statement will be executed; otherwise, the statement or block of statement in the else statement will be executed.


Note: Only the code associated with the if or the code that is associated with the else executes, never both.


Nested-If statement

** One of the most confusing aspects of the if statement in any programming language is nested ifs. A nested if is an if statement that is the object of either an if or else. This is sometimes referred to as “an if within an if.” The reason that nested ifs are so confusing is that it can be difficult to know what else associates with what if.

** Fortunately, C provides a very simple rule for resolving this type of situation

** In C, the else is linked to the closest preceding if that does not already have an else statement associated with it.

  • Consider the following situations:
    –Situations 1.
    The else at number 3 is paired with the if in number 2 since it is the nearest if statement with the else statement.
    1. if…..
    2. if ……

    3. else
  • Consider the following situations:
    –Situations 2
    . The else in number 5 is paired with the if in number 1.
    1. if ….
    2. {
    3. if ….
    4. }
    5. else

** Note that there is a pair of braces found in number 2 and number 4.

** The pair of braces defined the scope of the if statement in number 1 starting from the { in number 2 and ends with } in number 4.

** Therefore, the else statement in number 5 cannot paired with the if statement in number 3 because the else statement is outside the scope of the first if statement.

** This makes the if statement in number 1 the nearest if statement to the else statement in number 5.


The if-else-if Ladder

** A common programming construct in C is the if-else- if ladder.


**The general form of the if-else-if ladder statement is:


if ( expression_1)
statement_1;
else if (expression_2)
statement_2;
else if (expression_3;
statement_3;
:
:
else
statement_else;

  • Where:
    –If and else are reserve words in C
    –Expression_1, expression_2 up to expression_n in relational or boolean expression that evaluates to a TRUE (1) or False (0) value.
    –Statement_1, statement_2 up to statement_else may either be a single C statement or a block of C statement.
  • In an if-else-if ladder statement, the expression are evaluated from the top downward.
  • As soon as a true condition is found, the statement associated with it is executed and the rest of the ladder will not be executed. If none of the condition is true, the final else is executed.
  • The final else acts as a defaults condition. If all other conditions are false, the last else statement is performed.
  • If the final else is not present, then no action takes place.


Note: The final else is optional, you may include this part if needed in the program or you may not include if not needed.


The switch statement

** The switch statement is a multiple-branch decision statement.

** The general form of the switch statement is:


switch (variable)
{
case constant1:
statement sequence_1;
break;
case constant2:
statement_sequence_2;
break;
:
:
default:
statement_sequence_default;
}

** In a switch statement, a variable is successively tested against a list or integer or character constants.

** If a match is found, a statement or block of statement is executed.

** The default part of the switch is executed if no matches are found.

** According to Herbert Schildt (1992), there are three important things to know about switch statements:
–1. The switch differs from if statements in such a way that switch can only test fro equality whereas if can evaluate a relational or logical expression.

–2. No two case constants in the same switch can have identical values. Of course, a switch statement enclosed by an outer switch may have case constant that are the same.


–3. If character constants are used in the switch, they are automatically converted to their integer values.


Note: The break statement is used to terminate the statement associated with each case constant. It is a C keyword which means that at that point of execution, you should jump to the end of the switch statement by the symbol }.


The Nested Switch Statement


** The general form of the nested switch statement is:


switch (variable)
{
case constant:{
switch (variable)
{
case constant1:
statement sequence_1;
break;
case constant2:
statement_sequence_2;
break;
}
break;
}
case constant2:
statement sequence;
break;
default:
statement sequence;
}











































Saturday, September 20, 2008

programming - NAVARRA

In this week, we learn a lot f things. we learned that the term used to display your statement is “printf” and the term used to scan the data you will enter is the “scanf”. And there is also a term to end the program which is the the “getch”.

We also discuss about the different types of conditional statement such as:
l The If statement
l The If-Else Statement
l The Nested-If Statement
l The If-Else-If Ladder
l The Switch Statement
l The Nested Switch Statement

The If statement:
· The general form of the If statement is:
if ( expression)
statement;
· Expression is relational or Boolean expression that evaluates to a TRUE (1) or False (0) value.
· The general form of the If statement with block statement is:
if ( expression)
{
statement_sequence;
}
The If-Else statement:
· The general form of the if-else statement is:

If (expression)
statement_1;
else
statement_2;

· Where:
– If and else are reserved words
– Expression is relational or Boolean expression that evaluates to a TRUE (1) or False (0) value.
– Statement_1 and statement_2 may either be a single C statement or a block of c statements
l If an if-else statement, if the expression is TRUE (1), the statement or block of statement after the if statement will be executed; otherwise, the statement or block of statement in the else statement will be executed.

Nested-If statement
l One of the most confusing aspects of the if statement in any programming language is nested ifs. A nested if is an if statement that is the object of either an if or else.
l This is sometimes referred to as “an if within an if.”
l The reason that nested ifs are so confusing is that it can be difficult to know what else associates with what if.

The if-else-if Ladder
l A common programming construct in C is the if-else- if ladder.
l The general form of the if-else-if ladder statement is:
if ( expression_1)
statement_1;
else if (expression_2)
statement_2;
else if (expression_3;
statement_3;
:
:
else
statement_else;

The switch statement
l The switch statement is a multiple-branch decision statement.
l The general form of the switch statement is:
switch (variable)
{
case constant1:
statement sequence_1;
break;
case constant2:
statement_sequence_2;
break;
:
:
default:
statement_sequence_default;
}
l In a switch statement, a variable is successively tested against a list or integer or character constants.
The Nested Switch Statement
l The general form of the nested switch statement is:
switch (variable)
{
case constant:{
switch (variable)
{
case constant1:
statement sequence_1;
break;
case constant2:
statement_sequence_2;
break;
}
break;
}
case constant2:
statement sequence;
break;
default:
statement sequence;
}

Friday, September 12, 2008

"THE C ENVIRONMENT" by M. Nona SIson

FOUR PARTS OF C ENVIRONMENT:
  • Main Menu
  • Editor's status line and edit window
  • Compiler message window
  • Hot Keys

Main Menu

instruct C to do something as indicated in the list of menu.

It can be used by pressing Alt key and the first letter of the main menu.

The Basic Menu of C

File – used to save files

Run – used to compile links and runs the program currently loading in the environment.

Compile – used to compile the program currently in the environment.

Submenu under the file menu are:

Load – enables the user to select a file to be opened.

Pick – enables the user to select a file based on the last nine files previously opened or edited.

New – allows the user to start a new program.

Save – store the file that currently in the editor.

Write to – enables the user to save the file in different filename.

Directory – displays the content of the current working directory.

Change Dir – enables the user to specify the defined path to change the default path

OS Shell – load the DOS command processor

Quit – lets the user to exit.

FIVE ELEMENTARY DATA TYPE IN C:

  • Char (character)
  • Int (integer)
  • Floating point
  • Double floating
  • Void

Editor status line and edit window- it is the part where you type your program- where you can see the current line and the column of the text you typed.

Message Window- is located beneath the middle of the edit window and hotkeys.- Used to display various compiler or linker.

Hot Keys- located at the bottom of C operating system.- Refers for shortcut or shorthand for selecting a menu.

"FLOWCHARTING AND ALGORITHMS" by: M. Nona Sison

FLOWCHARTING - is a two –dimensional representation of an algorithm.

A diagram representing the logical sequence in which a combination of steps is to be performed.
A common method of defining the logical steps of flow within a program by using a series of symbols to identify the basic input, process and output function within a program.

  • Algorithm-is a finite set of instruction that specify a sequence of operations to be carried out in order to solve a specific problem or class of problems.Basic symbols used in flowcharting:
  • Terminal- it is used to signify the beginning and the end.
    Preparation/ initialization- signifies the preparation of data. used to select initial conditions. Used to represent instructions or groups of instructions that will alter or modify a program's course of execution.
  • Input/Output- shows input and output. data are to be read inro the omputer's memory from an input device or data are to be passed fom the memory to an output device.
  • Processing- performs any calculations that are to be done.
  • Decision- signifies any decisions to be done.
  • On – page Connector- Shows the entry or exit point of the flowchart. A non – processing symbol used to connect one part of the flowchart to another without drawing flow lines.
  • Off – page Connector- Designated entry to or exit from one page when a flowchart requires more than one page.
  • Flow lines- Signifies the process that is to be executed next.
There are three BASIC CONTROL structures:
  1. Sequence
  2. Selection
  3. Repetition

Sequence- a process executed from one to another in a straightforward manner.

Selection (if- then- else)- a choice is provided between alternatives.

Repetition (Looping) - provides for the rpetitive exection of an operation or routine while the conditio is true.

Commonly Used Operators in Flowcharting

Arithmetic operators
+ addition
- subtraction
* multiplication
/ division

Relational Operators

Equal ,lesser than,greater than, not equal, greater than or equal to, lesser than or equal to

Logical Operators

&&- and

ll or

! not

THE "C LANGUAGE" by M.NONA SISON

"THE C LANGUAGE"

C is often called a middle-level language. C as a middle-level language means that it combines elements of high-level language with the functionalism of assembly language. It allows manipulation of bits, bytes, and addresses the basic elements with which the computer functions.

Input commands, output commands, and special words often referred to as reserved words allow the use of lower case only.

They should be written in lower case since C is sensitive to those words. They have only 32 keywords (27 from Kernighan and Ritchie standard and 5 added by the ANSI Standardization Committee.

C was initially used for system development work, in particular the programs that make up the operating system.

C is used mainly because it produces codes that run as fast as codes written in assembly language.

B was developed in the year 1970 by Ken Thompson. The said language is a successor of Basic Command Programming Language (BCPL), which was developed by Martin Richards.

X3J11 committee was created in the year 1983 under the American National Standard Institute (ANSI) to provide machine definition of the language and was than approved in 1989.

Features of C Languages

  • A simple core language, such as math functions or file handling provided by a standard set of library routines.
  • C encourages the creation of libraries user-defined functions.
    C is flexible when it allows unrestricted conversion of data from one type to another, such as conversion of a character to its numeric equivalent.
USES OF C

  • Operating system
  • Language compilers
  • Assemblers
  • Text editors
  • Print spoolers
  • Network devices
  • Modern programs
  • Databases
  • Language Interpreters Utilities

Saturday, September 6, 2008

THE C ENVIRONMENT - NAVARRA


In this week, we discuss a very long topic that we didn’t finish it. But still we learned about many things especially in the programming portion. I learned that there 4 parts of C environment. They are the main menu, editor status line and edit window, compiler message window, and hot keys.

Main menu

- it instruct C to do something as indicated in the list of menu.
- It can de used by pressing Alt key and the first letter of the main menu.
· The basic menu are:
ü File – used to save files
ü Run – used to compile links and runs the program currently loading in the environment.
ü Compile – used to compile the program currently in the environment.
· The submenu under the file menu are:
ü Load – enables the user to select a file to be opened.
ü Pick – enables the user to select a file based on the last nine files previously opened or edited.
ü New – allows the user to start a new program.
ü Save – store the file that currently in the editor.
ü Write to – enables the user to save the file in different filename.
ü Directory – displays the content of the current working directory.
ü Change Dir – enables the user to specify the defined path to change the default path
ü OS Shell – load the DOS command processor
ü Quit – lets the user to exit.

Editor status line and edit window
- it is the part where you type your program
- where you can see the current line and the column of the text you typed.

Message Window
- is located beneath the middle of the edit window and hotkeys.
- Used to display various compiler or linker.

Hot Keys
- located at the bottom of C operating system.
- Refers for shortcut or shorthand for selecting a menu.

I also learned that there are five elementary data type in C. and they are the character that is cut into the term char, the integer that is known as the int, the floating point, the double floating, and the void.

Char
– used to hold ANSCII characters or any 8 – bit quantity.



Int
– used to hold any real numbers.

Floating and double floating
– used to hold any real numbers and fractional quantity.


Void
– used to declare explicitly a function as returning no value.
– Declare explicitly a function as no parameters
– Used to create generic pointers.

We also learned about the ranges of value of the numbers that a certain data can hold. Ai also learned that if we will apply the modifier, the value will be change because modifiers are used to alter the meaning of the base type to fit the needs of various situations more precisely.I also learned that the list of modifiers are the Signed, unsigned, long and short.

And as the end of the week, Sir allow us to read and familiarize the 32 keyword that we will be using in our program.