THE AUTOMATED FLOWCHART DESIGN AND CODE WRITING SYSTEM

Home || Contact us || Create code logic ||

LogicCoder Online Tutorial 3 of 7-EXAMPLE PROGRAM PROBLEM
> About LogicCoder
> What LogicCoder does?
> Sample screen-shots
> Online tutorial
>> Program flowcharts
>> Understanding the rules
>> Example program solution
.>> Introduction to LogicCoder
>> Building a flowchart
>> Editing and coding
>> Abstracting complex logic
> Computer programs
> Program flowcharts
> About LogicExtractor
> Code from flowchart

 

EXAMPLE PROGRAM PROBLEM SOLUTIONS

A Program Problem methodology consist of a standard approach for arriving at the solution to a program problem. The standard methodology for program problem and Software Systems solution consist of those steps listed below. There are also other standard methods for approaching the solution to computer programming problems. However, these are base on underlying principles which are not well stated in the literature. For example, to use a RAD approach to the solution of a problem, the intended target system must have existing reusable software systems with highly modular components which are flexible and easy to integrate into new systems or which can be easily changed. The system must also have interfaces that are common to its own internal components and to external ones.

LogicCoder is a system that lets you easily focus your attention on the essential characteristics of a software system using the Object Oriented appraoch, to make your system more usable for RAD and so on.

In this Tutorial you will learn about (1) The Systematic Approach to Program development (2) Phases in the Program development Cycle, (3) What a program problem specification is and how the program problem solution relates to the program specification. (4) Relationship between the implementation code in ANSI C++ and BASIC of example Loop and Case structures. (5) the actual use of ISO standard flowchart symbols in the flowchart that describes a program problem solution. (6) the various capabilities of LogicCoder in the design of program logic solution and the related automated code generating system. (7) . (8) .Use this link to convert your source code to LogicCoder and Ms Excel flowchart.


A STRUCTURED APPROACH TO PROGRAMMING

LogicCoder supports a structured approach to the development of software systems. LogicCoder makes it easier for developers to document and maintain their software systems with less uncertainty, more consistency and greater control over the management of changes. Hence, both design and program maintenance are made easier. Correctness of a program can more easily be aligned with its algorithmic description. Structured programming languages generally emphasise the use of well-established control statements that implement well-established control structures. The layouts of program code in these languages emphasise and make it easy to deduce these control structures. This helps to enhance the readability of the program logic and the maintainability of the program code. Logic Coder generates code in conformity to these basic principles. However, you no longer needs to pay attention to these details when developing software systems

THE PROGRAM DEVELOPMENT CYCLE

The Program Development Cycle is the well-established standard approach towards the development of professional maintainable software systems. Because of the precise nature of the sequence and kind of instructions involved in the solution to a programming problem, it is important that the programmer approach the solution to a programming problem in a systematic and discipline manner. This systematic approach is called the program development life cycle. The program development life cycle consist of the following stages:

1. Review of program specification
2. Program design
3. Program coding
4. Program testing and debugging
5. Program documentation

REVIEW OF THE PROGRAM SPECIFICATION

The solution to a programming problem begins with a clear description of the problem to be solved. This includes the following:

  • The format and type of input data,
  • Processing to be done on the input data,
  • Format of the output created from the processed data.

A clear understanding of the program specification should be the basis for the programming problem solution. At this point, the programmer should have no doubt as to the format of the input data, the processing to be done to them and the format of the output from the program.

THE PROGRAM DESIGN

Correct programming is base on a scientific principle. The design of the program logic is in keeping with the set of program specification derived from the program review. The programmer must have knowledge and understanding as to how a given objective in the program specification can be implemented on a computer system.

THE PROGRAM CODING

The programmer uses the flowchart to code the program logic in an appropriate programming Language The descriptive statements used by the programmer in the flowchart in most case will be influence by the programming Language to be used for implementation of the programming solution. If the program logic is well designed, the programmer should be able to code the program in any programming Language and still obtain the correct results. Therefore, good algorithmic description in a program flowchart is essential to good documentation, maintainability and portability of their implementation. Coding a program is an exact skill that the programmer must develop by paying careful attention to detail and the precise use of the syntax of a programming Language.

THE IMPORTANCE OF PROGRAM REVIEW

It is possible that a programmer from time to time will make errors in the logic design of a programming problem solution or in the syntax use of a programming Language Therefore, it is important that other programmers review a program before it is entered into the computer system. The program review is best done by people other than the programmer. A program review is not an exercise to critiqued a program, but an opportunity for classmate, or quality control people to benefit as a result of the following:

  1. A reviewed program should contain no error and will produce the correct result when it is run on the computer system.
  2. The programmer will spend less time and frustration in the process of testing and correcting the program.
  3. The person reviewing the program will benefit by seeing alternative approach to solving a problem. In the case where errors are discovered, the reviewer will avoid committing similar errors in their own program.

COMPUTER PROGRAM PROBLEM SOLUTION

SAMPLE PROGRAM PROBLEMS AND THEIR SOLUTION FLOWCHART

In the following 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.

 

 

 

 

Sample program logic design
   
 
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 decision xx void main(void) {
xxxxx r = 0; TotalChecks = 0;TotalAmount = 0;
xxxxx printf("\n\nChecking Account report\t Date: %s", __DATE__);
xxxxx scanf("%s,%f,%s",FileRec[r].Name, &FileRec[r].Amount, FileRec[r].Payee);
xxxxx while(strcmp(NAME, "END OF FILE")) {
xxxxx TotalChecks++;
xxxxx TotalAmount += CheckFile[r].Amount;
xxxxx printf("\n\t%s\t%.2f\t%s", FileRec[r].Name, FileRec[r].Amount, FileRec[r].Payee);
xxxxx scanf("%s,%f,%s",FileRec[r].Name, &FileRec[r].Amount, FileRec[r].Payee);
xxxxx }
xxx printf("\n\n\tTotal number of checks %d", Totalchecks);
xxx printf("\nTotalAmount of all checks: %s", TotalAmount);
xxx }

 

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 HERE to down load. 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.

 

 

 

 

 

Flowchart for Mileage report

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. The following example 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.

 

 

 

 

 

 

 

 

 

Program logic flowchart


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. Click HERE to download.

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 field. 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 implementing 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.

 

 

 

 

 

 

 

 

 

Program logic to select maximum and minimum

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 create 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 the following diagram.

.

Problem Specification Problem Flowchart Solution

 

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 Language 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 instance, if you enter the list of data values below, LogicCoder will insert them for you at the end of the source code with line numbers and string values properly delimited.


  BASIC Code generated by LogicCoder
Sample Code Generated by LogicCoder in BASIC

500 REM ****** PROCESSING ******
510 REM
520 PRINT TAB(11) "DESERT PARK"
530 PRINT " "
540 PRINT " NAME RESIDENCY DAYS FEES "
550 PRINT " "
560 REM
570 READ N$, C$, D
580 REM
590 IF N$ = "END OF FILE" THEN 850
600 IF C$ = "R" THEN 700
610 IF C$ = "N" THEN 650
620 PRINT USING F1$; N$, U$
630 GOTO 810
640 REM
650 LET A = D * C3
660 LET T2 = T2 + A
670 PRINT USING F1$; N$, O$, D, A
680 GOTO 800
690 REM
700 IF D > D1 THEN 740
710 LET A = D * C1
720 GOTO 770
730 REM
740 LET A = (D1*C1) + ((D-D1)*C2)
750 GOTO 770
760 REM
770 LET T2 = T2 + A
780 PRINT USING F1$; N$, R$, D, A
790 GOTO 810
800 REM
810 LET T1 = T1 + 1
820 READ N$, C$, D
830 GOTO 590
840 REM
850 PRINT " "
860 PRINT USING F2$; T1
870 PRINT USING F3$; T2
880 END

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 statements 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.

Copy right © May 2002
Logic Code Generator

73A Oldfield Road
Harlseden
London NW10 9UT
United Kingdom

Tel: +44(0)208 541 5097
Select a version of Logic Coder for purchase.