Professional Documents
Culture Documents
Implementation
Implementation
BOLA AKANDE
INTRODUCTION TO
PROGRAMMING
COSC101
BABCOCK UNIVERSITY
IMPLEMENTATION PHASE
Run-time error
– An error that does not prevent your program from
compiling, but causes it to fail when you try to run
it. This refers to errors reported during execution,
this can be a semantic error or it can be a logic
error.
Example includes:
– trying to divide by zero
– trying to open a file that does not exist
Programming Errors . . .
Logic error
– An error in design or implementation that does not
prevent your program from compiling but causes it
to not do what you intended.
– Difficult to detect and track.
– Examples are:
an incorrect formula
incorrect sequence of statements
INTRODUCTION TO C
Limitations of C:
cannot handle exceptions
range-checking
garbage collection
object-oriented programming
polymorphism
Thus C needs to be extended.
C EXTENSION
/
*………………………………………………………
…………………………………………………………
…………………………………………………………
……………………*/ multiple line commenting
//…………………………………………………
//…………………………………………………
// … single line commenting
Simple .c program
//first program
int main(void) //return-type function-name(parameters
{ //Function body
int age;
printf(“Akande Oyebola\n”);
printf(“I am good”);
return 0;
}
format specifier
\n
\t
printf(“Course code\tCourse tittle\t\tCourse
Unit\n”);
Printf(“C0SC101\tIntro Prog\t\t3\n”);
Assignment
Course form
1.Open the bin folder
int main(void)
Every C program must have at least a main function
int – mean main returns integer (whole number)
Void – means main does not receives information( argument)
Explanation
• {
This opening brace marks the start of the statements that
make up the function. And must be ended with a closing
brace (}).
This pair of braces and the portion of the program between the
braces is called a block
Explanation
return 0;
Indicate the program ended successfully
The keyword return is one of several means
we’ll use to exit a function
Every statement must end with a semicolon (also
known as the statement terminator).
Classwork
Syntax:
#define token-name replacement text
#define can be used for symbolic constant e.g.
#define PIE 3.142
This means subsequence occurrence of PIE will be
replaced by 3.142
Function Prototype and variable
declarations
Function prototypes and variable declarations is the third step
in creating a C file.
Function prototypes are also known as function declarations.
Declaration refers to where the nature of a variable is stated
but no storage is allocated.
At this stage user-defined function are declared. Also any
variable declared here are called external variable.
External variable is a variable which is not declared within any
function and can be accessed by any function.
Function
# indicates
That this
Line should be interpreted
By the preprocessor
Escape Sequences
C uses special character constants to represent unprintable characters
These characters usually perform control functions
For example, '\n' is the new line sequence.
The statement below tells the program to start a new line
of text on screen.
printf('\n');
The difference between a character constant and a special character
constant is the backslash
If you are using a special character constant on its own, you must
enclose it in single quotes
Using Special Constants contd
Some common examples of escape sequences are presented below:
Escape Sequence Description
\n Newline
Identifier
Constants
Operators
Punctuation/Separators
White space
Assignment
Using simple structure of C, write out your answers to the
classwork.
QUIZ
Problem solving problem
Structure of c program
Draw Flowchart to read score and determine pass or fail
Input score and determine grade from A to F
QUIZ
Comfort model school want to celebrate each pupils on
their birthdays. They want a record which will indicate the
current age of each pupil each year. Do the following in
tabular form:
Identify the input data
Identify the output data
Identify the processing requirements
Give each data a variable name
Indicate the data type of each variable
CLASSWORK
A class teacher needs to compute the average score
of 20 pupils in eight (8) subjects. Thus, before
developing the application you need to understand
and analyse the problem clearly stating the input
data, output data, and processing requirements.