0% found this document useful (0 votes)
15 views9 pages

Corrected Exercise - Algorithm + Python

This document describes an exercise aimed at managing project management for a web development company using a software program. The program must allow the input of multiple projects, display the fields of projects with fewer than 22 employees, and display the names of project managers who worked on a project in 2020.
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)
15 views9 pages

Corrected Exercise - Algorithm + Python

This document describes an exercise aimed at managing project management for a web development company using a software program. The program must allow the input of multiple projects, display the fields of projects with fewer than 22 employees, and display the names of project managers who worked on a project in 2020.
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

Computational thinking and programming

Exercise 4:
A web development company aims to computerize the management of its projects, each project
is characterized by:
Creation Date: composed of 3 numeric fields:
Day: whole
Month: whole
Year: integer
Domain: chain of up to 15 characters
Number of employees: who are working on this project
Project manager: composed of 2 fields:
Name: chain of up to 15 characters
Phone number: string of 8 digits
The application must allow:
The entry of n projects (2 ≤ n ≤ 10).
Displaying the domains of projects with fewer than 22 employees.
The display of the names of project managers who completed a project in the year 2020.
Write a program that performs these different processes in the order mentioned in
the statement.

Teacher: AHMED BELHASSEN 1


Computational thinking and programming

Solution :
Algorithm of the main program:
Algorithm projects
Start
n enter_size()
fill_table (t,n)
Write("The fields of the projects where the number of employees is less than 22:")
display_domains(t,n)
Write("The names of project managers who managed a project in the year 2020:")
display_project_leader (t,n)
End
Table of declaration of new types
Types

Recording
day : whole
month : whole
year
End

Recording
name: string
string
End

Recording
date
domain: string
number_of_employees: integer
project manager
End
Tab = table of 10 projects

Teacher: AHMED BELHASSEN 2


Computational thinking and programming

Global Objects Declaration Table (GODT)


Subject Type/Nature
Entire
t Tab
enter_size Function
fill_table Procedure
display_domains Procedure
show_project_manager Procedure

Algorithm of the function enter_size:


function input_size() : integer
Start
Repeat
Write("Give the number of projects (>= 2 and <= 10): ")
Read(x)
Until (x >= 2) and (x <= 10)
Return
The End
Local Objects Declaration Table (TDOL)
Subject Type/Nature
x Whole

Algorithm of the procedure fill_array:


Procedure fill_table (@ ta : Tab, x : integer)
Start
Pour it down to make
Write("**** Project num", i+1 , "****")
Write("Creation date:")
Write("Day : ")
Read(ta [i].creation_date.day)
Write("Month : ")
Read(ta [i].creation_date.month)
Write("Year: ")
Read(ta [i].creation_date.year)
Repeat
Write("Domain: ")
Read(ta [i].domain)
Until (check (your [i].domain)) and (length(your [i].name) <= 15)

Teacher: AHMED BELHASSEN 3


Computational thinking and programming

Write("Number of employees: ")


Read(ta [i].number_of_employees)
Repeat
Write("Name: ")
Read(ta [i].project_lead.name)
Until (check (your [i].project_leader.name)) and (length(your [i].project_leader.name) <= 15)

Repeat
Write("Phone number: ")
Read(ta [i].project_leader.phone_number)
Until (isnum(ta [i].project_leader.phone_number)) and (length(ta [i].project_leader.phone_number) = 8)

End for
End
Local Objects Declaration Table (TDOL)
Subject Type/Nature
i Whole
check Function

Algorithm of the verify function:


Function check (ch: string) : boolean
Start
If(long(ch) > 0)then
For a long time (ch)-1 to do
If(((ch [i] < "A") or (ch [i] > "Z")) and ((ch [i] < "a") or (ch [i] > "z"))) and (ch [i] ≠ " ") then
Return False
End if
End for
Return True
Otherwise
Return False
End if
End
Local Object Declaration Table (TDOL)
Subject Type/Nature
i Whole

Teacher: AHMED BELHASSEN 4


Computational thinking and programming

Algorithm of the procedure display_domains:


Procedure show_domains (ta: Tab, x: integer)
Beginning
Pouride0àx-1faire
If (ta [i].number_of_employees < 22) then
Write(ta [i].domain)
End if
End for
End
Local Objects Declaration Table (TDOL)
Subject Type/Nature
i Whole

Algorithm of the procedure display_project_leader:


Procedure display_project_leader (ta: Tab, x: integer)
Start
To do
If (ta [i].creation_date.year = 2020) then
Write(ta [i].project_leader.name)
Well then

End for
End
Local Objects Declaration Table (TDOL)
Subject Type/Nature
i Whole

Teacher: AHMED BELHASSEN 5


Computational thinking and programming

Program in python:
Dictionary version:
from numpy import *
def check(ch):
if(len(ch) > 0) :
for i in range(len(ch)):
if((ch [i] < "A")or(ch [i] > "Z"))and((ch [i] < "a")or(ch [i] > "z"))and(ch [i] != " ") :
return False
return True
else:
return False
def get_size () :
x=0
while(x < 2) or (x > 9):
x = int(input("Enter the number of projects (>= 2 and <= 10): "))
returnx
def fill_array (ta, x) :
for i in range(x):
ta [i] = {}
**** Project number
Creation date:
ta [i]["date_création"] = {}
ta [i]["date_création"]["jour"] =int(input("Jour : "))
Month :
int(input("Year: "))
ta [i]["domaine"] = ""
while not(check(ta[i]["domain"])) or (len(ta[i]["domain"]) > 15):
Field :
Number of employees:
Project manager:
ta [i]["chef_projet"] ={}
ta [i]["chef_projet"]["nom"] = ""
while not(verify(ta[i]["project_manager"]["name"])) or (len(ta[i]["project_manager"]["name"]) > 15):
input("Name: ")

Teacher: AHMED BELHASSEN 6


Computational thinking and programming

ta [i]["chef_projet"]["numéro_tel"] = ""
while not(ta[i]["project_manager"]["phone_number"].isdigit()) or (len(ta
The project manager's phone number is not 8 digits.

ta [i]["chef_projet"]["phone_number"] = input("Phone number: ")


def display_domains(ta, x):
for i in range(x):
if(ta [i]["number_of_employees"] < 22) :
print(ta [i]["domain"])
def display_project_manager (ta, x) :
for i in range(x):
if(ta [i]["creation_date"]["year"] == 2020) :
print(ta [i]["project_manager"]["name"])
main program
n = input_size ()
t = array([{}] * n)
fill_table (t,n)
Print("The areas of projects where the number of employees is less than 22:")
display_domains (t,n)
Print("The names of the project managers who completed a project in the year 2020:")
display_project_leader (t,n)

Teacher: AHMED BELHASSEN 7


Computational thinking and programming

Class version:
from numpy import *
classdate
day = 0
mois = 0
année = 0
classchef :
nom
numéro_tel
class project
date()
domaine
nombre_employés = 0
project_chef = chef()
defcheck (ch) :
if(len(ch) > 0) :
for i in range(len(ch)) :
if((ch [i] < "A") or (ch [i] > "Z")) and ((ch [i] < "a") or (ch [i] > "z")) and (ch [i] != " "):
return False
return True
else:
return False
def seize_size () :
x=0
while (x < 2) or (x > 10):
x = int(input("Enter the number of projects (>= 2 and <= 10): "))
returnx
def fill_array (ta, x) :
for i in range(x):
ta [i] = project ()
**** Project num
Creation date :
ta [i].creation_date = date()
day = int(input("Day: "))

Teacher: AHMED BELHASSEN 8


Computational thinking and programming

ta [i].date_creation.month = int(input("Month : "))


Year :
ta [i].domaine
while not(check(ta[i].domain)) or (len(ta[i].domain) > 15):
Domain:
ta [i].number_of_employees = int(input("Number of employees: "))
Project Leader:
ta [i].project_leader = leader ()

ta [i].chef_projet.nom
while not(check (ta [i].project_leader.name)) or (len(ta [i].project_leader.name) > 15) :
Name :
ta [i].chef_projet.numéro_tel
while not(ta[i].project_leader.phone_number.isdigit()) or (len(ta[i].project_leader.phone_number) != 8):
Project manager phone number:
def display_domains(ta, x):
for i in range(x):
if(ta [i].number_of_employees < 22) :
print(ta [i].domain)
def display_project_leader (ta,x) :
for i in range(x):
if(ta[i].creation_date.year == 2020) :
print(ta[i].project_lead.name)
main program
n = enter_size()
empty(n, project)
# t =array([project] * n)
fill_array (t,n)
Print("The fields of projects where the number of employees is less than 22:")
display_domains (t,n)
Print("The names of the project managers who worked on a project in the year 2020:")
display_project_manager (t,n)

Teacher: AHMED BELHASSEN 9

You might also like