Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. class Automobil
  6. {
  7.     int v;
  8. public:
  9.     Automobil()
  10.     {
  11.         v = 300;
  12.     }
  13.  
  14.     Automobil(int v)
  15.     {
  16.         this ->v = v;
  17.     }
  18.  
  19.     int get_v()
  20.     {
  21.         return v;
  22.     }
  23.  
  24.     void set_v(int v)
  25.     {
  26.         this ->v = v;
  27.     }
  28.  
  29.     int beschleunigen(Automobil&a)
  30.     {
  31.         int erg;
  32.         if(v<300)
  33.         {
  34.             erg = v+5;
  35.         }
  36.         else
  37.         {
  38.             cout<<"MAX V";
  39.         }
  40.         return erg;
  41.     }
  42.  
  43.     int bremsen(Automobil&b)
  44.     {
  45.         int erg;
  46.         if(v<0)
  47.         {
  48.             erg = v-5;
  49.         }
  50.         else
  51.         {
  52.             cout<<"Keine negative v";
  53.         }
  54.         return erg;
  55.     }
  56. };
  57.  
  58. int main()
  59. {
  60.     Automobil audi;
  61.     int eingabe,v;
  62.     cout<<"Wie schnell fahrt ihr Auto ? ";
  63.     cin>>v;
  64.     audi.set_v(v);
  65.     cout<<"Bremsen[2] oder Beschleunigen[1]?";
  66.     cin>>eingabe;
  67.     if(eingabe == 1)
  68.     {
  69.         v = audi.beschleunigen(audi);
  70.         cout<<v;
  71.     }
  72.     if(eingabe == 2)
  73.     {
  74.         v =audi.bremsen(audi);
  75.         cout<<v;
  76.     }
  77.     return 0;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement