Adv Procedural Programming
description
Transcript of Adv Procedural Programming
![Page 1: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/1.jpg)
Adv Procedural Programming
C Fundamentals
![Page 2: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/2.jpg)
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]
![Page 3: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/3.jpg)
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.
![Page 4: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/4.jpg)
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.
![Page 5: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/5.jpg)
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
![Page 6: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/6.jpg)
DecimalsDouble is used to define very large decimal values, 1.7e-308 to 1.7e308
![Page 7: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/7.jpg)
Characterschar values are actually stores as integers -128 to 127 which represents the ASCII value of the character.
![Page 8: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/8.jpg)
typedefUsing this statement you can rename a data type in order to make it easier to use.
typedef unsigned char xchar;
xchar variable;
![Page 9: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/9.jpg)
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.
![Page 10: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/10.jpg)
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”);
![Page 11: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/11.jpg)
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.
![Page 12: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/12.jpg)
Arithmetic Operators+ - Addition
- - Subtraction
* - Multiplication
/ - Division
% - Modulus (Remainder of Division operation)
![Page 13: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/13.jpg)
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
![Page 14: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/14.jpg)
Order of Operations( ) – Parenthesis, everything inside the parenthesis is completed first
^ - Exponent-- Negation
% - Modulus
*, / - Multiplication, Division
+, - - Addition, Subtraction
![Page 15: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/15.jpg)
Assignment StatementsSum = 0
Sum = VarA + VarB
These are both statements that assign a value to the Sum variable
![Page 16: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/16.jpg)
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”);
![Page 17: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/17.jpg)
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”);
![Page 18: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/18.jpg)
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;
}
![Page 19: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/19.jpg)
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.
![Page 20: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/20.jpg)
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
![Page 21: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/21.jpg)
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.
![Page 22: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/22.jpg)
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;
}
![Page 23: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/23.jpg)
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)
![Page 24: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/24.jpg)
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)
![Page 25: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/25.jpg)
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.
![Page 26: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/26.jpg)
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
}
![Page 27: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/27.jpg)
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.
![Page 28: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/28.jpg)
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
![Page 29: Adv Procedural Programming](https://reader036.fdocuments.us/reader036/viewer/2022062305/568150a3550346895dbea481/html5/thumbnails/29.jpg)
Program Development5. Maintenance
The program is changed according to business needs and any problems that were missed in testing are corrected