0% found this document useful (0 votes)
5 views4 pages

Algorithms and Data Structures Guide

The document outlines a corrective proposal for an exam on algorithms and data structures, detailing definitions, syntax for algorithms, and quality criteria for good algorithms. It includes specific algorithms for calculating net amounts and individual rankings based on weight and height, as well as definitions for various data structures. Additionally, it describes functions for client solvency and procedures for managing order stacks.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Algorithms and Data Structures Guide

The document outlines a corrective proposal for an exam on algorithms and data structures, detailing definitions, syntax for algorithms, and quality criteria for good algorithms. It includes specific algorithms for calculating net amounts and individual rankings based on weight and height, as well as definitions for various data structures. Additionally, it describes functions for client solvency and procedures for managing order stacks.

Translated by

ScribdTranslations
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

BTS SESSION 2021

SPECIALITE/OPTION : GENIE LOGICIEL(GL)

CORRECTIVE PROPOSAL for the exam: ALGORITHMS AND DATA STRUCTURES

PART A: SYNTAX OF ALGORITHMS


A.1 Definition of terms:
Algorithm: a sequence of instructions to solve a problem
Function: it is a subprogram included in another one and that must return exactly one and only one.
solution.
Procedure: it is a sub-program included in another and can return one or more solutions

A.2 The quality criteria of a good algorithm are:


Readable: the algorithm must be understandable even by a non-computer scientist.
It always ends: the algorithm must have an end.
Precise and unambiguous: each element of the algorithm should not be misleading.
Concise: an algorithm should not exceed one page. If it does, the problem should be broken down into
several sub-problems.
Structured: an algorithm must consist of different easily identifiable parts.
Solve the problem.

A.3 Syntax for declaring an iterative structure

As long as (condition) do
REPEATER
<treatment>
Treatment
Fintantque
UNTIL <Condition>

FOR <CounterVariable> FROM <InitialValue> TO <FinalValue> STEP <Increment> DO


<Traitement>
FINPOUR

A.4 Syntax of a conditional structure of our choice

IF(<Condition>)THEN IF(<Condition>)THEN
Treatment 1
SINON Treatment
Treatment 2
FINISH FINISH

A.5 Syntax of a procedure


ProcedureName(Data /*input declarations*/ Data/Results
PROCEDURE
/* input/output declarations */ Results /* output declarations */ )
CONST //constant declarations
VAR // variable declarations
DEBUT

//instructions

FINPROC
A.6 Differences between procedure and function
Function Procedure
Return necessarily one and only one
May not return a result
result
His call is an expression His call is an instruction.
The name of the procedure has no connection with
The name of the function contains the result
a solution

Part B: ALGORITHM WRITING


B.1 Algorithm for calculating the net to be received
ALGORITHM CalculNet
VAR Sb, NbreArt, Np : INTEGER
Re: REEL
DEBUT
WRITE ("Enter the number of items sold");
READ (NumArt);
YES (NumberArt < 30) THEN
Re = 0;
ELSE IF (NbreArt == 30) THEN
Re = 0.2 ;
IF NOT
Re = 0.5 ;
FINISH
FINISH
Np = Sb * (1 + Re)
WRITE ("The net amount to be received is: ", Np);
END

B.2 Writing the individual ranking algorithm


ALGORITHM WeightRanking
VAR I, T, P : REAL
DEBUT
WRITE ("Enter the weight and height of the individual") ;
READ (P, T);
I = P/(T^2);
IF (I < 18.5) THEN
WRITE ("The individual is THIN") ;
SINON IF (I < 25) THEN
WRITE ('The individual is MEANS');
SINON
The individual is OVERWEIGHT
FINISH
FINISH
END
PART C: ADVANCED DATA STRUCTURES
C.1 Definition of the data structure
Assuming that the program provides for the advisable use of a file, we will have the
following structure:
TYPE Tclient = RECORD
Codeclt, nom, prenom : Chaine de caractère
State fund, such as: Whole
FINAL RECORDING

TYPE Tcommand = RECORD


Codecmd, date, Refpd : String
whole
FINAL RECORDING

TYPE Tproduct = RECORD


Refpd, nomproduit : Chaine de caractère
PU, qteEnStock : Entier
FINENREGISTREMENT

VAR Fproduct: File of Tproduct


Fcommand: Tcommand File
Fclient: Tclient File

C.2 Function for determining a client's solvency


FUNCTION balance (codeclt) : BOOLEAN
VAR Eclient : Tclient
DEBUT
ASSIGNER (Fclient ; "C:\[Link]") ;
OPEN (Fclient) For reading;
REPEAT
READ (Eclient; Fclient);
UNTIL [Link] OR [Link] = codeclt
IF [Link] = codeclt THEN
Solde = true // Return true
SINON
Solde = false // Return false
FINISH
FINFUNCTION

C.3 Definition of the data structure corresponding to the order stacks


Type
Lcommande = ^Tcommande
Tcommande = Enregistrement
Codecmd, the integer;
Date, Refpd: Chaine de caractère
Follow: ^Tcommand
End;
Pcommande = Enregistrement
Summit: Lcommand
End;
C.4
The primitive that allows adding an element to the stack is called PUSH an element
Writing the primitive for stacking
Procedure StackD (P : Pcommand);
Variable Pt: Lcommand;
Debut
Allocate (Pt)
WRITE ("Enter the order code");
Read (Pt^.codecmd);
WRITE ("Enter the order date");
Read (Pt^.date) ;
Enter the quantity of product purchased
Read (Pt^.qte);
WRITE ("Enter the product ordered");
Read (Pt^.Refpd);
Pt^. Follow P. Summit ;
P. Summit Pt ;
End

C.5 Writing a function to pop the order


Function EmpilerD (P : Pcommand);
Variable Pt : Lcommande ;
Debut
Pt P. Summit ;
X [Link]^.Info ;
WRITE ("the order code:", [Link]^.codecmd);
WRITE ("the order date:", [Link]^.date);
WRITE ("the quantity of product purchased: ", [Link]^.qte);
WRITE ("the ordered product :", [Link]^.Refpd);
P. Summit P. Summit^.Follow ;
Free
End

You might also like