Corrected Exercise - Algorithm + Python
Corrected Exercise - Algorithm + Python
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.
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
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
End for
End
Local Objects Declaration Table (TDOL)
Subject Type/Nature
i Whole
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: ")
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.
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: "))
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)