You are on page 1of 7

E;ngcbel

Oin 5 "L*

/r-,r,);-- \--
/z,.kln.-,
o, r//AL"-t '
/ n _
/-, nr,o .--- 2o"o)
"

, ./- -:
.,. i ,./ (-,..- :
.,-.;f
1,',
' T.XJ )
/V '/'/
,' ttr-'.;
' '()

lc hG7
C++ Keywords
Keywords are predefined reserved identifiers that have special meanings. They cannot be
used as identifiers in your program. The following keywords are reserved for C++:
Syntax
: one of
asml Auto bad cast bad tvpeid
bool Brea k case catch
char Class const const cast
contin ue Default delete do
dou ble Dynamic cast else enu m
except Explicit extern false
fin ally Float for friend
goto If inl ine int
long Mutable namespace new
operator Private protected public
register ReinterDret cast return short
siqned Sizeof static static cast
struct Switch temDlate this
th row True trv Wpe_anfo
tvpedef Typeid tvDena me unton
unsiqned Using virtual void
volatile While
1 Reserved for compatibility with other C++ im plementations, but not implemented. Use
_asm'
Microsoft Specific
In Microsoft C++, identifiers with two leading underscores are reserved for compiler
im plementations. Therefore, the Microsoft convention is to precede M icrosoft-specific
with double u res. These words cannot be as identifier names,

Replaces c++ asm syntax.


2
The keyword has limited uses for 32-bit target compilations.
3
These are
-basedspecial identifiers when used with their use in other contexts is not
restricted. -declspec;
Microsoft extensions are enabled by default. To ensure that your programs are fully
portable, you can disable Microsoft extensions by specifying the ANSI-compatible /Za
command-line option (compile for ANSi compatibility) during compilation' When you do this,
M icrosoft-specific keywords are disabled.
When lvlicrosoft extensions are enabled, you can use the previously- listed keywords in your
programs. For ANSI compliance. these keywords are prefaced by a double underscore, For
backward compatibility, single- u nderscore versions of all the keywords except
and are supported. In addition, is available with no
-except,
-finally, -leave,
leading underscore. EN D Microsoft
-try Specific -cdecl
Klassen Übung Teil 6

#include <stdio.h>
#include <string.h>

class Fahrzeug
{

public:
Fahrzeug0 {}
void setjreis(float p)
{preisl;}
float getjreis0
{ return preis;}
void drucken 0
{printf ("FahrzeugVr") } ;

voidset hersteller(char+h)
{herstelter=h;}
charx get_hersteller0
{return hersteller;}

private:

float preis;
chari< hersteller:

class PKW:public Fahrzeug


{
public:
PKw0 {}

void drucken0
(printf("Dies ist ein PKW\n");); //inline-Deklaration

void set_farbe(char* f)
{ farbe=f; }
char* get_farbeQ
{retum farbe; }

void set..perszahl (int pz)


{perszahl=pz;}
int get-perszahl fl
{return perszahl;}

private:
char* farbe;
int perszahl;

/A/ariablen für Eigenschaf ten

);
class LKW:public Fahrzeug
{
public:
LKwo {}
void drucken0
{printf("Dies ist ein LKW\n');}; //inline-Deklaration

private:
//Variablen für Eigenschaften
VDL t7 .11.99
15:07
);

main 0
{

PKW Pkw;
okw.drucken0;
Pkw.setireis(2000):
/r pkw.set-farbe(rot):
// Pkw.setlerszahl(9);

printf ("Preis: 4o Zt DM\n


"'pkw'get-preis()):,.,,,'.
a'd\n"Pkw getierszahl II):
printf ("Personenzahll

/iPkw 'Fahrzeug: : drucken 0 ;

LKWlkw;
lkw.drucken0;
tkw.setireis(70000);
Ikw set hersteller("k'):
rintf("ireis; 4o 2f DM\n " lkw getl]rers{)':

Fahrzeug fzg;
fze.drucken0;
fz! set Preis(90000
getireis0)i
printf("Pr.is g"sami''Z' Zf Omnfn"'t'g
get-hersteller0) ;
itiniti"u""'är"lz's\n"'lkw'
return 0;
)

t7 .11.99
VDL l5:07
Erstellt von Frank Pitscher Erstelldatum 17.11.99

// Autos.cpp

#include<stdio.h>

class Fahrzeug
{
public:
Fahrzeug0 {}
void Drucken0
{printf("VrDies ist ein Fahrzeug \n");}

void setjreis(float p) //p= preis


(preis=p;]

float get preis$ //Kopf der Funktion


{retum preis;} //Rumpf der Funktion

void set hersteller(charx h) //der x ist ein Zeiger,der die Speicheradresse anzeigt
{ hersteller= h;}

charx get herstellerQ //Kopf der Funktion


{retum hersteller;} //Rumpf der Funktion

private: //Variable für Eigenschaften


float preis;
char* hersteller;

t,
class PKw:public Fahrzeug
{
public:
PKW0 {} // Konsruktor

void Drucken0
{printf ("Dies ist ein PKW\n);} // dies ist eine inline Deklaration

void set_farbe (char* f) {farbe=f;}


char*get_farbe 0
{return farbe;}
void setjers_zahl (int p){pers zahl=p;}
int getjers_zahlo
{retum pers_zahl;}

private:
char*farbe;
int pers_zalrl;

l.

//LKW.cpp

class LKW: public Fahrzeug


{
public:
LKWQ {} // Konstruktor

void Drucken0
{printf("\nDies ist ein LKW\n");} // dies ist eine inline Deklaration
Erstellt von Frank Pitscher Erstelldatum 17.11.99

l.

main0
(
PKW pkw; //PKW = Datentyp pkw = Variablenname
pkw.Drucken0:
pkw.setjreis(2000);
pkw.set hersteller("BMW");

printf ("\nPersonenzahl: Tod",pkw.getjers_zahl0) ;


printf ("\nHersteller: 7os Vr", pkw.get_hersteller0) ;
printf ("Preis: 7o.2f DM \n",pkw.getjreis0);

pkw.Fahrzeug: :Drucken0 ;

LKW lkw; //PKW = Datentyp pkw = Variablenname


lkw.Drucken0;
\!. lkw.setjreis(200000);
lkw.set hersteller("MAN") ;

printf ("\nHersteller: 7os \r", tkw.get_heßtetler0) ;


printf ("Preis: 7o.2f DMVr",lkw.getjreis0) ;

Fatuzeug fahrzeug;
fahrzeug.Drucken0 ;

printf("\o");
retum 0;
]
Aufgabe: Schattjahr-Berechn un g

Es sollen zwei Jahreszahlen (vierstellig im Format jjjj) eingegeben werden: die zweite muß
größer sein als die erste.
Es soll die Anzahl der Schaltjahre in diesem Zeitraum errechnet und auf dem Monitor
ausgegeben werden.
Ein Jahr ist dann ein Schaltj ahr, wenn seine Zahl durch 4 teilbar ist, jedoch nicht durch 100;
es ist aber auch dann ein Schaldahr, wenn es durch 400 teilbar ist.

Legen Sie zunächst die benötigten Eigenschaften und Methoden flir eine entsprechende
Klasse schriftlich fest.
Zeichnen Sie ggf. Struktogramme für die einzelnen Methoden.
Schreiben Sie dann das Programm.

You might also like