forked from aaronbloomfield/pdr
-
Notifications
You must be signed in to change notification settings - Fork 228
/
debug.cpp.html
82 lines (62 loc) · 8.39 KB
/
debug.cpp.html
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite">
<title>debug.cpp</title>
</head>
<body style="background-color:white">
<pre><i><span style="color:#9A1900">//----------------------------------------------------------------------</span></i>
<i><span style="color:#9A1900">// This program reads five numbers from the keyboard, and prints out the</span></i>
<i><span style="color:#9A1900">// average and the maximum value</span></i>
<i><span style="color:#9A1900">//----------------------------------------------------------------------</span></i>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000"><iostream></span>
<b><span style="color:#0000FF">using</span></b> <b><span style="color:#0000FF">namespace</span></b> std<span style="color:#990000">;</span>
<i><span style="color:#9A1900">// Global Constants</span></i>
<b><span style="color:#0000FF">const</span></b> <span style="color:#009900">int</span> MAX <span style="color:#990000">=</span> <span style="color:#993399">5</span><span style="color:#990000">;</span>
<i><span style="color:#9A1900">// Function Prototypes</span></i>
<span style="color:#009900">double</span> <b><span style="color:#000000">GetAverage</span></b><span style="color:#990000">(</span> <span style="color:#009900">int</span> nIn<span style="color:#990000">[],</span> <span style="color:#009900">int</span> nMax<span style="color:#990000">);</span>
<span style="color:#009900">int</span> <b><span style="color:#000000">GetMax</span></b><span style="color:#990000">(</span> <span style="color:#009900">int</span> nIn<span style="color:#990000">[],</span> <span style="color:#009900">int</span> nMax <span style="color:#990000">);</span>
<span style="color:#009900">int</span> <b><span style="color:#000000">main</span></b><span style="color:#990000">()</span> <span style="color:#FF0000">{</span>
<span style="color:#009900">int</span> nValues<span style="color:#990000">[</span>MAX<span style="color:#990000">];</span>
<span style="color:#009900">int</span> nCount<span style="color:#990000">;</span>
<i><span style="color:#9A1900">// Display a prompt:</span></i>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"Enter five numbers: "</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<i><span style="color:#9A1900">// First we read in the numbers.</span></i>
<b><span style="color:#0000FF">for</span></b> <span style="color:#990000">(</span> nCount <span style="color:#990000">=</span> <span style="color:#993399">0</span><span style="color:#990000">;</span> nCount <span style="color:#990000"><</span> MAX<span style="color:#990000">;</span> nCount<span style="color:#990000">++</span> <span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"Enter the next number : "</span><span style="color:#990000">;</span>
cin <span style="color:#990000">>></span> nValues<span style="color:#990000">[</span><span style="color:#993399">1</span><span style="color:#990000">];</span>
<span style="color:#FF0000">}</span>
<i><span style="color:#9A1900">// Now we echo the input back to the user</span></i>
<b><span style="color:#0000FF">for</span></b> <span style="color:#990000">(</span> nCount <span style="color:#990000">=</span> <span style="color:#993399">1</span><span style="color:#990000">;</span> nCount <span style="color:#990000"><</span> MAX<span style="color:#990000">;</span> nCount<span style="color:#990000">++)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"Value [ "</span> <span style="color:#990000"><<</span> nCount <span style="color:#990000"><<</span> <span style="color:#FF0000">"] is : "</span> <span style="color:#990000"><<</span> nValues<span style="color:#990000">[</span>nCount<span style="color:#990000">]</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<i><span style="color:#9A1900">// Now lets call a function to get the average:</span></i>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The average is "</span> <span style="color:#990000"><<</span> <b><span style="color:#000000">GetAverage</span></b><span style="color:#990000">(</span>nValues<span style="color:#990000">,</span> MAX <span style="color:#990000">)</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<i><span style="color:#9A1900">// Now lets call a function to get the max:</span></i>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"The max is "</span> <span style="color:#990000"><<</span> <b><span style="color:#000000">GetMax</span></b><span style="color:#990000">(</span>nValues<span style="color:#990000">,</span> MAX <span style="color:#990000">)</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#0000FF">return</span></b> <span style="color:#993399">0</span><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span> <i><span style="color:#9A1900">// End of main</span></i>
<span style="color:#009900">double</span> <b><span style="color:#000000">GetAverage</span></b><span style="color:#990000">(</span><span style="color:#009900">int</span> nIn<span style="color:#990000">[],</span> <span style="color:#009900">int</span> nMax<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<span style="color:#009900">double</span> temp <span style="color:#990000">=</span> <span style="color:#993399">0.0</span><span style="color:#990000">;</span>
<b><span style="color:#0000FF">for</span></b> <span style="color:#990000">(</span> <span style="color:#009900">int</span> i <span style="color:#990000">=</span> <span style="color:#993399">0</span><span style="color:#990000">;</span> i <span style="color:#990000">></span> nMax<span style="color:#990000">;</span> i<span style="color:#990000">++)</span>
temp <span style="color:#990000">+=</span> nIn<span style="color:#990000">[</span>i<span style="color:#990000">];</span>
temp <span style="color:#990000">/=</span> nMax<span style="color:#990000">;</span>
<b><span style="color:#0000FF">return</span></b> temp<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span> <i><span style="color:#9A1900">// End of GetAverage()</span></i>
<span style="color:#009900">int</span> <b><span style="color:#000000">GetMax</span></b><span style="color:#990000">(</span> <span style="color:#009900">int</span> nIn<span style="color:#990000">[],</span> <span style="color:#009900">int</span> nMax<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<span style="color:#009900">int</span> nBiggest <span style="color:#990000">=</span> nIn<span style="color:#990000">[</span><span style="color:#993399">0</span><span style="color:#990000">];</span>
<b><span style="color:#0000FF">for</span></b> <span style="color:#990000">(</span> <span style="color:#009900">int</span> i <span style="color:#990000">=</span> <span style="color:#993399">1</span><span style="color:#990000">;</span> i <span style="color:#990000"><</span> nMax<span style="color:#990000">;</span> i<span style="color:#990000">++)</span>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>nBiggest <span style="color:#990000">></span> nIn<span style="color:#990000">[</span>i<span style="color:#990000">])</span>
nBiggest <span style="color:#990000">=</span> nIn<span style="color:#990000">[</span>i<span style="color:#990000">];</span>
<b><span style="color:#0000FF">return</span></b> nBiggest<span style="color:#990000">;</span>
<span style="color:#FF0000">}</span> <i><span style="color:#9A1900">// End of GetMax()</span></i>
<i><span style="color:#9A1900">//----------------------------------------------------------------------</span></i>
<i><span style="color:#9A1900">// END OF LISTING</span></i>
<i><span style="color:#9A1900">//----------------------------------------------------------------------</span></i>
</pre>
</body>
</html>