summaryrefslogtreecommitdiffstats
path: root/contents/wissen/cpp-tutorial/07-funktionen.php
blob: 485e733f1ecec4acb3190d880157ddaede8e3ed6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
	$author = 'Jakob und Matthias';
	$pathToRoot = '../../../';
?>
<?php
	include($pathToRoot . 'includes/firstinclude.inc.php');
	include($pathToRoot . 'includes/header.inc.php');
	include($pathToRoot . 'includes/mainmenu.inc.php');
	
	include($pathToRoot . 'sidebars/wissen/cpp.inc.php');
?>

<div id="inhalt">
	<h2>
		7. Funktionen
	</h2>
	<p>
		<code style="white-space:pre">
#include &lt;iostream&gt;
	
int summe(int iX, int iY)
{
  // Hier wird die Summe von iX und iY zurückgegeben.
  return iX + iY;
}
	
int main()
{
  int x,y;
  
  std::cout &lt;&lt; &quot;Geben sie bitte zwei Zahlen ein.&quot; &lt;&lt; std::endl;
  std::cin &gt;&gt; x;
  std::cin &gt;&gt; y;
  std::cout &lt;&lt; &quot;Die Summe ihrer Zahlen ist: &quot; &lt;&lt; summe(x, y) &lt;&lt; std::endl;
  
  return 0;
}
	
		</code>
	</p>
<p>
In diesem Programm werden erstmal eigene Funktionen benutzt.
</p>
<p>
Der Name unserer ersten Funktion ist summe.
int ist dabei der Rückgabewert, d. h., beim Aufruf der Funktion gibt die Funktion eine Ganzzahl
an den Aufrufer zurück. iX und iY ist Parameter, d. h., dies sind Variablen, die vom Aufrufer
übergeben werden.
</p>
<h3>Aufgabe:</h3>
<p>
Erstelle ein Programm, das mit Hilfe einer
Funktion überprüft, ob eine Zahl ohne Rest
durch 2 teilbar ist.
</p>
</div>
	
<?php
	include($pathToRoot . 'includes/footer.inc.php');
	include($pathToRoot . 'includes/lastinclude.inc.php');
?>