CS 31 Worksheet Week 4
Concepts: While Loops, Do While Loops,
String Traversal, Functions
Downloaded by: Kayyh |
Distribution of this document is illegal
, Stuvia.com - The Marketplace to Buy and Sell your Study Material
CS 31 Worksheet Week 4
This worksheet is entirely optional, and meant for extra practice. Some problems will
be more challenging than others and are designed to have you apply your knowledge
beyond the examples presented in lecture, discussion or projects. Although exams are
online this quarter, it is still in your best interest to practice these problems by hand and
not rely on a compiler.
Solutions are written in red. The solutions for programming problems are not
absolute, it is okay if your code looks different; this is just one way to solve the specific
problem.
If you have any questions or concerns please contact your LA or go to any of the LA
office hours.
Concepts: While Loops, Do While Loops, String Traversal, Functions
m
er as
Reading Problems
co
eH w
1. What does the following code snippet output? What does the call to mystery in
main() return? What does main() return?
o.
#include <iostream>
rs e
ou urc
using namespace std;
int mystery(int a, int b) {
o
int count = 0;
aC s
while (count < 2) {
vi y re
a = a + b/2;
b = a + 5;
cout << "a: " << a << " b: " << b << endl;
count++;
ed d
}
ar stu
return count;
}
int main() {
is
int a = 5, b = 10;
cout << "a: " << a << " b: " << b << endl;
Th
mystery(a, b);
cout << "a: " << a << " b: " << b << endl;
if (a % b == 0) {
sh
return 1;
}
return 0;
}
This study source was downloaded by 100000826342158 from CourseHero.com on 10-06-2021 14:19:00 GMT -05:00
https://www.coursehero.com/file/81070311/CS31-F20-Solutions-Week-4docx/
Downloaded by: Kayyh |
Distribution of this document is illegal