Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Uwe Wienkop
Prog2-SS2020-Wienkop
Commits
0cebf2be
Commit
0cebf2be
authored
Apr 22, 2020
by
Uwe Wienkop
Browse files
2020-04-22
parent
05030622
Changes
7
Show whitespace changes
Inline
Side-by-side
01OperatorOverloading/Program.cs
View file @
0cebf2be
...
@@ -18,6 +18,7 @@ namespace _01OperatorOverloading
...
@@ -18,6 +18,7 @@ namespace _01OperatorOverloading
z
=
Convert
.
ToInt32
(
d
[
0
]);
z
=
Convert
.
ToInt32
(
d
[
0
]);
n
=
Convert
.
ToInt32
(
d
[
1
]);
n
=
Convert
.
ToInt32
(
d
[
1
]);
}
}
public
static
Bruch
Mult1
(
Bruch
b1
,
Bruch
b2
)
public
static
Bruch
Mult1
(
Bruch
b1
,
Bruch
b2
)
{
{
int
zaehler
=
b1
.
z
*
b2
.
z
;
int
zaehler
=
b1
.
z
*
b2
.
z
;
...
@@ -36,7 +37,13 @@ namespace _01OperatorOverloading
...
@@ -36,7 +37,13 @@ namespace _01OperatorOverloading
=>
new
Bruch
(
b1
.
z
*
b2
.
z
,
b1
.
n
*
b2
.
n
);
=>
new
Bruch
(
b1
.
z
*
b2
.
z
,
b1
.
n
*
b2
.
n
);
public
static
Bruch
operator
*(
Bruch
b1
,
Bruch
b2
)
public
static
Bruch
operator
*(
Bruch
b1
,
Bruch
b2
)
=>
new
Bruch
(
b1
.
z
*
b2
.
z
,
b1
.
n
*
b2
.
n
);
=>
new
Bruch
(
b1
.
z
*
b2
.
z
,
b1
.
n
*
b2
.
n
);
public
static
bool
operator
==(
Bruch
b1
,
Bruch
b2
)
=>
b1
.
z
==
b2
.
z
&&
b1
.
n
==
b2
.
n
;
// nur wenn b1.z == b2.z ist, wird b1.n == b2.n ausgeführt
public
static
bool
operator
!=(
Bruch
b1
,
Bruch
b2
)
=>
!(
b1
==
b2
);
// Konvertierungsoperatoren:
public
static
explicit
operator
int
(
Bruch
b
)
public
static
explicit
operator
int
(
Bruch
b
)
=>
b
.
z
/
b
.
n
;
=>
b
.
z
/
b
.
n
;
public
static
implicit
operator
double
(
Bruch
b
)
public
static
implicit
operator
double
(
Bruch
b
)
...
@@ -56,21 +63,39 @@ namespace _01OperatorOverloading
...
@@ -56,21 +63,39 @@ namespace _01OperatorOverloading
Bruch
b2
=
new
Bruch
(
2
);
Bruch
b2
=
new
Bruch
(
2
);
Bruch
b3
=
new
Bruch
(
"3/4"
);
Bruch
b3
=
new
Bruch
(
"3/4"
);
// Bruch e1 = 3.Mult(b1);
// Bruch e1 = b1.Mult(b2); // wäre möglich
// Bruch e1 = b1.Mult(2); // ist möglich
// Bruch e1 = 3.Mult(b1); // ist nicht möglich, da 3 vom Typ int und nicht Bruch ist
Bruch
e2
=
Bruch
.
Mult
(
b1
,
b2
);
Bruch
e2
=
Bruch
.
Mult
(
b1
,
b2
);
//Bruch e2 = Bruch.Mult(2, b2); // nicht nötig, über Konv.Op. erledigt
//Bruch e2 = Bruch.Mult(b1, 2); // nicht nötig, über Konv.Op. erledigt
Bruch
e3
=
b1
*
b2
;
Bruch
e3
=
b1
*
b2
;
Bruch
e4
=
b1
*
2
;
Bruch
e4
=
b1
*
2
;
Bruch
e5
=
2
*
b1
;
Bruch
e5
=
2
*
b1
;
// 2 --> impl.Konv. in einen Bruch
// Wir haben Bruch.operator*(Bruch, Bruch)
// int.op*, double.op*, Bruch.op*
// Bruch.op*(Bruch, Bruch)
// int->Bruch, Bruch ???
// 2 --> impl.Konv. --> Bruch
// op* (Bruch, Bruch)
// op* (Bruch, Bruch)
// double.op*(int, double) --> double.op*(int-->double, double)
int
k2
=
3
*
(
int
)
4.5
;
int
k
=
(
int
)
e3
;
// explizite Konvertierung
int
k
=
(
int
)
e3
;
// explizite Konvertierung
double
d
=
e3
;
// implizite Konvertierung
double
d
=
e3
;
// implizite Konvertierung
Console
.
WriteLine
(
k
);
Console
.
WriteLine
(
k
);
Console
.
WriteLine
(
d
);
Console
.
WriteLine
(
d
);
double
d2
=
34
;
double
d2
=
(
int
)
34
;
int
k2
=
(
int
)
3.5
;
int
k3
=
(
int
)
3.5
;
Bruch
b4
=
new
Bruch
(
2
,
5
);
// b4: neuer Speicher #100000
Bruch
b5
=
new
Bruch
(
2
,
5
);
// b5: neuer Speicher #200000
if
(
b4
==
b5
)
Console
.
WriteLine
(
"Sind gleich"
);
else
Console
.
WriteLine
(
"Sind unterschiedlich"
);
}
}
}
}
}
}
01OperatorOverloading/bin/Debug/netcoreapp3.1/01OperatorOverloading.dll
View file @
0cebf2be
No preview for this file type
01OperatorOverloading/bin/Debug/netcoreapp3.1/01OperatorOverloading.pdb
View file @
0cebf2be
No preview for this file type
01OperatorOverloading/obj/Debug/netcoreapp3.1/01OperatorOverloading.csprojAssemblyReference.cache
View file @
0cebf2be
No preview for this file type
01OperatorOverloading/obj/Debug/netcoreapp3.1/01OperatorOverloading.dll
View file @
0cebf2be
No preview for this file type
01OperatorOverloading/obj/Debug/netcoreapp3.1/01OperatorOverloading.pdb
View file @
0cebf2be
No preview for this file type
01OperatorTrueFalse/Program.cs
View file @
0cebf2be
...
@@ -37,6 +37,8 @@ namespace _01OperatorTrueFalse
...
@@ -37,6 +37,8 @@ namespace _01OperatorTrueFalse
public
static
bool
operator
!=(
LaunchStatus
x
,
LaunchStatus
y
)
=>
!(
x
==
y
);
public
static
bool
operator
!=(
LaunchStatus
x
,
LaunchStatus
y
)
=>
!(
x
==
y
);
public
override
bool
Equals
(
object
obj
)
=>
obj
is
LaunchStatus
other
&&
this
==
other
;
public
override
bool
Equals
(
object
obj
)
=>
obj
is
LaunchStatus
other
&&
this
==
other
;
// Equals testet, ob ein hier: Launchstatus-Obj. gleich einem anderen OBJEKT ist
// Dies setzt gleiche Typen und gleiche Inhalte voraus!
public
override
int
GetHashCode
()
=>
status
;
public
override
int
GetHashCode
()
=>
status
;
}
}
...
@@ -49,11 +51,16 @@ namespace _01OperatorTrueFalse
...
@@ -49,11 +51,16 @@ namespace _01OperatorTrueFalse
// Überladung von true und false. Daher wird GetNavigationLaunchStatus nur aufgerufen,
// Überladung von true und false. Daher wird GetNavigationLaunchStatus nur aufgerufen,
// wenn GetFuelLauchStatus gleich true ist!
// wenn GetFuelLauchStatus gleich true ist!
LaunchStatus
okToLaunch1
=
GetFuelLaunchStatus
()
&&
GetNavigationLaunchStatus
();
LaunchStatus
okToLaunch1
=
GetFuelLaunchStatus
()
&&
GetNavigationLaunchStatus
();
// GetFuelLauchStatus() --> LaunchStatus ---(op true)--> bool
// Wenn true --> GetNavigationLaunchStatus() --> LaunschStatus ---(op true)--> bool
// GetFuelLaunchStatus() & GetNavigationLaunchStatus(); --- Einfaches &
Console
.
WriteLine
(
"----------------"
);
Console
.
WriteLine
(
"----------------"
);
LaunchStatus
okToLaunch2
=
GetFuelLaunchStatus
()
&
GetNavigationLaunchStatus
();
LaunchStatus
okToLaunch2
=
GetFuelLaunchStatus
()
&
GetNavigationLaunchStatus
();
// Nochmals: Durch das überladene true ist der nachfolgende Ausdruck zulässig!
// Nochmals: Durch das überladene true ist der nachfolgende Ausdruck zulässig!
Console
.
WriteLine
(
"----------------"
);
Console
.
WriteLine
(
"----------------"
);
Console
.
WriteLine
(
okToLaunch1
?
"Ready to go!"
:
"Wait!"
);
Console
.
WriteLine
(
okToLaunch1
?
"Ready to go!"
:
"Wait!"
);
// okToLaunch1 ---(op true)--> bool
//if (okToLaunch1.Equals(okToLaunch2))
}
}
static
LaunchStatus
GetFuelLaunchStatus
()
static
LaunchStatus
GetFuelLaunchStatus
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment