1、# in clu d e# in clu d e# in clu d e# in clu d eco n st in t TMAX=5 0 ;u sin g n amesp ace std ;class Perso np u b lic:in t n u m;/编号strin g n ame;/姓名strin g sex ;/性别in t ag e;/年龄d o u b le water;/用水量d o u b le p o wer;/用电量p u b lic:Perso n (in t n =0 ,strin g n m=“ “,strin g s=“ “,in t a=0 ,d o u b
2、 le w=0 .0 ,d o u b lep =0 .0 )/初始化n u m = n ; n ame = n m;sex = s; ag e = a;water = w; p o wer = p ;v irtu al v o id In p u t();v irtu al v o id Ou tp u t();in t GetNu m()retu rn n u m;/获取编号strin g GetName()retu rn n ame;/获取姓名d o u b le GetWater()retu rn water;/获取用水量d o u b le GetPo wer()retu rn p
3、o wer;/获取用电量;class Teach er:v irtu al p u b lic Perso n /教师p u b lic:strin g d ep art;/工作部门d o u b le watermo n ey ;/教师水费d o u b le p o wermo n ey ;/教师电费in t ch o ice1 ; in t ch o ice2 ;p u b lic:Teach er(in t n =0 ,strin g n m=“ “,strin g s=“男“,in t a=0 ,strin g d =“普通教师“,d o u b le w=0 .0 , d o u
4、b le p =0 .0 , d o u b le wm=0 .0 , d o u b le p m=0 .0 ) :Perso n (n ,n m,s,a,w,p ),d ep art(d )/构造函数 watermo n ey =wm;p o wermo n ey =p m;v o id In p u t()co u tn u m;co u tn ame;co u tch o ice2 ;switch (ch o ice2 ) case 1 :sex =“男“;b reak ; case 2 :sex =“女“;b reak ;d efau lt:co u tag e;co u tch o
5、 ice1 ;switch (ch o ice1 ) case 1 :d ep art=“普通教师“;b reak ; case 2 :d ep art=“教务处“;b reak ;case 3 :d ep art=“财政处“;b reak ; case 4 :d ep art=“创业办公室“;b reak ;d efau lt:co u twater;co u tp o wer;watermo n ey =0 .5 * water; p o wermo n ey =0 .5 * p o wer;v o id Ou tp u t() co u tn u m;co u tn ame;co u t
6、ch o ice2 ;switch (ch o ice2 ) case 1 :sex =“男“;b reak ; case 2 :sex =“女“;b reak ;d efau lt:co u tag e;co u tch o ice1 ; switch (ch o ice1 ) case 1 :b j=“计科1班“;b reak ;case 2 :b j=“计科2班“;b reak ; case 3 :b j=“计科3班“;b reak ;case 4 :b j=“计科4班“;b reak ;d efau lt:co u twater;co u tp o wer;watermo n ey =
7、0 .5 * (water-1 0 ); p o wermo n ey =0 .5 * (p o wer-1 0 );v o id Ou tp u t() co u t=TMAX) co u tch o ice;switch (ch o ice)case 1 :co u tn ame; co u twater;co u tp o wer; co u tn u m; fo r(in t i=0 ;ich o ice;switch (ch o ice)case 1 : co u tn u m; fo r(in t i=0 ;ich o ice; switch (ch o ice) case 1 :
8、fo r(in t j=i;jn ame;fo r(in t i=0 ;ich o ice;switch (ch o ice) case 1 : fo r(in t j=i;jch o ice;switch (ch o ice)case 1 : d o u b le zwater=0 .0 , zp o wer=0 .0 ;fo r(in t i=0 ; iStu i.n u m Stu i.n ameStu i.sex Stu i.ag eStu i.b j Stu i.waterStu i.p o wer Stu i.watermo n eyStu i.p o wermo n ey )i+
9、; to p +;co u t=TMAX) co u tch o ice;switch (ch o ice)case 1 : co u tn ame;co u twater; co u tp o wer;co u tn u m;fo r(in t i=0 ;ich o ice;switch (ch o ice) case 1 : co u tn u m;fo r(in t i=0 ;ich o ice;switch (ch o ice) case 1 : fo r(in t j=i;jn ame; fo r(in t i=0 ;ich o ice; switch (ch o ice) case
10、 1 : fo r(in t j=i;jch o ice;switch (ch o ice)case 1 : d o u b le zwater=0 .0 , zp o wer=0 .0 ; fo r(in t i=0 ; iTeai.n u mTeai.n ame Teai.sexTeai.ag e Teai.d ep artTeai.water Teai.p o werTeai.watermo n ey Teai.p o wermo n ey ) i+;to p +;co u t教师水电费管理 t2 =学生水电费管理 t0 =退出系统 “ch o ice; switch (ch o ice
11、) case 1 :TeaMen u ();b reak ; case 2 :Stu Men u ();b reak ;case 0 :co u tch o ice;switch (ch o ice) case 1 :t.Ad d ();b reak ; case 2 :t.Search ();b reak ; case 3 :t.Ed it();b reak ; case 4 :t.Delete();b reak ;case 5 :t.Sh o w();b reak ; case 6 :t.Sav e();b reak ;case 7 :t.Read ();b reak ; case 8 :
12、t.To tal();b reak ;case 0 :co u tch o ice; switch (ch o ice) case 1 :s.Ad d ();b reak ;case 2 :s.Search ();b reak ; case 3 :s.Ed it();b reak ;case 4 :s.Delete();b reak ; case 5 :s.Sh o w();b reak ;case 6 :s.Sav e();b reak ; case 7 :s.Read ();b reak ;case 8 :s.To tal();b reak ; case 0 :co u t“退出成功!“en d l;b reak ;d efau lt:co u t“无此选项!请重试!“en d l;b reak ;