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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
// Tyler Taormina
// CST 116
// Module 11B Debugging Exercise
// pg 289-292
// #1 for 10pts
#include <iostream>
#include <iomanip>
using std::cin;
using std::cout;
using std::endl;
using std::setw;
void GetAndDisplayWelcomeInfo ( );
void FunctionOne ( int varX[], int varY[] );
void FunctionTwo ( int varX[], const int varY[], int varZ[] );
void PrintFunction ( const int varX[], const int varY[],
const int varZ[] );
const int SIZE = 10;
int main ( )
{
int varX[SIZE];
int varY[SIZE];
int varZ[SIZE]; // Notice how we used the const here!
// Breakpoint 1
// Put breakpoint on the following line
GetAndDisplayWelcomeInfo ( );
FunctionOne ( varX, varY );
// Breakpoint 3
// Put breakpoint on the following line
FunctionTwo ( varX, varY, varZ );
varZ[0] = -99;
PrintFunction ( varX, varY, varZ );
return 0;
}
void GetAndDisplayWelcomeInfo ( )
{
char name[2][20]; // First name in row 0, last name in row 1
cout << "Please enter your first name: ";
cin >> name[0];
cout << "\nPlease enter your last name: ";
cin >> name[1];
// Breakpoint 2
// Put breakpoint on the following line
cout << "\n\n\tWelcome " << name[0] << " " << name[1]
<< "!\n\t Hope all is well \n\n";
}
void FunctionOne ( int varX[], int varY[] )
{
for ( int x = 0; x < SIZE; x++ ) // NOTICE '<' NOT <=
// Breakpoint 4
// Put breakpoint on the following line
varX[x] = x;
for ( int x = 0; x < SIZE; x++ )
varY[x] = x + 100;
}
void FunctionTwo (int varX[], const int varY[], int varZ[] )
{
for ( int x = 0; x < SIZE; x++ ) // Notice the const SIZE here
varZ[x] = varX[x] + varY[x];
varX[1] = 99;
}
void PrintFunction ( const int varX[20], const int varY[20],
const int varZ[20] )
{
int x;
cout << " \t x \t y \t z\n\n";
for ( x = 0; x < SIZE; x++ )
cout << "\t" << setw ( 3 ) << varX[x]
<< "\t " << varY[x]
<< "\t " << varZ[x] << endl;
}
|