Klassen

http://www.anonym24.de/lehre1/

// Beispielprogramm zum raussuchen von PLZs mit Klassen
 
#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;
 
class tele_vorwahl {
 
   private:
           string vorwahl,ort;        
   public:
          // Hier wird der Konstruktor überschrieben 
          tele_vorwahl(string A);
          // Methodenaufruf als Prototype
          bool pruefe_vorwahl(string VW);
 
          // Methodenaufruf als Inline
          string get_vorwahl ()
          {
 
                 if (pruefe_vorwahl(vorwahl))
                 return ort;
                 else
                 return "Keine Zuordnung, "+ort;
          }
 
};
// Konstruktor Programm
tele_vorwahl::tele_vorwahl(string A)
          {
              vorwahl=A;
          }
 
bool tele_vorwahl::pruefe_vorwahl(string VW)
     {
     int k;
     // Hier noch Programmieren
        if (VW=="030")
            {
            ort="Berlin\n";
            return true;
            }
              else if(VW=="040")
                   {
                    ort="Hamburg\n";
                    return true;
                    }
                           else if(VW=="089")
                                {
                                 ort="Muenchen\n";
                                  return true;
                                  }
                                         else if(VW=="0221")
                                              {
                                               ort="Koeln\n";
                                               return true;
                                               }
            else
            {
                ort="nicht bekannter Ort\n";
                return false;
            }    
      }
 
int main(int argc, char *argv[])
{
  // Instanz bilden 
  tele_vorwahl Vor_W("0666");
 
  // Dynamische Instanz!
  // int *pi=new int;
 
 
 
  // Testausgabe zum Fkt. Test
      cout << Vor_W.get_vorwahl()  << endl;
 
    system("PAUSE");
    return EXIT_SUCCESS;
}