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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
cst 116 Austin Guertin
11a 10.10 pg 282-283 #1 (submit code and runs)
#include <iostream>
using namespace::std;
int main()
{
int Choice;
int Dollars;
int id[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
string Student_Club[10] = { "Computer Systems Society", "Society of Women Engineers", "Sigma Tu Gamma", "Trekkies", "Home Brewers", "High Altitude Ballooning", "Rugby", "IEEE", "International Club", "Dance Club" };
string President[10] = { "Kim Cares", "Jennie Queen", "Storm Drain", "C. Kirk", "Ross Coe", "Justin Time", "Ryan Johns", "Marc Bansmere", "Kong Mbonkum", "Will Shaver" };
int Students[10] = { 49, 51, 241, 230, 15, 19, 25, 36, 102, 64 };
for (int i = 0; i < 10; i++)
{
cout << "\n-----Club #" << i + 1 << "-----\n";
cout << "\nStudent Club: " << Student_Club[i] << "\nPresident: " << President[i] << "\nAmount of students: " << Students[i] << "\n";
}
cout << "\n------------------------------------------------------------------------------------------\n";
cout << "\n\nOut of all of the students clubs, which one of the would you like to select:\n\n#";
cin >> Choice;
if (Choice > 10 || Choice < 1)
{
cout << "\n\n\nYou have inputted an incorrect number, rerun the program.\n\n\n\n";
return 0;
}
cout << "\nYou want to choose club #" << Choice << "? So that is:\n";
cout << "\nStudent Club: " << Student_Club[Choice - 1] << "\nPresident: " << President[Choice - 1] << "\nAmount of students: " << Students[Choice - 1] << "\n";
Dollars = Students[Choice - 1] * 75;
cout << "\nAnd since the club receives $75 for each student in the club, and there are " << Students[Choice - 1] << " students, \nand the club number is #" << Choice << ", or the club of " << Student_Club[Choice - 1] << ", it will receive $" << Dollars << "\n\n\n\n";
}
11b 10.14 pg 289-292 #1 (submit code and runs)
#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(const int varX[], const int varY[], int varZ[]);
void PrintFunction(const int varX[], const int varY[], const int varZ[]);
const int SIZE = 5;
int main()
{
int varX[5];
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);
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 < 5; x++)
varY[x] = x + 100;
}
void FunctionTwo(const 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];
} 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;
}
11c 10.15 pg 292-293 #1 (submit code and runs)
#include <iostream>
using namespace std;
bool IsAPalindrome(string cString) {
for (int i = 0; i < cString.length() / 2; i++)
{
if (cString[i] != cString[cString.length() - 1 - i])
{
return false;
}
}
return true;
}
bool IsAlphaStr(string cString)
{
for (int i = 0; i < cString.length(); i++)
{
if (!((cString[i] >= 'A' && cString[i] <= 'Z') || (cString[i] >= 'a' && cString[i] <= 'z'))) {
return false;
}
}
return true;
}
int CountChar(string cString, char ch)
{
int count = 0;
for (int i = 0; i < cString.length(); i++)
{
if (cString[i] == ch)
{
count++;
}
}
return count;
}
int main()
{
string s;
cout << "Enter the string: \n\n";
cin >> s;
if (IsAPalindrome(s))
{
cout << "\nThis string --" << s << "-- is a palindrome\n" << endl;
}
else
{
cout << "\nThis string --" << s << "-- is not a palindrome\n" << endl;
}
if (IsAlphaStr(s))
{
cout << "\nThis string --" << s << "-- is an alphabetic\n" << endl;
}
else
{
cout << "\nThe string --"<<s<<"-- is not an alphabetic\n" << endl;
}
char ch;
cout << "\nEnter a character to search for: \n\n";
cin >> ch;
cout << "\nNumber of times --"<< ch << "-- has occurred: \n\n" << CountChar(s, ch) << endl;
return 0;
}
|