Sei sulla pagina 1di 9

Computer programming is creating a sequence of instructions to enable the computer to

do something.

A programming language is an artificial language that can be used to control the


behavior of a machine, particularly a computer.

Source Program - Program written in a high-level programming language.

Object Program - The source program after it has been translated into machine
language.

Translator Program - The program that translates the source program into the object
program. Can be either a compiler or an interpreter.

Compiler - spends some time evaluating the entire program and then translates all the
programming statements of a program into a machine language program, which is then
executed at once.

Interpreter - translates interactively each programming statement into an immediately


usable machine language instruction. Although an interpreter slows down the execution
speed of a program somewhat, it does not require extra steps to compile and link like a
compiler.

Categories of Programming

Systems programming involves writing programs that enable a computer to carry out its
basic internal functions as well as some other specialized functions.

Applications programming refers to the process of developing programs to be used for


specific applications, such as a business application

Stages in the Applications Programming Process

1. Problem statement

2. Algorithm development

3. Program coding

4. Program testing

5. Program documentation
Common Programming Errors

1. Syntax Errors

- occurs when your code violates one or more grammar rules of C and is detected by
the compiler as it attempts to translate your program.

2. Run-time Errors

- are detected errors and displayed by the compiler during the execution of the program.

- occurs when the program directs the computer to perform illegal operation, such as
dividing a number by zero

3. Logic Errors

- occur when a program follows a faulty algorithm.

C History

Dennis Ritchie – developed Turbo C at AT&T Bell Laboratories.

Turbo C was first developed for system programming.

C Language

- One of the most popular languages of modern times.


- Programs written in C are Portable across different environments
- Applications created using the C language range from operating systems to
database systems.

C Language Elements

The C Preprocessor - a program that is executed before the source code is compiled.
DIRECTIVES – how C preprocessor commands are called, and begin with a pound /
hash symbol (#).

Two Common Directives:

1. #include – gives program access to a library.

- causes the preprocessor to insert definitions from a standard header file into the
program before compilation.

- tells the preprocessor that some names used in the program are found in the standard
header file.
2. #define – allows you to make text substitutions before compiling the program.

- by convention, all identifiers that are to be changed by the preprocessor are written in
capital letters.

Libraries – C implementations that contain collections of useful functions and symbols


that may be accessed by a program.

Function Main

Every C program has a main function. This is where program execution begins.

Body- the remaining line of the program in the body.

Braces {} – enclose the body of the function.

- indicates the beginning and end of the function main.

Two parts of the function body:

1. Declarations

– the part of the program that tells the compiler the names of memory cells in a program
needed in the function, commonly data requirements identified during problem analysis.

2. Executable statements

– derived statements from the algorithm into machine language and later executed.

a reserved word is defined as the word that has special meaning in C and cannot be
used for other purposes.

Punctuation Marks

/* */ -(slash asterisk) used to enclose a single line remarks.

“ -(double quotation) used to display series of characters, and initializing string


constant.

; -(semicolon) statement separator

, -(comma) used to separate one variable to another

= -(equal sign) used as assignment operator

‘ -(single quotation) used for initializing character expression

& -(ampersand) used as address operator


{} -(open/close braces) denotes the beginning and end of the program.

Variables, Data Types and Constants Variables

- are like containers in your computer's memory

- associated with a memory cell whose value can change as the program executes.
Variable declaration

– statements that communicate to the C compiler the names of all variables used in the
program and the kind of information stored in each variable.

- also tells how that information will be represented in memory.

Data Type – a set of values and a set of operations that can be performed on those
values.

Seven Basic C Data Types:

1. Text (data type char) – made up of single characters (example x,#,9,E) and strings
(“Hello”), usually 8 bits, or 1 byte with the range of 0 to 255.

2. Integer values – those numbers you learned to count with.

3. Floating-point values – numbers that have fractional portions such as 12.345, and
exponents 1.2e+22.

4. Double-floating point values – have extended range of 1.7e-308 to 1.7e+308.


Variables, Data Types and Constants

5. Enumerated data types – allow for user-defined data types.

6. Void – signifies values that occupy 0 bit and have no value. You can also use this
type to create generic pointers.

7. Pointer – does not hold information as do the other data types. Instead, each pointer
contains the address of the memory location.

int - data type int is used to define integer numbers.

float - data type float is used to define floating point numbers.

double - data type double is used to define BIG floating point numbers. It reserves twice
the storage for the number. On PCs this is likely to be 8 bytes.

char - data type char defines characters


Modifiers

The three data types above have the following modifiers.

- short
- long
- signed
- unsigned

Constants

– identifiers that are having a constant value all throughout the program execution.

- also fixed values that may not be altered by the program.

Examples:

1. Character constants – enclosed between single quotes. Ex. ‘A’, ‘+’

2. Integer constants – specified as numbers without fractional components. Ex. 5 and -


160 Variables, Data Types and Constants

3. Floating constants – require the use of decimal point followed by the number’s
fractional components. Ex. 16.234

4. String constants – set of characters enclosed by double quotes. Ex. “bag” and “this is
good”

5. Backslash character constants – enclosing all character constants in single quotes


that works for most printing characters. Ex. g = ‘\t

SEQUENCE | NAME | MEANING

\a | Alert | Sound a beep

\b | Backspace | Backs up one character

\f | Form feed | Starts a new screen of page

\n | New line | Moves to the beginning of the next line

\r | Carriage Return | Moves to the beginning of the current line

\t | Horizontal tab | Moves to the next Tab position

\v | Vertical tab | Moves down a fixed amount

\\ | Backslash | Displays an actual backslash


\’ | Single quote | Displays an actual single quote

\? | Question mark | Displays an actual question mark

\”” | Double quote | Displays an actual double quote

Defining Constants

#define preprocessor - allows us to define symbolic names and constants.

Operators

Assignment Operator

– Equal sign (=) - the most basic assignment operator where the value on the right of
the equal sign is assigned to the variable on the left.

Binary Operators - take two operands and return a result.

+, -, *, /, %

Increment (++) and Decrement (--) Operators

++ increment adds one to a value of the variable

-- decrement subtracts one from a value of the variable

Prefix increment is when the ++ is placed immediately in front of its operand.  the value
of the expression is the variable’s value after incrementing.

Postfix increment is when the expression’s value is the value of the variable before it is
incremented.

Date Types printf conversion specification scanf conversion specifications

long double %Lf %Lf

double %f %lf

float %f %f

unsigned long int %lu %lu

long int %ld %ld

unsigned int %u %u

int %d %d
short %hd %hd

char %c %c

String - %s

Numeric Input Command

scanf() – one of the Turbo C object stream object that is used to accept data from the
standard input, usually the keyboard.

getch() – allows the user to input a character and wait for the enter key. Inputted char
will not be echoed but could be stored if location is specified.

getche() – allows the user to input a character and there is no need for the enter key.
Inputted char will be echoed but could be stored if location is specified.

gets() – allows the user to input a sequence of characters (string).

printf – writes formatted output to the standard output device such as the monitor.

putchar – writes the single character to the screen

puts – writes the string to the standard output device such as the monitor and positions
the cursor to the next line.

Control Flow

Control Structures - specify the sequence of execution of a group of statements.

3 Types:

1. Sequential

2. Conditional

3. Iterative

Sequential - organized such that statements are executed in sequence, i.e., one after
the other in the order of their appearance in the source code.

A flowchart is a diagrammatic representation that illustrates the sequence of operations


to be performed to get the solution of a problem. Flowcharts are generally drawn in the
early stages of formulating computer solutions. Flowcharts facilitate communication
between programmers and business people. Documentation of a complex program.
Advantages of Flowchart

1. Communication.

2. Effective analysis

3. Proper documentation

4. Efficient coding flowcharts act as a guide or blueprint during the system analysis and
program development phase.

5. Proper Debugging flowchart helps in debugging process

6. Efficient program maintenance maintenance becomes easy with. It helps the


programmer to put efforts more efficiently on that part.

Limitations of flowcharts

1. Complex logic – sometimes the logic is quite complicated, which makes flowchart
becomes complex and clumsy.

2. Alteration and Modifications – if alterations are required, the flowchart may require re-
drawing completely.

3. Reproduction – flowchart symbols cannot be typed, reproduction of flowchart


becomes a problem.

4. The essentials of what is done can easily be lost in the technical details of how it is
done.

Flowchart Symbols:

1. Terminal Symbol - used to designate the beginning and end of a program.

2. Input Symbol or - represents an instruction to an input device

3. Processing Symbol - used to represent a group of program instructions that perform a


processing function or activity such as mathematical operations or logical comparisons.
Algorithms and Flowcharting Flowchart Symbols:

4. Output Symbol or - represents an instruction to an output device.

5. Decision Symbol - denotes a point in the program where more than one path can be
taken or used to designate a decision making process. Algorithms and Flowcharting
Flowchart Symbols:
6. Flow lines and Arrowheads - used to show reading order or sequence in which
flowchart symbols are to be lead. - show the direction of processing of data flows.

7. On-page Connector - non processing symbol - used to connect one part of the
flowchart to another without drawing flow lines within page. A A Denotes an entry
Denotes an exit Algorithms and Flowcharting A A Flowchart Symbols:

8. Off-page Connector - non processing symbol - used to connect one part of the
flowchart to another without drawing flow lines not within the same page.

9. Predetermined Symbol - used as a subroutine symbol - inner procedure needs to be


repeated several times.

A system flowchart shows in general terms the operations that will be performed on
information in an information system

OTHER TYPES OF FLOWCHARTS

High-Level Flowchart

Detailed Flowchart

Potrebbero piacerti anche