adv procedural programming
DESCRIPTION
Adv Procedural Programming. C Fundamentals. Variables. All variables utilized by a C program must be defined. TypeDef Var Name f loat Var double Var int Var long Var c har Var c har Var [X]. Integers. - PowerPoint PPT PresentationTRANSCRIPT
Adv Procedural Programming
C Fundamentals
VariablesAll variables utilized by a C program must be defined.
TypeDef Var Name
float Var double Var
int Var long Var
char Var
char Var[X]
Integersint defines an integer value or whole number, a value without a decimal point.
Values defined as integers are stored in memory using 2 bytes of storage and can hold values from 32,766 to -32,766.
The first bit of storage is used to identify the sign of the value.
Integerslong identifies an integer value that is stored utilizing 4 bytes of storage. As such it can store 231 to -231(2,147,483, 647 to 2,417,483,648).
Again the first bit is utilized to define the sign of the value.
Decimalsfloat is used to define a decimal value that is stored in 4 bytes of memory. The first three bytes are the mantissa the remaining byte stores the exponent.
2.295 = 2.295e101
22.95 = 2.2295e102
DecimalsDouble is used to define very large decimal values, 1.7e-308 to 1.7e308
Characterschar values are actually stores as integers -128 to 127 which represents the ASCII value of the character.
typedefUsing this statement you can rename a data type in order to make it easier to use.
typedef unsigned char xchar;
xchar variable;
printfNot only used to output numbers and character stings but also used to format output.
printf(“print this”);
Output is formatted using escape sequences, a backslash followed by a character.
printfCommonly used escape sequences.
\n – The newline character moves the cursor to the next line.
printf(“Print This\n”);
\t – The tab sequence inserts a tab between the desired characters.
printf(“Print\tThis”);
printfNumbers are formatted using format specifiers.
%d - Format integer as decimal%f – Format float as decimal%x – Format integer as a hex value%5.2f – Format a float as 5 digits with 2 decimal points%5f – Format as a float with 8 digits and now decimal
points.
Arithmetic Operators+ - Addition
- - Subtraction
* - Multiplication
/ - Division
% - Modulus (Remainder of Division operation)
Relational Operators== - Are two values equal to one another
< - Greater than
<= - Greater Then or Equal to
> - Less than
>= - Less than or Equal to
!= Not Equal to
Order of Operations( ) – Parenthesis, everything inside the parenthesis is completed first
^ - Exponent-- Negation
% - Modulus
*, / - Multiplication, Division
+, - - Addition, Subtraction
Assignment StatementsSum = 0
Sum = VarA + VarB
These are both statements that assign a value to the Sum variable
Decision Structuresif – then : A single decision structure if the condition is
true execute the code, it its false don’t execute the code.
if (A == B)
printf(“Look What You Did/n”);
Decision Structuresif – then – else : A two decision structure if the
condition is true execute the code, if it’s not then execute some other code.
if (A == B) then
printf(“Look What You Did/n”);
else
printf(“Opps You Did This Instead/n”);
Decision StructuresSwitch - A structure utilized in place of a nested or chained if-then-else
structure to react to several different values of a condition. The major drawback to this structure is its limitation to the use of integers.
Switch (Var1)
{
case 1:
printf(“It’s a 1/n”);
break;
case2:
printf(“It’s a 2/n”);
break;
}
IterationIteration is another way of referring to repetition or basically repeating selected instructions. There are two basic types of structures utilized when performing iteration:
Determinate – you know exactly how many times you want to repeat the operations.
Indeterminate-You repeat the operations until a condition is meet but don’t know how many times specifically.
Determinate StructuresRemember these structures are used when you know exactly how many times you want to execute the operations.
for(var = initial value, terminating value, increment)
for(int X = 0, X < 10, X++)
This loop will execute 10 times and then stop
Indeterminate StructuresThese structures are utilized when you don’t know exactly how many time you want the execute the operations. You also have to include a terminating condition that when meet causes execution to stop.
Two basic structures pre-test where the condition is examined prior to execution and post-test where the condition is examined after the loop executes at least once.
Indeterminate StructuresStandard Pre-Test structure of a while loop. While the condition is true then execute the statement or statements.
while (condition is true)
{
statements;
}
Indeterminate StructuresA post-test structure that executes the body of the loop at least once the second repetition dependent on the outcome of the test.
do
{
statements;
statements;
} while (conditon)
FunctionsBefore being used by a program a function must be declared sand a function prototype must be included in the program.
Function name (data type parameter name)
return type function name (data type parameter name)
FunctionsFunctions are called using the function name and the arguments or data that is sent to the function.
FunctionName (arguments)
Functions can appear at the top or the bottom of a program usually the function declaration is place at the top of the program while the function itself is placed at the bottom of the program.
FunctionsA function is defined by its header which his located at the top of the function and is similar to the function declaration.
RtnType FunctionName(Arguments)
void Function(Value1, value2) --- Header
{
Function Body
}
Program Development1. Planning
What has to be done, what information is to be delivered to the user. When is it needed, how will it be used, what format does it need to take.
2. AnalysisHow is the information currently gathered, does it exist and where does it reside, what format does it take. How is it ordered, what security is needed. What data is needed and what format does it need to be in.
Program Development3. Design
How will the new system work what procedures and functions will be used what order will the operations take
4. ImplementationThe program is actuality developed, tested, debugged and refined
Program Development5. Maintenance
The program is changed according to business needs and any problems that were missed in testing are corrected