Skip to content

Instantly share code, notes, and snippets.

@TaderFit
Last active January 16, 2018 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TaderFit/dff5fe8a71942c4ca4aaa4325b51845a to your computer and use it in GitHub Desktop.
Save TaderFit/dff5fe8a71942c4ca4aaa4325b51845a to your computer and use it in GitHub Desktop.
ruby script for managing school
require_relative 'TD1'
module Gestion
module Etudian
class Eleve
include Commune
end
class Delege < Eleve
end
end#module Etudian
module Administration
class Professeur
include Commune
end
class Surveillant < Professeur
end
end #module Administration
end#premier module Gestion
module Commune
attr_accessor :fiche
def initialize (nom)
@nom = nom
@notes=[]
@fiche={nom:@nom,notes:@notes}
@arret=0
$stdout.sync
#STDIN.sync=true
end
def nombreNote
print "Nombre De Note a Atribuer a #{@nom}: "
a=gets.chomp.to_i
@arret=a
end
def ajouterNote
i=0
while(@arret != i)
print "Note #{i}:"
a=gets.chomp.to_i
@notes << a
i+=1
end
end
def isMoyenne
sum=0
@notes.each {|i| sum+=i}
return sum/@notes.length
end
def presenTation(presnet,chaine)
presnet.call(@fiche)
puts chaine
end
###ajotuer une methode qui me permet de cree et d'enregistré dans un fichei
def self.MikFile
begin
Dir::mkdir("Gestion",0777)
rescue Errno::EEXIST => exist
ensure
if exist
File.new("Gestion/Etudian.txt","w+")
File.new("Gestion/Administration.txt","w+")
else
File.new("Gestion/Etudian.txt","w+")
File.new("Gestion/Administration","w+")
end
end#begin
end#def
# 1_ Enregistrement
#beug ici faut le regeler
def enregistrement(instance)
instance=instance.class
if (instance.class.to_s == "Gestion::Etudian::Eleve" && instance.class.to_s == "Gestion::Etudian::Delege")
file1=File.open("Gestion/Etudian.txt","a")
file1.write "NOM: #{@fiche[:nom]}\tNOTES: #{@fiche[:notes]}\tMOYENNE: #{isMoyenne}/20\n"
file1.close
elsif (instance.class == "Professeur"&& instantce.class == "Surveillant")
file1=File.open("Gestion/Administration.txt","a")
file1.write "NOM: #{@fiche[:nom]}\tNOTES: #{@fiche[:notes]}\tMOYENNE: #{isMoyenne}/20\n"
file1.close
end #if
end#methode
#faut ajouter une methode qui me permet de cree des instantce
#et une autre qui me permet d'atribuer des note et une dernier qui comportera le proc et fera l'aplpel de l'afficheage
end#module
require_relative "TD"
begin
File.readlines("Gestion/Etudian.txt")
rescue Errno::ENOENT => @noFile
end
if @noFile
puts"\n***************************************************************************"
puts "=================================Menu====================================="
puts " 1_ Configure /(configure la Base de Donnee)"
puts " 2_ Exit /(Sortire du Programme)"
puts"***************************************************************************\n"
puts "\nEntre Votre Choix :"
a=gets.chomp
if a == "1"
Commune.MikFile
else
exit
end# if 2
end # if 1
puts"\n***************************************************************************"
puts"***************************************************************************"
puts "=================================Menu====================================="
puts " 1_ Cree une Fiche"
puts " 2_ Suprimer une Fiche"
puts " 3_ Voir les Fiche"
puts"***************************************************************************"
puts"***************************************************************************\n"
a=gets.chomp
if a == "1" # cree une fiche if 1
puts"\n***************************************************************************"
puts"***************************************************************************"
puts "=================================Menu 2====================================="
puts " 1_ Etudian"
puts " 2_ Administration"
puts"***************************************************************************"
puts"***************************************************************************\n"
a=gets.chomp
if a == "1"#Etudian if 2
puts"\n***************************************************************************"
puts"***************************************************************************"
puts "=================================Menu 3====================================="
puts " 1_ Eleve"
puts " 2_ delege"
puts"***************************************************************************"
puts"***************************************************************************\n"
#==============================================================section Etudian =======================================================================#
#==============================================================section Eleve =======================================================================#
a=gets.chomp
if a== "1" ##Eleve if 3
@arret=0
while @arret != 1
puts "Nom Complet:"
a=gets.chomp
eleve1=Gestion::Etudian::Eleve.new (a)
eleve1.nombreNote
eleve1.ajouterNote
@pres=Proc.new{|eleve| puts "\nCes information sont elle exacte \nNOM:#{eleve[:nom]}\nNotes:#{eleve[:notes]}\nMoyenne:#{eleve1.isMoyenne}/20"}
eleve1.presenTation(@pres,"Eleve : simple")
puts "\n\n"
puts"Enregistrement ? ( yes/no )"
b=gets.chomp
$stdin.flush
if b =="yes"
eleve1.enregistrement(eleve1)
@arret=1
else
puts "Veuiller redonnee les information corecte\n"
@arret=0
end#if
end #while
#=================================================================section DELEGE ==================================================================#
#ici le problem c'est que il faut entré plusiuer foi le choi et s'a n'execute meme pas
@arret=0
a=gets.chomp
elsif a == "2" #delege
STDIN.flush
while @arret #qui est declarer dans la 3emme condition if 3
puts "Nom Complet:"
a=gets.chomp
eleve1=Gestion::Etudian::Delege.new (a)
eleve1.nombreNote
eleve1.ajouterNote
@pres=Proc.new{|eleve| puts "\nCes information sont elle exacte \nNOM:#{eleve[:nom]}\nNotes:#{eleve[:notes]}\nMoyenne:#{eleve1.isMoyenne}/20"}
eleve1.presenTation(@pres,"Eleve : DELEGE")
puts "\n\n Enregistrement ? ( yes/no )"
a=gets.chomp
if a == "yes"
eleve1.enregistrement(eleve1)
@arret=1
else
@arret = 0
end#if
end#while
end# if 3
#=========================================================section administration ======================================================#
#ici aussi le probleme c'est que il fau entré le choix plusieur foi pour que sa execute le Programme
a=gets.chomp
elsif a== "2" # Administration if 2
puts"\n***************************************************************************"
puts"***************************************************************************"
puts "=================================Menu 3====================================="
puts " 1_ Professeur"
puts " 2_ Surveillant"
puts"***************************************************************************"
puts"***************************************************************************\n"
a=gets.chomp
if a == "1"
@arret = 0 #variable darret ou de bouclage
while @arret!=1 #qui est declarer dans la 3emme condition if 2
puts "Nom Complet:"
prof=Gestion::Administration::Professeur.new (gets.chomp)
prof.nombreNote
prof.ajouterNote
@pres=Proc.new{|eleve| puts "\nCes information sont elle exacte \nNOM:#{eleve[:nom]}\nNotes:#{eleve[:notes]}\nMoyenne:#{prof.isMoyenne}/20"}
prof.presenTation(@pres,"Administration : Professeur ")
puts "\n\n Enregistrement ? (1 yes/no 2)"
a=gets.chomp.to_i
if a == 1
prof.enregistrement(prof)
@arret=1
else
@arret = 0
end#if
end#while
a=gets.chomp
elsif a == "2"
@arret = 0 #variable darret ou de bouclage
while @arret!=1 #qui est declarer dans la 3emme condition if 2
puts "Nom Complet:"
surve=Gestion::Administration::Professeur.new (gets.chomp)
surve.nombreNote
surve.ajouterNote
@pres=Proc.new{|eleve| puts "\nCes information sont elle exacte \nNOM:#{eleve[:nom]}\nNotes:#{eleve[:notes]}\nMoyenne:#{surve.isMoyenne}/20"}
surve.presenTation(@pres,"Administration : Surveillant ")
puts "\n\n Enregistrement ? ( yes/no )"
a=gets.chomp
if a == "yes"
surve.enregistrement(surve)
@arret=1
else
@arret = 0
end#if
end#while
end
end # if administration
end# if 2
#end#if 1
=begin
methode enregistrement this methode helping me to save my hash in File
problem with my enresgistrement methode i'm obligate to entere 3 time "yes"
and she do not work correctelly
=end
@TaderFit
Copy link
Author

TaderFit commented Jan 16, 2018

the problem is here

def enregistrement(instance)
instance=instance.class
if (instance.class.to_s == "Gestion::Etudian::Eleve") && (instance.class.to_s == "Gestion::Etudian::Delege")
file1=File.open("Gestion/Etudian","a")
file1.write "NOM: #{@fiche[:nom]}\tNOTES: #{@fiche[:notes]}\tMOYENNE: #{isMoyenne}/20\n"
file1.close
elsif (instance.class == "Professeur"&& instantce.class == "Surveillant")
file1=File.open("Gestion/Administration","a")
file1.write "NOM: #{@fiche[:nom]}\tNOTES: #{@fiche[:notes]}\tMOYENNE: #{isMoyenne}/20\n"
file1.close
end #if
end#methode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment