/
THE AUTOMATED FLOWCHART DESIGN AND CODE WRITING SYSTEM |
Home || Contact us || Create code logic || Login xxxxx |
What is a Computer Program Problem? |
COMPUTER PROGRAMMING AND PROGRAM PROBLEM SOLUTIONI have listed some sample program problem and their algorithmic solution illustrated with flowchart. I also have the source code that is generated from these flowchart by LogicCoder. The information here is available in pdf format along with actual flowchart files that you can use with LogicCoder. |
WHAT IS A COMPUTER? |
||
A computer is any device or machine which operation can be ordered under the control of a program to solve a specific problem. There are many different kinds of computing devices to be found at various points in human civilisation and more recently, during the industrial revolution. By a computer program we mean the configuration of a device or machine that affects the way the device or machine operates or behaves under the influence of some input energy source. Therefore, there are permanently programmed systems such as those found in industrial machines and there are re-programmable devices most of which are electronic systems. I have given broad definitions to the terms "Computer" and "Computer Program" in preceding paragraph. However, in this manual we confine our interest to digital computer systems that operates on the principle of the stored program concept. Therefore, a more concise definition of a Computer Program is as follows. |
||
|
Definition
|
Illustration
|
Classification |
|
A consise definition of a computer is as follows: |
/ |
Modern Electronic Computer systems
can be classified in terms of (a) Type (b) Size (c) Generation |
| Click the following link to purchase books with the above and following information with more deatiled explanation. | ||
DIGITAL COMPUTERS AND THE STORED PROGRAM CONCEPT |
||
| Digital computers operates on the principles of the binary number system and are therefore controled by digital signals. An example digital signal is illustrated in figure 1-3. Here are some of the basic elements that constitute a micro-computer system | ||
|
A microcomputer system is made out of three basic functional
elements: Each component of a microcomputer system can in turn
be broken down into smaller sub-system components. For example, the CPU
(or microprocessor) consists of the following sub-system components: |
STRUCTURE OF A MICROCOMPUTER SYSTEM
![]() |
|
|
WHAT IS DATA?
|
An Example Digital Signal
|
|
|
The operations performed by a computer require data. Data values are represented as digital signals like that illustrated in figure 1-3. Data is the representation of facts, concepts, or instructions in a structured and logical manner suitable for processing, communication, and interpretation by humans or some programmed device. Examples of data are: The balance of a bank account, The score a student receive on a test, or The list of all male students doing a particular subject at a college. The purpose of a computer is to accept and process data to produce useful information for human use. In the context of a digital computer system, we define data as Information in a form that can be used by a computer program. |
![]() |
|
|
The numeric characters "1" and "0" are used to represent numbers in the Binary Number system. We use the shotened expression "Bit" when refering to these numeric digits in base 2. The Binary number system uses the principle of place value positions to represent numeric values. |
||
|
The place value of each bit position in a seven bit binary number, starting at your right and moving to the left are as illustrated by the example in figure 9-36. Each character on a standard computer keyboard is encoded in a binary system so that the digital compputer can use the information that it represents in a logical and consistent manner. For example, the character "1" has a ASCII coded value assigned to it in this system of coding. The coded value has a decimal equivalent as illustrated here. |
![]() |
|
| The decimal equivalent for the ASCII code for 1 is calculated as follows: |
![]() |
|
|
Therefore, we see that the signal represented in figure 1-3 could be that of the ASCII code for a keyboard character. It could even be that of a coded machine instruction been transmiited through the system or it could be the representation of some othere data format been used by a program. |
||
WHAT IS A COMPUTER PROGRAM? |
||
|
The "Stored Programming Concept" requires that both th data values and the instructions that controls operations on them during the run of a program to be represented in a digital format and be stored in the Internal memory of the computer system. |
||
WHAT IS A PROGRAMMING LANGUAGE? |
||
On a digital computer, programs at machine level consist of a series of binary words that are directly interpreted by the central processing unit (CPU). These specific sequences of instructions are designed to solve a particular problem on a selected device. Programming is the process of selecting the correct sequence of machine instructions to be used for solving a specific problem. The binary coded instructions used on a selected electronic device (computer system) are determine by the electronic configuration of the device. However, there are fundamental concepts and principles that govern the way programs are written and how they are executed. Writing machine programs require that you have knowledge of the electronic configuration of the machine. In addition, a program written for a given machine is not portable to other machines. Therefore, writing machine programs is best left to people who like to do things using 1's and 0's. The example below illustrates a machine level computer program. |
||
| Not many people will want to write programs for themselves using machine language. Therefore, manufacturers of microprocessors invented Assembly Language so that more users will purchase their product and at the same time "copy cat" users will have more problems trying to figure out the detail structure of their product. |
Table 1-1. An example Machine/Assembly language program.
|
|
![]() |
||
|
Assembly language is machine language written using mnemonics. A mnemonic is a word or combination of letters that suggest the meaning of the instruction it represents. Like BASIC, an assembly language consists of a set of commands that can be written into instructions that tells the computer what to do. However, each mnemonic word in an Assembly Language instruction set refers directly to the digital components of the computer system. Therefore, we see that Assembly Language mainly provides a convenient abstraction of the binary interpretation of a particular machine instruction set and the representation of data values on the system. Assembly Language does not adequately abstract the structure of a system. From this we see that a programming language forms an interface between the programmer and the hardware system of the computer. There are levels of abstraction between the hardware system and the programming language. These abstractions are logical and are built on consistent rules that manifest themselves at the software interface as syntax and semantic rules in particular programming languages. Good programmers have a comprehensive knowledge of the way digital computer systems works and is able to appreciate the syntax and semantic rules in well defined programming languages. Understanding of a computer system includes basic knowledge of the way the hardware system works at machine or assembly language level. Click the following link to purchase books with the above and following information with more deatiled explanation. Click HERE More information about these books can be found at this link. |
HIGH LEVEL PROGRAMMING LANGUAGES |
||
|
Therefore, we had to invent a system whereby a person who is not an expert at this level can program such a digital device that will solve a problem for the programmere with the solution approach been in the programmer's problem domain as opposed to that of the implementation machine domain. In a high level programming language instructions are written using statements
and expressions similar to those used in every day natural languages.
Instructions written in a low-level language are written using machine
code or mnemonics. Low level languages are machine oriented. Because of
the limitation of low level programming languages, high level languages
were developed. High level languages are: |
||
A SYSTEMATIC APPROACH TO PROGRAMMING |
||
|
Click the following link to get more information about the systematic approach to programming and the Program Development Life Cycle. Click HERE |
||
WHY USE PROGRAM FLOWCHARTS? |
||
|
This section gives a concise introduction to the concepts and principles of flowcharting as a means for illustrating program algorithms to be executed on digital computer systems. This on-line documentation is not intended to be a detailed practical guide. Reference sources that gives more practical learning material including programming language concepts and design techniques are given at the link to additional learning resources. I will give you a link that gives you some experimental results from students learning programming with a visual design system as opposed to purely using a text base programming language. The difference with UML is that it is base on high level concepts that are not well defined and does not deal with issues that have been bugging software engineers and computer programming for a long time now. Typical issues UML fail to deal with are the issue of Complexity, Maintainability and Re-usability. LogicCoder effectively deals with these issues by developing a standard for the design of program algorithms with the use of program flowchart. These are simple straight forward easy to understand principles. They are not targetted at the highly academic but they can be used by the highly creative person to build sound, large, complex and consistent systems. Visual programming system that autoamates a lot of programming task for the development of compplex software systems is evolving and is becoming predominant choice in all areas of program/software development. |
||
SAMPLE PROGRAM PROBLEMS AND THEIR SOLUTION FLOWCHART |
||
| In the follwoing set of sample program problems and their solution, I illustrate the use of an automated code writing system, namely LogicCoder for the integration of problem solution design, system documentation, system coding and maintenance with the use of a single user document interface. | ||
|
Problem specification
|
The Problem Flowchart Solution
|
|
|
The sample program used in this chapter prepares a report on a checking account. The report is an output listing of checks drawn on a personal account in the month of September. Each line of the report list information on each check drawn during the month as follows. The amount drawn on each check, the check number, the check date and the person to whom the check is made payable. At the end of the report listing, the total number of checks and the total amount drawn on all checks for the month are printed on the output report.
|
![]() |
|
|
ANSI C source code generated by LogicCoder
|
||
| With LogicCoder, you can quickly and easily modify the control logic so that each record in the program is included as part of an internal data list. In addition, you can change the Input/Output symbols that "Read a Record" to appropriate Processing symbol so that the system implement the control loop as a for-next loop. You can also put these symbols into the Ignore state and then put an appropriate control for statement in the loop decission. |
void main(void) |
ANOTHER PROGRAM SPECIFICATION |
||
|
Click the following link to download a sample free tutorial copy of LogicCoder with the source code text file for the following flowchart. Download is a zipfile for Ms Windows. Click to dowwnload. When you have installed LogicCoder, load the flowchart below and then the source code text file. You can then generate the required C/C++ program. You can then do modifications to the flowchart to create other programs with similar control logic. |
||
|
Problem Specification
|
Problem Flowchart Solution
|
|
|
A mileage report for sales people is to be prepared. The input test data is listed below. Each report line should contain the sales person's name, the beginning mileage, the ending mileage, the total mileage done (ending mileage - beginning mileage), and the mileage allowance. The mileage allowance is calculated by multiplying the total mileage by 0.20. The total number of sales persons, the total mileage done by all sales persons, and the total mileage allowance for all sales persons is to be printed at the end of the listing. The output listing should contain report and column headings
|
![]() |
|
|
A sample copy of input test data is given in the table below. The input test data is to be included as part of the source code. |
||
|
INPUT TEST DATA
|
||
|
SALES PERSON NAME
|
BEGINNING MILEAGE
|
ENDING MILEAGE
|
| HARRIET HILL EUGENE JACKSON HARVEY MUMM JULIE SIMPSON |
13505
26482 32598 15444 |
13607
27101 32690 16748 |
ANOTHER PROGRAM SPECIFICATION |
||
|
Our next sample program problem illustrate the basic elements in the control logic of the of the Case structure and its implementation within the loop logic structure.You can also have control logic for a loop nested on either legs of the Case logic structure. The case structure can also have multiple instructions on either or both path that is given control after the decision instruction is executed. Figure 4-3 illustrates an example of this. |
||
|
Problem Specification
|
Problem Flowchart Solution
|
|
|
A traffic citation report is to be prepared. You are required to design and code a program that will produce the report. INPUT DATA FILE The input test data file consists of records. Each record contain the name of the person receiving the traffic citation, a code that indicate whether the citation is for moving (code M) or for non-moving (code N) violation, and the number of citation for that person over the pass three years. The input test data is given in the table below.
|
![]() |
|
| Each line on the output report list the name of the person receiving the traffic citation, a fine of 30.00 for moving violation or 10.00 for non-moving violation, a penalty of 20.00 if the number of violation is more than 3 and no penalty if the number of violation is less than or equal to 3. Each line on the report should also list the total fine due (fine + penalty). The total number of tickets, the total moving violation, the total non-moving violations, the total fines, the total penalties, and the total amount due are to be printed at the end of processing all records. The format for the output report is illustrated below. |
INPUT TEST DATA
|
||
|
NAME
|
TYPE OF VIOLATION | NUMBER OF VIOLATION | |
|
JUNIOR HAINES
TOM JULION JUNE RHODES DALE SMEARS EVERET MILLS |
N
N M N N |
2 6 4 1 5 |
|
|
Click the following link to get sample download of LogicCoder flowchart files. Here is another sample program problem in which an algorithm is required that scan through a data file consisting of records in order to determine the largest and the smallest in a selected fild. In this case, the program problem is specific as you can determine from the specification given. However, the problem belong to a class of well known or common problem. Therefore, a generalise or generic algorithm would be useful for impleenting a solution. If you were to use LogicCoder to derive a solution to this problem, you could use this single solution to generate the required generic algorithm. In LogicCoder, we call a flowchart that represent a generic algorithm a "Template flowchart". You can use a template flowchart to quickly implement the solution to any problem that belong to the class of problems represented by the generic algorithm. |
||
|
Problem Specification
|
Problem Flowchart Solution
|
|
|
A program is to be designed and then coded in BASIC that will produce a wheat production listing. Each input record used in the data file contain the field number from which the wheat is harvested, and the tonnage of wheat produced. The following information should be listed at the end of the report: The total tonnage of wheat produced from all fields, The field number and tonnage of the field that produce the most wheat, The field number and tonnage of the field that produce the least wheat. The input test data is given below.
|
![]() |
|
|
INPUT TEST DATA
|
|
|
FIELD NUMBER
|
TONNAGE OF WHEAT
|
|
65-009
65-010 67-221 67-348 68-110 |
328
458 201 595 455 |
|
Notice from this program logic design that you are basically selecting
the maximum and the minimum values from a set of values. Therefore, the
instance of this program algorithm implement the solution of a more general
problem, i.e. selection of the maximum and the minimum from a set of values.
This gives us the opportunity to create what we call a "GENERIC SOLUTION"
for this class of problems. LogicCoder allow you to create generic solutions
to class of programming problems by creating a "Template flowchart" from a given instance within that class of problems. You can then use
the template flowchart to implement a solution to any problem within the
class of problems. You can also creat template flowchart base solely on
a visual perception in the control logic presented in a flowchart. Therefore,
you can have template for class of problems that has similar processing
pattern requirement. |
||
ANOTHER SAMPLE PROGRAM SPECIFICATION |
||
| The sample program in this chapter is to prepare a park camping fee report. The logic to be used by the sample program consists of a loop with a nested case structure. This nested case structure determines alternative ways for calculating campers' fees base on three tested conditions. The report created by the program contains report and column headings. Each line of the report list the camper's Name, the camper's Residency, the number of Days the camper is staying and the camping Fee. The camping fee is determined as follows. If the camper is a resident, the cost for the first seven days is 7.95 per day, after which the fee is calculated at 5.95 per day for the days in excess of 7. If the camper is a non-resident, the fee is calculated at 9.95 for the full camping period. If there is an error in the residency code field of the camper's record, i.e. this field neither contain a "R" (resident) or a "N" (non-resident), then the value; "UNKNOWN" is to be printed in the residency column on the output report. The input data file and a sample of the output report is given in figure 5-12. | ||
|
The Program Flowchart
|
||
|
With LogicCoder, you can easily transfer the implementation of your program logic design from a given source language to another with very little effort. You do this by paying more attention to the control logic of your program and the meaning of command statements in the source language. No more need for "hang-ups" on programming lnguage paradigms.
|
![]() |
|
|
OUTPUT SPECIFICATION
|
|||
|
The output consist of an edited report that list the values in the input data file as illustrated below in the sample output. You can also use LogicCoder to enter a list of data values to be used in a program for testing the program. For intance, if you eneter the list of data values below, LogicCoder will insert them for you at the end of the source ocde with line numbers and string values properly delimited.
|
|||
|
Sample Code Generated by LogicCoder in BASIC
500 REM ****** PROCESSING ****** |
|||
|
More advance versions of LogicCoder allow you to select to generate BASIC programs with the use of standard control structures as opposed to that that uses the traditional line numbering as illustrated here. Many high level programming languages implement these standard control structures with the use of standard control statements such as do-while, while, if, if-then and so on. Never the less, as we have seen, with LogicCoder there is no need to think about these control staements when writing the source code for a program. Click the following link to download a copy of this flowchart and the C/C++ source code text file. |
||
ANOTHER PROGRAM SPECIFICATION |
||
You are to design a program and then write the source code. The program is to encode the sorted sequence for a set of data values from two pre-sorted lists that are to be merged in-place. In addition, the permutation sequence should encode the order in which values are to be selected from the two list been merged in a stable manner. |
||
|
BACKGROUND INFORMATION
|
|||
| A merge or sort algorithm is said to be in-place whenever it does merging or sorting with the use of constant amount of extra memory. In this case, the amount of memory required to implement the algorithm does not depend on the number of records in the input list(s). In addition, a merge algorithm is stable if it always leave sequences of equal data values in the same order at the end of merging. For example, if we have the set of indexed values in the A list and the B list as follows. |
|
![]() |
|
|
If the merge algorithm is such that it keeps the indices of a sequence of equal values from a given list in sorted order. I.e. they are kept in the same order as they were before the merge as illustrated in the output example for the above input, the algorithm is said to be stable. Otherwise, the algorithm is said to be unstable. Output when the merge operation is stable is as illustrated by C in figure 3-15. The encoding algorithm should encode the sequence in which the values in C are selected as follows: 10011100110100. Note that, the merge operation that produces the output list C selects values from A in preference to that from B whenever a tie occurs. We define stability in the general sense to mean that values from A are always given preference whenever a tie occurs between values in A and B and that the indices of equal set of values are kept in sorted order at the end of the merge operation. |
|||
|
INPUT TEST DATA
|
||
| The input test data to be used in the program consist of two pre-sorted lists, each consist of a set of integer values listed below. |
![]() |
|
|
During the merge if there is a tie between a value from the A list and the B list, the value from the A list is given preference to that from the B list. |
||
|
OUTPUT
|
||
| Output from the encoding operation should be a bit-pattern stored in a variable name of the appropriate type. This bit pattern encodes the sequence in which values are to be selected from A and B to create a stable merge. During the merge operation, we use a 1 to encode a value selected from the A list and a 0 to encode a value selected from the B list. We count bit position in the encoded data starting with the LSB. For example, to stable merge the two pre-sorted sequence A and B in figure 3-15, we create the new output list C by selecting values in A and B as explained above. Therefore, the output C would be encoded by the following bit pattern: 111110010011100100110000 | ||
|
THE PROGRAM LOGIC DESIGN
|
||
|
The overall control logic to be used in the program design is relatively simple and straightforward as illustrated by the flowchart in figure 3-16. However there is a need for the use of several bit-manipulating functions in order to meet the overall program objective. For the purpose of doing a visual checks on the results of our program, we define a function that will print the bit pattern for a value stored as an unsigned long int. We call this function Print_bits( ). In this function we select each bit in the value to be printed by shifting it to the LSB position and then masking out the remaining bits. This function is defined in the source code of figure 3-17. |
![]() |
|
|
THE OUTPUT SOURCE PROGRAM
|
|||
|
Figure 3-20 Further information on this program problem is found in the text book "STRUCTURED PROGRAMMING WITH ANSI C" Page 15 - 17 |
|
void main(void) |
|
|
Most information listed on this web page are taken from the following
text books |
|||
Copy right © May 2002
Logic Code Generator
London
United Kingdom
Tel: +44(0)794
EMail: info@logiccoder.com