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

University of Science and Technology Houari Boumediene Faculty of Computer Science Algorithmics and Data Structures Ingenieur - Info

The document outlines two exercises related to records in programming. The first exercise involves creating and manipulating records for cities, including calculating distances and displaying population sizes. The second exercise focuses on forest fire statistics in Algeria, requiring the creation of records for forest fires and an algorithm to count fires in Algiers from 2010 to 2020.

Uploaded by

tarekkara001
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)
6 views4 pages

University of Science and Technology Houari Boumediene Faculty of Computer Science Algorithmics and Data Structures Ingenieur - Info

The document outlines two exercises related to records in programming. The first exercise involves creating and manipulating records for cities, including calculating distances and displaying population sizes. The second exercise focuses on forest fire statistics in Algeria, requiring the creation of records for forest fires and an algorithm to count fires in Algiers from 2010 to 2020.

Uploaded by

tarekkara001
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
You are on page 1/ 4

University of Science and Technology Houari Boumediene

Faculty of computer science


Algorithmics and Data Structures INGENIEUR.INFO: 2023/2024

TD N° 3: Records

Exercise 1 :
Consider the following records:
Type
TPoint = Record
x,y: integer;
End;
TSpace = Record
Position: Tpoint;
Area, Altitude: integer;
End ;
TVille = Record
InfoG: TSpace;
Name: string[25];
PopSize: integer; //population size
End;

Let T be an array of N Cities (N≤100). Write an algorithm allowing:


a- Fill the array T.
b- Display the distance between two cities A and B.
c- Show the population size of the highest city.
d- Show the geographical position of the largest city.

Algorithm Exo1;
Var
TPoint = record x,y : Integer ; End;
TSpace= record Position : Tpoint ; Area, Altitude :integer ; End ;
TCity = record
InfoG : TSpace;
Name :String[25] ;
PopSize :Integer ;
End;

T : Array[100] of TCity ;
N,i : integer ;
V1, V2 : String ;
P1, P2 : integer ;
Correct : boolean ;

Begin
Repeat
Write ( “ How many cities ? “ ) ; Read (n) ;
Until (n > 0 and n <=100) ;

// filling the vector


For i ← 1 to n do
Read (T[i].InfoG.Position.x) ;
Read (T[i].InfoG.Position.y) ;
Read (T[i].InfoG.Altitude) ;
Read (T[i].InfoG.Area ) ;
Read (T[i].Name) ;
Read (T[i].PopSize) ;
Done ;

// Distance between two cities


Correct ← false ;
Repeat
Write ( “Give us the name of the 1st city “ ) ; Read (V1) ;
Write ( “Give us the name of the 2nd city “ ) ; Read (V2) ;
P1 ← 0 ;
P2 ← 0 ;
i←1;
While (P1 = 0 and i <= n) do
IF (T[i].name = V1) Then P1 ← i ; endIF ;
i←i+1;
Done ;
i←1;
While (P2 = 0 and i <= n) do
IF (T[i].name = V2) then P2 ← i ; endIF ;
i←i+1;
Done ;

IF (P1 <> 0 and P2 <> 0)


Then Correct ← True ;
D ←sqrt( ( (T[P1].InfoG.Position.x - T[P2].InfoG.Position.x) * (T[P1].InfoG.Position.x
- T[P2].InfoG.Position.x) ) + (T[P1].InfoG.Position.y - T[P2].InfoG.Position.y) *
(T[P1].InfoG.Position.y - T[P2].InfoG.Position.y) ) )
Write (“Distance(V1, V2) = “, D) ;
EndIF ;
Until (Correct =True ) ;

//Display PopSize of the highest city)


AltMax ←0 ;
indexV ←0 ;
For i ← 1 to N Do
IF T[i].InfoG.Altitude > AltMax
Then AltMax ← T|i].InfoG.Altitude ;
indexV ← i ;
EndIF ;
Done ;
Write(“There is “, T[indexV].PopSize ,” residents in the highest city. “) ;

// Display the position of the widest city


AreaMax ←0 ;
indexV ←0 ;
For i ← 1 to N Do
IF T[i].InfoG.Area > AreaMax
Then AreaMax ← T|i].InfoG.Area ;
indexV ← i ;
EndIF ;
Done ;
Write(“The widest city is positioned at ( “,
T[indexV].InfoG.Position.x , “ , “ , T[indexV].InfoG.Position.y , “ ). “ ) ;
End.

Exercise 2 :
We are interested in statistics related to forest fires in Algeria. Let T be an array of N Forest
fires (N≤100). Each TFire forest fire is characterized by a geographical position PG (x, y), a
wilaya Wilaya, a burned Area (in hectares), a start date DateStart and an end date
DateEnd. These dates are made up of Hour, Day, Month, and Year.

1- Give all the necessary records to describe a Forest Fire.

2- Write an algorithm allowing you to:


- Fill the array T.
- Display the number of fires in the wilaya of “Algiers” per year between [2010 - 2020].

Type TPositionG = Record


x, y : real;
End;

TDate = Record
Hour, Day, Month, Year : integer;
End;

TFire = Record
PG : TPositionG;
Wilaya : String ;
Area : real ;
DateStart, DateEnd : TDate ;
End ;

Algorithm exo2 ;
//put the type declaration here.
Var
i, N, nbrFire : integer;
T : Array [100] of TFire ;
Begin
Write(“How many forest fire do me have ?”);
Repeat Read(N); Until (N>0) and (N<=100);

//Filling the array T


For i ← 1 to N Do
With T[i] Do
Read(Wilaya); Read(PG.x , PG.y); Read(Area);
With DateStart Do Read(Hour, Day, Month, Year); Done ;
With DateEnd Do Read(Hour, Day, Month, Year); Done ;
Done;
Done;

//Display the number of fires


For i ← 2010 to 2020 Do
nbrFire ← 0;
For i ← 1 to N Do
IF (T[i].Wilaya = “Algiers” And T[i].DateStart.Year = i)
Then nbrFire ← nbrFire + 1 ;
EndIF ;
Done ;

Write(“Year ”, i , “ Fires Number = ” , nbrFire , “\n”);


Done ;

End.

You might also like