Advertisement
Abelsor

Automovil

Feb 8th, 2024
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.54 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Automovil{
  6.     // Constructores
  7.     public:
  8.         Automovil();
  9.         Automovil(string, string, float);
  10.  
  11.         virtual ~Automovil();
  12.  
  13.     // Metodos / Prototipos
  14.         // Setters
  15.         void setMarca(string);
  16.         void setModelo(string);
  17.         void setCapacidadTanque(float);
  18.  
  19.         // Getters
  20.         string getMarca();
  21.         string getModelo();
  22.         float getCapacidadTanque();
  23.         float getCantidadCombustible();
  24.  
  25.         // Metodos
  26.         void cargarCombustible(string, float);
  27.         void info();
  28.         void viajar(float);
  29.  
  30.     private:
  31.         string marca;
  32.         string modelo;
  33.         string tipoCombustible;
  34.         float cantidadCombustible=0;
  35.         float capacidadTanque;
  36.         float autonomia;
  37.         float distancia;
  38.  
  39. };
  40.  
  41. Automovil::Automovil(){
  42.     // Constructor
  43. }
  44.  
  45. Automovil::Automovil(string _marca, string _modelo, float _capacidadTanque = 30.0){
  46.     marca = _marca;
  47.     modelo = _modelo;
  48.     capacidadTanque = _capacidadTanque;
  49. }
  50.  
  51. Automovil::~Automovil(){
  52.     // Destructor
  53. }
  54.  
  55. void Automovil::setMarca(string _marca){
  56.     marca = _marca;
  57. }
  58.  
  59. void Automovil::setModelo(string _modelo){
  60.     modelo = _modelo;
  61. }
  62.  
  63. void Automovil::setCapacidadTanque(float _capacidad_tanque){
  64.     capacidadTanque = _capacidad_tanque;
  65. }
  66.  
  67. string Automovil::getMarca(){
  68.     return marca;
  69. }
  70.  
  71. string Automovil::getModelo(){
  72.     return modelo;
  73. }
  74.  
  75. float Automovil::getCapacidadTanque(){
  76.     return capacidadTanque;
  77. }
  78.  
  79. float Automovil::getCantidadCombustible(){
  80.     return cantidadCombustible;
  81. }
  82.  
  83.  
  84. void Automovil::cargarCombustible(string _tipoCombustible, float _cantidadCombustible){
  85.         cantidadCombustible += _cantidadCombustible;
  86.         autonomia = (cantidadCombustible*100.0)/8.0; // Autonomia de 8L/100Km
  87. }
  88.  
  89. void Automovil::info(){
  90.     cout<<"=== Caracteristicas del Automovil ==="<<endl;
  91.     cout<<"Marca: "<<marca<<endl;
  92.     cout<<"Modelo: "<<modelo<<endl;
  93.     cout<<"Capacidad del tanque: "<<capacidadTanque<<" Litros"<<endl;
  94.     cout<<"Cantidad de Combustible: "<<cantidadCombustible<<" Litros"<<endl;
  95.     cout<<"Autonomia: "<<autonomia<<" Km"<<endl;
  96. }
  97.  
  98. void Automovil::viajar(float _distancia){
  99.     cantidadCombustible -= (_distancia*8.0)/100;
  100.     autonomia = (cantidadCombustible*100.0)/8.0; // Autonomia de 8L/100Km
  101. }
  102.  
  103.  
  104. int main()
  105. {
  106.     int opcion = 0;
  107.     bool bandera = true;
  108.     string tipo = " ";
  109.     float cant;  
  110.     float aux;
  111.    
  112.     Automovil Auto_1("Mercedes Benz","C220",20);
  113.  
  114.     while(bandera){
  115.         switch(opcion)
  116.         {
  117.         case 0:
  118.             cout<<"= == === ==== Menu Principal ====  === == ="<<endl;
  119.             cout<<"1 -> Ver Informacion del Automovil"<<endl;
  120.             cout<<"2 -> Cargar Combustible"<<endl;
  121.             cout<<"3 -> Viajar"<<endl;
  122.             cout<<"4 -> Salir"<<endl;
  123.             cin>>opcion;
  124.             break;
  125.  
  126.         case 1:
  127.             cout<<"= == === ==== Informacion ====  === == ="<<endl;
  128.             Auto_1.info();
  129.            
  130.             cout<<"\nPresiona '0' para volver al Menu Principal..."<<endl;
  131.             cin>>opcion;
  132.             break;
  133.         case 2:
  134.             cout<<"= == === ==== Cargar Combustible ====  === == ="<<endl;
  135.             cout<<"Cantidad de Combustible: "<<Auto_1.getCantidadCombustible()<<endl;
  136.             cout<<"Tipo: "; cin>>tipo;
  137.             cout<<"Cantidad: "; cin>>cant;
  138.  
  139.             if(Auto_1.getCantidadCombustible()+cant <= Auto_1.getCapacidadTanque()){
  140.                 Auto_1.cargarCombustible(tipo,cant);
  141.  
  142.                 cout<<"Listo!"<<endl;
  143.             }
  144.  
  145.             else{
  146.                 cout<<"La cantidad sobre pasa la capacidad del tanque("<<Auto_1.getCapacidadTanque()<<" Litros)."<<endl;
  147.             }
  148.  
  149.             cout<<"\nPresiona '0' para volver al Menu Principal..."<<endl;
  150.             cin>>opcion;
  151.             break;
  152.         case 3:
  153.             cout<<"= == === ==== Viajar ====  === == ="<<endl;
  154.             aux = Auto_1.getCantidadCombustible();
  155.  
  156.             cout<<"Distancia: ";
  157.             cin>>cant;
  158.             Auto_1.viajar(cant);
  159.  
  160.             cout<<"Informacion del viaje..."<<endl;
  161.             cout<<"Distancia Recorrida: "<<cant<<endl;
  162.             cout<<"Combustible utilizado: "<<aux - Auto_1.getCantidadCombustible()<<" Litros."<<endl;
  163.            
  164.             cout<<"\nPresiona '0' para volver al Menu Principal..."<<endl;
  165.             cin>>opcion;
  166.             break;
  167.  
  168.         default:
  169.                 bandera = false;
  170.             break;
  171.         }
  172.     }
  173.  
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement