0% found this document useful (0 votes)
20 views125 pages

ES084 - Lecture Notes MADE4 Learning Part 1 - A

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 125

Computer Programming 1

Prepared by:

Roel Lauron
Instructional Resources/ Textbook

References:
005.133/B789/2013 Bronson, Gary J. C++ Programming: Principles and Practices for Scientists and Engineers. Cengage
Learning, 2013.

005.133/F769/2011 Forouzan, Behrouz A. Foundations of C Programming. Cengage Learning, 2011.

005.133/M295/2011 Malik, D.S. C++ Programming: Problem Analysis to Program Design. Cengage Learning, 2011.

005.133/Sch644/2011 Scholl, T., Nugent, G. C++ Programming Problem Analysis to Program Design (Lab Manual). Cengage
Learning, 2011

005.133/V74/2008 Vine, Micheal A. C Programming for the Absolute Beginner, 2008


Internet Sources:

www.course.com
www.thomsonlearning.com
www.tutorialspoint.com/cprogramming/
www.cprogramming.com/tutorial/c-tutorial.html
www.iu.hio.no/~mark/CTutorial/CTutorial.html
http://fresh2refresh.com/c-tutorial-for-beginners
What is computer Programming?
Computer programming is creating a sequence of
instructions to enable the computer to do
something.

Computer programming is not just programming


language syntax and using development
environment. At its core, computer
programming is solving problems.
What is a programming language?

A programming language is an artificial


language that can be used to control the
behavior of a machine, particularly a
computer.
Programming Language Translation
 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.
Compilers vs. Interpreters
 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.
 In a production environment where throughput is more critical, a
compiled language is preferred.
 Any high-level language can either be interpreted or compiled.
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. Examples of systems
programs include operating systems, device drivers, and utility
programs.
 Applications programming refers to the process of
developing programs to be used for specific applications, such
as a business application (e.g., computing benefits to be paid to
different employee classifications) or an academic application
(e.g., determining who qualifies for which scholarship, based on
specified eligibility criteria).
Stages in the Applications Programming Process
1.Problem statement: The programming process begins
with a clear, written statement of the problem to be solved
by the computer.
2.Algorithm development: Once the problem has been
clearly stated and all the requirements have been
understood, the next step is to develop the program logic
necessary for accomplishing the task.
*An algorithm is defined as a logical sequence of steps
that must be performed in order to accomplish a given
task.
•Sample Tool: Flowchart
Stages in the Applications Programming Process
3. Program coding: When the programmer is satisfied with the
efficacy of the logic developed in the preceding step, it is time
to convert that logic (in either flowchart or pseudocode form)
to the specific syntax of the programming language that will
be used.
4. Program testing: The coded program is next checked for
errors.
5. Program documentation: The programming process is
complete when the program has been fully documented.
Computer Programming 1
Five steps to define a programming problem:
1. Restate the problem.
2. Analyze the problem.
3. Identify the output.
4. Identify the input.
5. Identify the process.
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.
Note: If a statement has a syntax error, it cannot be
translated and your program will not be executed.
Common Programming Errors
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.
- an attempt to perform an invalid operation, detected during
program execution.
Note: When a run-time error occurs, the computer will stop
executing your program and will display a diagnostic message
that indicates the line where the error was detected.
Common Programming Errors

3. Logic Errors
- occur when a program follows a faulty algorithm.
- do not cause a run-time error and do not display
error messages, so are very difficult to detect.

Note: The only sign of a logic error may be incorrect


program output.
C History
Dennis Ritchie – developed C at AT&T
Bell Laboratories.

C was first developed for system


programming.
C Programming Language
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 Programming Language

 C is a programming language designed by


Dennis Ritchie in 1972 at AT&T Bell
Laboratories.
 C was designed as a language for systems
programming, as a way to fully access the
computer’s power without becoming caught up
in the tedious writing of assembly language.
General Description of C

C is a concise language
⚫ it has only about 32
keywords
⚫ it encourages concise code.
General Description of C

C is flexible, powerful, and


well suited for programming
several levels of abstraction.
General Description of C
 C is a modular language
⚫ The function is the primary program
structure, but functions may not be
nested.
⚫ The C programmer depends on a library
of function, many of which becomes part
of the standard language definition.
General Description of C
 C is the basis for C++.
⚫ C++ programmer also uses many of the
constructs and methodologies that are
routinely used by the C programmer.
⚫ learning C can be considered a first step
in learning C++.
General Description of C

C is weakly typed
⚫ allowing quite a bit of data
conversion and providing
minimal run time checking.
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 (#).
No white space should appear before the #, and a
semi colon is NOT required at the end.
C Language Elements
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.
C Language Elements
Two Common Directives:
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.
C Language Elements
#include <stdio.h>
#define MIN 0 /* #defines */
#define MAX 10
#define TRUE 1
#define FALSE 0
int main() { /* beginning of program */
int a;
int okay=FALSE;/*the compiler sees this as int okay=0;*/
while(!okay) {
printf("Input an integer between %d and %d: ", MIN, MAX); scanf("%d",
&a);
if(a>MAX) {
printf("\nToo large.\n"); }
else if(a<MIN) {
printf("\nToo small.\n"); }
else { printf("\nThanks.\n");
okay = TRUE; }
} return 0; }
C Language Elements
Libraries – C implementations that
contain collections of useful
functions and symbols that may be
accessed by a program.

Note: A C system may expand the number of


operation available by supplying additional
libraries. Each library has a standard
header file whose name ends with the
symbol .h.
C Language Elements
Commenting Your Code
You can add comments to your code by enclosing your
remarks within /* and */. However, nested comments
aren't allowed.
A few properties of comments:
• They can be used to inform the person viewing the code
what the code does. This is helpful when you revisit the
code at a later date.
• The compiler ignores all the comments. Hence, commenting
does not affect the efficiency of the program.
• You can use /* and */ to comment out sections of code
when it comes to finding errors, instead of deletion.
C Language Elements
Here are examples of commented code:

/* Comments spanning several */


/* lines can be commented*/
/* out like this!*/
/* But this is a simpler way of doing it! */
// These are C++
// style comments
// and should NOT
// be used with C!!
/* /* NESTED COMMENTS ARE ILLEGAL!! */ */
C Language Elements
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.
C Language Elements
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.
C Language Elements
Your First Program

#include <stdio.h>
#include <conio.h>

main()
{
printf("Hello World!\n"); //syntax of printf
getch();
}
C Language Elements
Reserved Words
In C, a reserved word is defined as
the word that has special meaning
in C and cannot be used for other
purposes.

Examples: int, void, double, return,


printf, scanf, if, while, do, for
C Language Elements
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.
2-3 Identifiers
One feature present in all computer languages is the
identifier. Identifiers allow us to name data and other
objects in the program. Each identified object in the
computer is stored at a unique address. If we didn’t have
identifiers that we could use to symbolically represent data
locations, we would have to know and use object’s
addresses. Instead, we simply give data identifiers and let
the compiler keep track of where they are physically
located.
C Language Elements
Reserved Words
In C, a reserved word is defined as
the word that has special meaning
in C and cannot be used for other
purposes.

Examples: int, void, double, return


Variables, Data Types and Constants
Naming Conventions (Identifiers)

1. Names are made up of letters and digits.


2. The first character must be a letter.
3. C is case-sensitive, example ‘s’ is not the same with ‘S’.
4. The underscore symbol (_) is considered as a letter in C.
It is not recommended to be used, however, as the first
character in a name.
5. At least the first 3 characters of a name are significant.
Variables, Data Types and Constants
Names... Example

CANNOT start with a number 2i


CAN contain a number elsewhere h2o
CANNOT contain any arithmetic operators... r*s+t
CANNOT contain any other punctuation marks... #@x%£!!a
CAN contain or begin with an underscore _height_
CANNOT be a C keyword struct
CANNOT contain a space im stupid
CAN be of mixed cases Squared
Note
An identifier must start with a letter or underscore:
it may not have a space or a hyphen.
Note
C is a case-sensitive language.
Variables, Data Types and Constants
Variables - are like containers in your
computer's memory - you can store values
in them and retrieve or modify them when
necessary.
- 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.
Variables, Data Types and Constants
Syntax for Declarations:

data type variable_list;

Ex. int x,age;


float sum,a,b;
char middle_intial;
Note
When a variable is defined, it is not initialized.
We must initialize any variable requiring
prescribed data when the function starts.
Variables, Data Types and Constants
Data Type – a set of values and a set
of operations that can be performed
on those values.

Standard Predefined Data Type in C:


➢ char

➢ double/float

➢ int
Variables, Data Types and Constants
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.
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.
Variables, Data Types and Constants
int - data type
int is used to define integer numbers.
Ex.
{ int Count;
Count = 5; }

float - data type


float is used to define floating point numbers.
Ex.
{ float Miles;
Miles = 5.6; }
FIGURE 2-10 Floating-point Types
Variables, Data Types and Constants
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.
Ex.
{ double Atoms;
Atoms = 2500000; }

char - data type


char defines characters.
Ex.
{ char Letter;
Letter = 'x'; }
Variables, Data Types and Constants
Modifiers

The three data types above have the following


modifiers.
 short
 long
 signed
 unsigned
The modifiers define the amount of storage allocated
to the variable. The amount of storage allocated is
not cast in stone. ANSI has the following rules:
short int <= int <= long int
float <= double <= long double
Variables, Data Types and Constants
Type Bytes Bits Range
short int 2 16 -32,768 -> +32,767 (32kb)
unsigned short int 2 16 0 -> +65,535 (64Kb)
unsigned int 4 32 0 -> +4,294,967,295 ( 4Gb)
int 4 32 -2,147,483,648 -> +2,147,483,647 (2Gb)
long int 4 32 -2,147,483,648 -> +2,147,483,647 (2Gb)
signed char 1 8 -128 -> +127
unsigned char 1 8 0 -> +255
float 4 32
double 8 64
long double 12 96
Variables, Data Types and Constants
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
 Floating constants – require the use of
decimal point followed by the number’s
fractional components. Ex. 16.234
 String constants – set of characters
enclosed by double quotes. Ex. “bag”
and “this is good”
 Backslash character constants –
enclosing all character constants in
single quotes that works for most
printing characters. Ex. g = ‘\t’
Variables, Data Types and Constants
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
Variables, Data Types and Constants
Defining Constants

 #define preprocessor
- allows us to define symbolic names and
constants.
A quick example:
#define PI 3.14159
This statement will translate every occurrence of PI in
the program to 3.14159.
Here is a more complete example:
#define PI 3.14159 main() { int r=10; float cir; cir =
PI * (r*r); }
Variables, Data Types and Constants
Defining Constants

 The const keyword.


- used to create a read only variable. Once initialized, the value of the variable
cannot be changed but can be used just like any other variable.
const syntax:
main()
{ const float pi = 3.14; }
The const keyword is used as a qualifier to the following data types - int float
char double struct.
const int degrees = 360;
const float pi = 3.14;
const char quit = 'q';
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.
Example:
c = c + 1;
radius = 2 * diameter;
stat = getch();
Operators
Binary Operators
- take two operands and return a result.

Operator Use Result


+ op1 + op2 adds op1 to op2
- op1 - op2 subtracts op2 from op1
* op1 * op2 multiplies op1 by op2
/ op1 / op2 divides op1 by op2
% op1 % op2 computes the remainder
from dividing op1
by op2
Operators
Unary Operators
- changes the sign of a value or
variable.
- Unary minus (-) and unary plus
(+)
Examples:
2 +-3
((-x) + (+y))
Operators
Increment (++) and Decrement (--)
Operators

++ increment adds one to a value of the


variable
-- decrement subtracts one from a value
of the variable

Note: The value of the expression in which


++ or -- operator is used depends on the
position of the operator.
Increment (++) and Decrement(--) Operators

 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.
Increment (++) and Decrement(--) Operators

 Postfix increment
⚫ is when the expression’s value is the
value of the variable before it is
incremented.
Increment (++) and Decrement(--) Operators

 Comparison of POSTFIX and PREFIX


Increments
 Before… x y
Increment (++) and Decrement(--) Operators
 Increments… y = ++x y = x++
 Prefix: Increment x and then used
it.
 Postfix: Use x and then increment
it.

 Prefix Postfix
 After… x y x y
Example
main(){
int a=3, b;

b=a++;
printf(“b is %d, and a is %d\n”, b, a);
b=++a;
printf(“Now b is %d, and a is %d\n”, b, a);
b=5%--a;
printf(“Now b is %d, and a is %d\n”, b, a);
printf(“Now b is %d, and a is %d\n”, ++b, a--);
printf(“Now b is %d, and a is %d\n”, b, a);
}
Output
b is 3, and a is 4
Now b is 5, and a is 5
Now b is 1, and a is 4
Now b is 2, and a is 4
Now b is 2, and a is 3
Operators
Prefix increment/decrement - when the ++
or -- is placed immediately in front of its
operand. Meaning the value of the
expression is the variables value after
incrementing or decrementing.

Postfix increment/decrement – when the


++ or -- comes immediately after the
operand. The value of the expression is
the value of the variable before it is
incremented or decremented.
Predefined Mathematical Functions
Function Purpose
abs(x) returns the absolute value of integer x.
x=abs(-5); x=5
fabs(x) returns the absolute valued of type double.
x=fabs(-5.2); x=5.2
ceil(x) rounds up or returns the smallest whole
number that is not less than x.
x=ceil(5.2); x=6
floor(x) rounds down or returns the largest whole
number that is not greater than x.
x=floor(5.2); x=5
Predefined Mathematical Functions
Function Purpose
sqrt(x) returns the non-negative square of x.
x=sqrt(25); x=5
pow(x) returns x to the power of y.
x=pow(4,2); x=16
sin(x) returns the sine of angle x.
cos(x) returns the cosine of angle x.
tan(x) returns the tangent of angle x.
log(x) returns the natural logarithm of x.
log10(x) returns the base 10 logarithm of x.
Conversion Specifications
Date Types printf conversion scanf conversion
specification 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
I/O Functions
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.
syntax:
scanf(“format”, &var_name);
Example:
printf(“Input side of the square:”);
scanf(“%d”, &s);
Note
A terminal keyboard and monitor can be associated
only with a text stream. A keyboard is a source
for a text stream; a monitor is a destination
for a text stream.
Note
scanf requires variable addresses in the address list.
I/O Functions
Character/String Input Command

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.
Syntax:
getch();
var_name = getch();

Example: ans = getch();


I/O Functions
Character/String Input Command

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.
Syntax:
getche();
var_name = getche();

Example: ans = getche();


I/O Functions
Character/String Input Command

gets() – allows the user to input a sequence


of characters (string).
syntax:
gets(variable_name_of_char_type);

Example:
gets(name);
I/O Functions
Output Command

printf – writes formatted output to the standard output device such as the
monitor.
syntax:
printf(“format code”,var_name);
Example:
printf(“%d”,x);

puts – writes the string to the standard output device such as the monitor and
positions the cursor to the next line.
syntax:
puts(“string expression”);
Example: puts(“CIT”);
FIGURE 2-17 Output Stream Formatting Example
I/O Functions
Output Command

putchar – writes the single character to


the screen.
syntax:
putchar(var_name);

Example:
putchar(a);
Introduction to C Programming

CONTROL FLOW
Control Flow
Control Structures - specify the sequence of
execution of a group of statements.
3 Types:

1. Sequential

2. Conditional

3. Iterative
Control Flow
1. Sequential Logic Structure

- The oldest logic structure


- The most used logic structure
- The easiest structure to understand
- Is one statement after another
statement, after another statement,
after another statement, etc.
FLOWCHART

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.
Flowchart
Flowcharting is a technique of
showing logical flow of data in
pictorial form and integration
of programming steps for
solving a given problem.
Program Flowchart
The flowchart is a means of visually presenting the flow of data through an
information processing systems, the operations performed within the system and the
sequence in which they are performed. In this topic, the concentration will be that of
a program flowchart, which describes what operations (and in what sequence) are
required to solve a given problem. The program flowchart can be likened to the
blueprint of a building. As we know a designer draws a blueprint before starting
construction on a building. Similarly, a programmer prefers to draw a flowchart prior
to writing a computer program. As in the case of the drawing of a blueprint, the
flowchart is drawn according to defined rules and using standard flowchart symbols
prescribed by the American National Standard Institute, Inc.
Guidelines in Flowcharting
1. In drawing a proper flowchart, all necessary
requirements should be listed in logical order.
2. Flowchart should be clear, neat and easy to follow.
3. The usual direction of the flow of a procedure or
system is from left to right or top to bottom.
4. Only one flow line should come out from a process
symbol.
Guidelines in Flowcharting
5. Only one flow line should enter a decision symbol, but
2 or more flow lines, one for each possible answer,
should leave the decision symbol.
6. If flowchart becomes complex, it is better to use
connector symbols to reduce the number of flow lines.
Avoid the intersection of flow lines.
7. Ensure that flowchart has a logical start and end.
8. It is useful to test the validity of the flowchart by
passing through it with a simple test data.
Advantages of Flowchart
1. Communication
flowcharts are better way of communicating the logic
of a system to all concerned.
2. Effective analysis
with the help of flowchart, problem can be analyzed
in more effective way.
3. Proper documentation
flowcharts serve as a good program documentation.
Advantages of Flowchart
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.
Algorithms and Flowcharting
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.
Denotes an
Denotes an
A exit
entry A
Algorithms and Flowcharting
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.
Flowchart Symbols:
10. Preparation/Initialization Symbol
Most Commonly Used Symbol
Flowchart (Applications)
Sequential/Linear Flowchart
Sequential/Linear Flowchart
Sequential/Linear Flowchart
Sample Flowchart
Sample Flowchart
Sample Flowchart
Sample Flowchart
System Flowcharts
A system flowchart shows in general
terms the operations that will be
performed on information in an
information system. The arrows on a
system flowchart show the direction that
data will flow in around the system rather
than the order in which the operations will
be carried out.
System Flowchart Symbols
System Flowchart Example : Car Repair Garage
OTHER TYPES OF FLOWCHARTS

High-Level Flowchart
A high-level (also called first-level or top-down) flowchart shows the major steps in a process. It
illustrates a "birds-eye view" of a process, such as the example in the figure entitled High-Level
Flowchart of Prenatal Care. It can also include the intermediate outputs of each step (the product or
service produced), and the sub-steps involved. Such a flowchart offers a basic picture of the process
and identifies the changes taking place within the process. It is significantly useful for identifying
appropriate team members (those who are involved in the process) and for developing indicators for
monitoring the process because of its focus on intermediate outputs.
Most processes can be adequately portrayed in four or five boxes that represent the major steps or
activities of the process. In fact, it is a good idea to use only a few boxes, because doing so forces
one to consider the most important steps. Other steps are usually sub-steps of the more important
ones.
Detailed Flowchart

The detailed flowchart provides a detailed picture of a process by


mapping all of the steps and activities that occur in the process. This type
of flowchart indicates the steps or activities of a process and includes
such things as decision points, waiting periods, tasks that frequently must
be redone (rework), and feedback loops. This type of flowchart is useful
for examining areas of the process in detail and for looking for problems
or areas of inefficiency. For example, the Detailed Flowchart of Patient
Registration reveals the delays that result when the record clerk and
clinical officer are not available to assist clients.
Sample Problem

1. Make a flowchart that will input the length and width of a


rectangle. Output the perimeter.
2. Make a flowchart that will compute for the area of a circle
given a radius of 9 cm.
3. Make a flowchart that will ask the user to input the radius
of a circle. compute for the area of a circle and output it.
Sample Problem
4. Make a flowchart that will input 2 integers and will
output the sum, difference, product and qoutient of
the 2 integers.

5. A certain store sells softdrinks for P 6.00 and


sandwiches for P 6.50. Draw the flowchart to input
the number of softdrinks and sandwiches bought and
output the bill.
Sample Problem
A certain store sells softdrinks for P 6.00
5-1.
and sandwiches for P 6.50. Draw the flowchart
to input the number of softdrinks and
sandwiches bought and output the bill. Assume
that your program will ask the buyer to input
amount to pay. OUtput the change to given to
the buyer.
Sample Problem
6. Make a flowchart that will prompt the user to input the base
and the height of a triangle. Output the computed area of a
triangle.

7. Make a flowchart that will input a measurement in meters and


output the equivalent measurement in inches.

8.Make a flowchart that will input the area of a circle. Determine


the diameter of the circle.
Sample Problem

8.Make a flowchart and a C Program that will


input the area of a circle. Determine the
diameter of the circle.
Sample Problem
9. A salesman in XYZ company is selling toothpaste for
P89.75 each and tooth powder for P155.95 each. The
salesman will have a 10% commission on the sale of
toothpaste and 20% commission on tooth powder.
Draw a flowchart and a C Program to input the name of
the salesman, the number of toothpaste and tooth
powder he sells. Output the name of the salesman, the
total sale and the total commission he earned.
Sample Problem
10. Make a flowchart and a C Program that will
compute for the distance between 2 points A
and B. The user is asked to input the values of
points A(x1,y1) and B(x2,y2). Output the
following:
a] distance between the 2 points
b] slope of the line
Sample Problem
11.Max wants to borrow P50,500.00 in a bank to
put up a small business. The bank gives a rate of 9.5
percent for a 6 year period of time. Compute for the
interest that Max will pay after 6 years? Output the
computed interest. Draw the flowchart and make a
C Program.
Sample Problem
12. Make a flowchart to input a radius and will compute for
the area and volume of a sphere (surface). Output the
computed area and volume.

Area = 4 × pi × radius2
Volume= 3/4 × pi × radius3.
Sample Problem
13. Make a flowchart and a C program to input
2 integers. If the 1st integer is greater than the
nd
2 integer, compute the sum of the 2
integers, otherwise compute the product.
Output the sum or product of the 2 integers.
Sample Problem
13. Any customer whose total PURCHASE
is at least P1000 will be given a 10%
discount. Make a flowchart that would
input the customer’s PURCHASE and
output his net BILL.
Computer Programming 1

THE END
PART A

You might also like