init ( gestiunea studen get Æ set vc lt ( Æ gt ( Æ bool eq ( Æ ilor...

5
Student NrMa Nume Nrn Note _ _init_ _(self) Get(self) Set(self, V c ) __lt__(self,other) Bool __gt__(self,other) Bool __eq__(self,other) Bool Media(self) Real __str__(self) str Atrib(self) Student Lab.7 Fp Programare Modulară ~ Clase Studenti.Py: from UI.Apl_Stud import * main() Meniu.Txt: Gestiunea studentilor: 1. Citirea studentilor, 2. Afisarea stud. ordonati dupa nr matricol, 3. Afisarea stud. cu media notelor peste 9, 4. Lista stud. cu cel putin o nota de 10, 0. Terminare FileSt.Txt: 3235 Stef Ralu 4 7 5 10 8 2256 Ursulescu Eena 3 8 10 9 5656 Pascu Cosmina 2 9 8 1012 Truta Flaviu 4 8 10 9 10 1313 Tulbure Catalin 5 9 10 8 9 8 1486 Roman Tudor 5 9 6 9 10 8 2512 Radu Paul 3 7 8 9 1957 Pop Toma Marian 5 9 8 9 8 9 2013 Miclea Tudor 3 10 10 9 1983 Ghinda Robert Cristi 4 1 9 5 7 1516 Cocan Valentin 5 2 8 1 3 5 1426 Buze Gabriel 5 9 10 9 7 8 Gestiunea studen ţ ilor

Upload: duongtram

Post on 11-May-2018

217 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: init ( Gestiunea studen Get Æ Set Vc lt ( Æ gt ( Æ Bool eq ( Æ ilor …per/Python/Lab7-Python.pdf ·  · 2013-11-201516 Cocan Valentin 5 2 8 1 3 5 1426 Buze Gabriel 5 9 10 9

Student • NrMa • Nume • Nrn • Note • _ _init_ _(self) • Get…(self) … • Set…(self, Vc) • __lt__(self,other) Bool • __gt__(self,other) Bool • __eq__(self,other) Bool • Media(self) Real • __str__(self) str • Atrib(self) Student

Lab.7 Fp

Programare Modulară ~ Clase Studenti.Py:

from UI.Apl_Stud import *

main()

Meniu.Txt:

Gestiunea studentilor: 1. Citirea studentilor, 2. Afisarea stud. ordonati dupa nr matricol, 3. Afisarea stud. cu media notelor peste 9, 4. Lista stud. cu cel putin o nota de 10, 0. Terminare

FileSt.Txt:

3235 Stef Ralu 4 7 5 10 8 2256 Ursulescu Eena 3 8 10 9 5656 Pascu Cosmina 2 9 8 1012 Truta Flaviu 4 8 10 9 10 1313 Tulbure Catalin 5 9 10 8 9 8 1486 Roman Tudor 5 9 6 9 10 8 2512 Radu Paul 3 7 8 9 1957 Pop Toma Marian 5 9 8 9 8 9 2013 Miclea Tudor 3 10 10 9 1983 Ghinda Robert Cristi 4 1 9 5 7 1516 Cocan Valentin 5 2 8 1 3 5 1426 Buze Gabriel 5 9 10 9 7 8

Gestiu

nea stu

den

ţilor

Page 2: init ( Gestiunea studen Get Æ Set Vc lt ( Æ gt ( Æ Bool eq ( Æ ilor …per/Python/Lab7-Python.pdf ·  · 2013-11-201516 Cocan Valentin 5 2 8 1 3 5 1426 Buze Gabriel 5 9 10 9

2

UI.Apl_Stud.py: from Domeniu.ModStud import * def Str_St(r): NrMa=int(r[0:4]) # ; print "<",NrMa,">" Nume=r[5:28] # ; print "<",Nume,">" Nrn=int(r[27:29]) # ; print "<",Nrn,">" Note=[] for i in range(0,Nrn): Nota=int(r[30+i*3:32+i*3]) # print "Nota:<",Nota,">" Note+=[Nota] return Student(NrMa,Nume,Nrn,Note) def CitStud(St): print " CitStud ..." f = open('FileSt.Txt', 'r'); for r in f: St+=[Str_St(r)] f.close() def Fc(s1,s2): return cmp(s1.GetNrMa(), s2.GetNrMa()) # s1<s2 def AfStOm(St): print " AfStOm ..." St.sort(Fc) for s in St: print s def CitStM9(St): print " CitStM9 ..." for s in St: if s.Media()>9: print s,' Media:{:5.2f}'.format(s.Media()) def CitSt10(St): print " CitSt10 ..." for s in St: if 10 in s.Note: print s def CitText(Name): f = open(Name, 'r'); ''' s="" for r in f: s+=r ''' s=f.read() f.close() return s def main(): Meniu=CitText("Meniu.Txt"); F=[CitStud,AfStOm,CitStM9,CitSt10] St=[] while True: print Meniu Opt=int(input(" Functia : ")) if 1<=Opt<=len(F): F[Opt-1](St) else: break

Page 3: init ( Gestiunea studen Get Æ Set Vc lt ( Æ gt ( Æ Bool eq ( Æ ilor …per/Python/Lab7-Python.pdf ·  · 2013-11-201516 Cocan Valentin 5 2 8 1 3 5 1426 Buze Gabriel 5 9 10 9

3

Domeniu.ModStud.py: class Student:

def __init__(self, nrma=0, nume='', nrn=0, note=[]): self.NrMa=nrma self.Nume=nume self.Nrn=nrn self.Note=note

def GetNrMa(self): # ... GetNume, GetNrn, GetNote return self.NrMa def SetNrMa(self, nrma): # ... SetNume, SetNrn, SetNote self.NrMa=nrma def __lt__(self, other): return self.NrMa < other.NrMa def __gt__(self, other): return self.NrMa > other.NrMa def __eq__(self, other): return self.NrMa == other.NrMa # ... ne(!=), ge(>=), le(<=)

def Media(self): s=0.0 # s=0 ! for nota in self.Note: s+=nota return s/self.Nrn def __str__(self): ss=str(self.NrMa)+':'+self.Nume+' '+str(self.Nrn)+' Note: ' for n in self.Note: ss+=str(n)+', ' return ss[:len(ss)-2] def Atrib(self): # c=self c=Student(self.NrMa,self.Nume,self.Nrn,self.Note) return c def test(): s=Student(123456,'Popescu Ioan',5,[7,8,9,10,6])

print " Initial:",s s.SetNrMa(246123) print " Valoarea noua:",s.GetNrMa() print " Modificat:",s

t=Student(126000,'Ionescu Dan',3,[5,7,8,9,9])

print " Alt Stud.:",t

if s<t: print " < ",s else: print " <=",t

if s>t: print " > ",s else: print " >=",t

print " Media pt.",s,s.Media() print " Media pt.",t,t.Media()

a=s.Atrib() # a=s print " Stud. s..:",s print " Alt_stud.:",a a.SetNrMa(121212) print " Alt_stud.:",a print " Stud. s..:",s if __name__ == "__main__": test()

Page 4: init ( Gestiunea studen Get Æ Set Vc lt ( Æ gt ( Æ Bool eq ( Æ ilor …per/Python/Lab7-Python.pdf ·  · 2013-11-201516 Cocan Valentin 5 2 8 1 3 5 1426 Buze Gabriel 5 9 10 9

4

Console: Gestiunea studentilor: 1. Citirea studentilor, 2. Afisarea stud. ordonati dupa nr matricol, 3. Afisarea stud. cu media notelor peste 9, 4. Lista stud. cu cel putin o nota de 10, 0. Terminare Functia : 1 CitStud ... Gestiunea studentilor: 1. Citirea studentilor, 2. Afisarea stud. ordonati dupa nr matricol, 3. Afisarea stud. cu media notelor peste 9, 4. Lista stud. cu cel putin o nota de 10, 0. Terminare Functia : 2 AfStOm ... 1012:Truta Flaviu 4 Note: 8, 10, 9, 10 1313:Tulbure Catalin 5 Note: 9, 10, 8, 9, 8 1426:Buze Gabriel 5 Note: 9, 10, 9, 7, 8 1486:Roman Tudor 5 Note: 9, 6, 9, 10, 8 1516:Cocan Valentin 5 Note: 2, 8, 1, 3, 5 1957:Pop Toma Marian 5 Note: 9, 8, 9, 8, 9 1983:Ghinda Robert Cristi 4 Note: 1, 9, 5, 7 2013:Miclea Tudor 3 Note: 10, 10, 9 2256:Ursulescu Eena 3 Note: 8, 10, 9 2512:Radu Paul 3 Note: 7, 8, 9 3235:Stef Ralu 4 Note: 7, 5, 10, 8 5656:Pascu Cosmina 2 Note: 9, 8 Gestiunea studentilor: 1. Citirea studentilor, 2. Afisarea stud. ordonati dupa nr matricol, 3. Afisarea stud. cu media notelor peste 9, 4. Lista stud. cu cel putin o nota de 10, 0. Terminare Functia : 3 CitStM9 ... 1012:Truta Flaviu 4 Note: 8, 10, 9, 10 Media: 9.25 2013:Miclea Tudor 3 Note: 10, 10, 9 Media: 9.67 Gestiunea studentilor: 1. Citirea studentilor, 2. Afisarea stud. ordonati dupa nr matricol, 3. Afisarea stud. cu media notelor peste 9, 4. Lista stud. cu cel putin o nota de 10, 0. Terminare Functia : 4 CitSt10 ... 1012:Truta Flaviu 4 Note: 8, 10, 9, 10 1313:Tulbure Catalin 5 Note: 9, 10, 8, 9, 8 1426:Buze Gabriel 5 Note: 9, 10, 9, 7, 8 1486:Roman Tudor 5 Note: 9, 6, 9, 10, 8 2013:Miclea Tudor 3 Note: 10, 10, 9 2256:Ursulescu Eena 3 Note: 8, 10, 9 3235:Stef Ralu 4 Note: 7, 5, 10, 8 Gestiunea studentilor: 1. Citirea studentilor, 2. Afisarea stud. ordonati dupa nr matricol, 3. Afisarea stud. cu media notelor peste 9, 4. Lista stud. cu cel putin o nota de 10, 0. Terminare Functia : 0

Page 5: init ( Gestiunea studen Get Æ Set Vc lt ( Æ gt ( Æ Bool eq ( Æ ilor …per/Python/Lab7-Python.pdf ·  · 2013-11-201516 Cocan Valentin 5 2 8 1 3 5 1426 Buze Gabriel 5 9 10 9

5