Baixe o app para aproveitar ainda mais
Prévia do material em texto
Revisão: Exercício Ônibus (Aula Prática 07) BCC702-Programação de Computadores II Emiliana Mara Lopes Simões simoes.eml@gmail.com Universidade Federal de Ouro Preto maio 2010 Classe Passageiro: Arquivo Passageiro.h #i f n d e f PASSAGEIRO_H #de f i n e PASSAGEIRO_H #in c l u d e <s t r i n g > #in c l u d e <ios t r eam> us i ng namespace s t d ; c l a s s Pa s s a g e i r o { p ub l i c : P a s s a g e i r o ( ) ; P a s s a g e i r o ( s t r i n g n ) ; vo id setNome ( s t r i n g n ) ; s t r i n g getNome ( ) ; v i r t u a l f l o a t ca l cPaga ( f l o a t taxa ) ; v i r t u a l vo i d imp r im i r ( ) ; p r i v a t e : s t r i n g nome ; } ; #end i f Classe Passageiro: Arquivo Passageiro.cpp #in c l u d e " Pa s s a g e i r o . h" Pa s s a g e i r o : : P a s s a g e i r o ( ) { setNome ( "" ) ; } Pa s s a g e i r o : : P a s s a g e i r o ( s t r i n g n ) { setNome (n ) ; } vo id Pa s s a g e i r o : : setNome ( s t r i n g n ) { nome = n ; } s t r i n g Pa s s a g e i r o : : getNome ( ) { r e t u r n nome ; } . . . Classe Passageiro: Arquivo Passageiro.cpp f l o a t Pa s s a g e i r o : : ca l cPaga ( f l o a t taxa ) { r e t u r n taxa ; } vo id Pa s s a g e i r o : : imp r im i r ( ) { cout << "\nPASSAGEIRO COMUM: " << end l << "Nome : " << getNome ( ) << end l ; } Classe Aposentado: Arquivo Aposentado.h #i f n d e f APOSENTADO_H #de f i n e APOSENTADO_H #in c l u d e " Pa s s a g e i r o . h" c l a s s Aposentado : p ub l i c Pa s s a g e i r o { p ub l i c : Aposentado ( ) ; Aposentado ( s t r i n g n , s t r i n g r ) ; vo id setRg ( s t r i n g r ) ; s t r i n g getRg ( ) ; v i r t u a l f l o a t ca l cPaga ( f l o a t taxa ) ; v i r t u a l vo i d imp r im i r ( ) ; p r i v a t e : s t r i n g rg ; } ; #end i f Classe Aposentado: Arquivo Aposentado.cpp #in c l u d e "Aposentado . h" Aposentado : : Aposentado ( ) : P a s s a g e i r o ( ) { setRg ( "" ) ; } Aposentado : : Aposentado ( s t r i n g n , s t r i n g r ) : P a s s a g e i r o ( n ) { setRg ( r ) ; } vo id Aposentado : : setRg ( s t r i n g r ) { rg = r ; } s t r i n g Aposentado : : getRg ( ) { r e t u r n rg ; } . . . Classe Aposentado: Arquivo Aposentado.cpp f l o a t Aposentado : : ca l cPaga ( f l o a t taxa ) { r e t u r n 0 ; } vo id Aposentado : : imp r im i r ( ) { cout << "\nPASSAGEIRO APOSENTADO" << end l << "Nome : " << getNome ( ) << end l << " I d e n t i d a d e : " << getRg ( ) << end l ; } Classe Estudante: Arquivo Estudante.h #i f n d e f ESTUDANTE_H #de f i n e ESTUDANTE_H #in c l u d e " Pa s s a g e i r o . h" c l a s s Estudante : p ub l i c Pa s s a g e i r o { p ub l i c : Es tudante ( ) ; Es tudante ( s t r i n g n , s t r i n g r ) ; vo id setRa ( s t r i n g r ) ; s t r i n g getRa ( ) ; v i r t u a l f l o a t ca l cPaga ( f l o a t taxa ) ; v i r t u a l vo i d imp r im i r ( ) ; p r i v a t e : s t r i n g ra ; } ; #end i f Classe Estudante: Arquivo Estudante.cpp #in c l u d e " Estudante . h" Estudante : : Es tudante ( ) { setRa ( "" ) ; } Es tudante : : Es tudante ( s t r i n g n , s t r i n g r ) : P a s s a g e i r o ( n ) { setRa ( r ) ; } vo id Estudante : : se tRa ( s t r i n g r ) { ra = r ; } s t r i n g Estudante : : getRa ( ) { r e t u r n r a ; } . . . Classe Estudante: Arquivo Estudante.cpp f l o a t Estudante : : ca l cPaga ( f l o a t taxa ) { r e t u r n taxa /2 ; } vo id Estudante : : imp r im i r ( ) { cout << "\nPASSAGEIRO ALUNO" << end l << "Nome : " <<getNome ( ) << end l << " R e g i s t r o academico : " << getRa ( ) << end l ; } Classe Onibus: Arquivo Onibus.h #i f n d e f ONIBUS_H #de f i n e ONIBUS_H #in c l u d e " Estudante . h" #in c l u d e "Aposentado . h" c l a s s Onibus { p ub l i c : Onibus ( ) ; // c o n s t r u t o r ~Onibus ( ) ; // d e s t r u t o r vo id addPas s age i r o ( Pa s s a g e i r o ∗p ) ; f l o a t c a l cTo t a lA r r e c adado ( ) ; vo id i m p r im i r P a s s a g e i r o s ( ) ; vo id s e tMo t o r i s t a ( s t r i n g m) ; s t r i n g g e tMo to r i s t a ( ) ; vo id setTaxa ( f l o a t t ) ; f l o a t getTaxa ( ) ; . . . Classe Onibus: Arquivo Onibus.h p r i v a t e : i n t t o t a l P a s ; s t r i n g mo to r i s t a ; f l o a t taxa ; Pa s s a g e i r o ∗ vetPas [ 4 5 ] ; } ; #end i f Classe Onibus: Arquivo Onibus.cpp #in c l u d e "Onibus . h" Onibus : : Onibus ( ) { t o t a l P a s = 0 ; s e tMo t o r i s t a ( "" ) ; setTaxa (0 ) ; f o r ( i n t i =0; i <45; i++) vetPas [ i ] = NULL ; } Onibus : : ~ Onibus ( ) { f o r ( i n t i =0; i<t o t a l P a s ; i++) de l e t e vetPas [ i ] ; } . . . Classe Onibus: Arquivo Onibus.cpp vo id Onibus : : addPas s age i r o ( Pa s s a g e i r o ∗p ) { i f ( t o t a l P a s < 45) { vetPas [ t o t a l P a s ] = p ; t o t a l P a s++; } e l s e cout << " Pa s s a g e i r o nao ad i c i o n ado . Onibus sem vagas ! ! ! ! " ; } Classe Onibus: Arquivo Onibus.cpp f l o a t Onibus : : c a l cTo t a lA r r e c adado ( ) { f l o a t t o t a lA r r e c a d ado = 0 ; f o r ( i n t i =0; i<t o t a l P a s ; i++) t o t a lA r r e c a d ado += vetPas [ i ]−>ca lcPaga ( taxa ) ; r e t u r n t o t a lA r r e c a d ado ; } Classe Onibus: Arquivo Onibus.cpp vo id Onibus : : imp r im i r P a s s a g e i r o s ( ) { f o r ( i n t i =0; i<t o t a l P a s ; i++){ vetPas [ i ]−>imp r im i r ( ) ; cout<<endl<<"−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−"<< end l ; } } Classe Onibus: Arquivo Onibus.cpp vo id Onibus : : s e tMo t o r i s t a ( s t r i n g m) { mo to r i s t a = m; } s t r i n g Onibus : : g e tMo to r i s t a ( ) { r e t u r n moto r i s t a ; } vo id Onibus : : se tTaxa ( f l o a t t ) { taxa = t ; } f l o a t Onibus : : getTaxa ( ) { r e t u r n taxa ; } Programa Principal: Arquivo Main.cpp #in c l u d e "Onibus . h" i n t main ( ) { Onibus ∗bus = new Onibus ( ) ; i n t opcao , t i poPa s ; s t r i n g nomeMot , nomePas , rgPas , raPas ; f l o a t v a l o rPa s ; cout<<" D i g i t e : "<<end l <<" 1 . Cada s t r a r nome do mo to r i s t a "<<end l <<" 2 . Cada s t r a r v a l o r da passagem"<<end l <<" 3 . Cada s t r a r p a s s a g e i r o "<<end l <<" 4 . Most rar todos p a s s a g e i r o s "<<end l <<" 5 . Most rar t o t a l a r r e cadado "<<end l <<" 6 . S a i r "<<end l ; c in>>opcao ; Programa Principal: Arquivo Main.cpp wh i l e ( opcao != 6) { sw i t ch ( opcao ) { case 1 : cout<<"\ nD i g i t e o nome do mo to r i s t a do on ibu s : " ; c in>>nomeMot ; bus−>se tMo t o r i s t a (nomeMot ) ; break ; case 2 : cout<<"\ nD i g i t e o v a l o r da passagem : " ; c in>>va l o rPa s ; bus−>setTaxa ( v a l o rPa s ) ; break ; Programa Principal: Arquivo Main.cpp case 3 : cout<<"\ nD i g i t e : "<<end l <<" 1 . Cada s t r a r p a s s a g e i r o comum"<<end l <<" 2 . Cada s t r a r p a s s a g e i r o e s t udan t e "<< end l <<" 3 . Cada s t r a r p a s s a g e i r o aposentado "<< end l ; c in>>t ipoPas ; Programa Principal: Arquivo Main.cpp sw i t ch ( t i poPa s ) { case 1 : cout<<"\ nD i g i t e o nome do p a s s a g e i r o : " ; c in>>nomePas ; bus−>addPas sage i r o (new Pa s s a g e i r o ( nomePas ) ) ; break ; case 2 : cout<<"\ nD i g i t e o nome do p a s s a g e i r o ( e s t udan t e ) : " ; c in>>nomePas ; cout<<"\ nD i g i t e o r e g i s t r o academico do p a s s a g e i r o ( e s t udan t e ) : " ; c in>>raPas ; bus−>addPas sage i r o (new Estudante ( nomePas , raPas ) ) ; break ; Programa Principal: Arquivo Main.cpp case 3 : cout<<"\ nD i g i t e o nome do p a s s a g e i r o ( aposentado ) : " ; c in>>nomePas ; cout<<"\ nD i g i t e a i d e n t i d a d e do p a s s a g e i r o ( aposentado ) : " ; c in>>rgPas ; bus−>addPas sage i r o (new Aposentado ( nomePas , rgPas ) ) ; break ; d e f a u l t : cout<<"\n∗∗∗∗ Opcao i n v a l i d a . Tente novamente ! ! ! ! ∗∗∗∗\n\n" ; } break ; Programa Principal: Arquivo Main.cpp case 4 : cout<<"\n∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗\n" <<"DADOS DE TODOS OSPASSAGEIROS"<<end l <<"\n∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗\n" ; bus−>imp r im i r P a s s a g e i r o s ( ) ; break ; case 5 : cout<<"\n∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗\n" <<"Ar recadacao t o t a l do on i bu s : "<<bus−> ca l cTo t a lA r r e c adado ( )<<end l <<"\n∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗\n" ; break ; d e f a u l t : cout<<"\n∗∗∗∗ Opcao i n v a l i d a ! ! ! ! ∗∗∗∗\n\n" ; } Programa Principal: Arquivo Main.cpp cout<<" D i g i t e : "<<end l <<" 1 . Cada s t r a r nome do mo to r i s t a "<<end l <<" 2 . Cada s t r a r v a l o r da passagem"<<end l <<" 3 . Cada s t r a r p a s s a g e i r o "<<end l <<" 4 . Most rar todos p a s s a g e i r o s "<<end l <<" 5 . Most rar t o t a l a r r e cadado "<<end l <<" 6 . S a i r "<<end l ; c in>>opcao ; } cout<<"Programa sendo f i n a l i z a d o . P r e s s i o n e qua l que r t e c l a . " ; system ( "PAUSE>NULL" ) ; de l e t e bus ; // d e l e t a o ob j e t o bus r e t u r n EXIT_SUCCESS ; } Dúvidas? Próxima Aula Prova dia 31/05/2010!
Compartilhar