100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Exam (elaborations)

CS 31 Worksheet Week 4 Concepts While Loops, Do While Loops, String Traversal, Functions.

Rating
-
Sold
-
Pages
7
Grade
A+
Uploaded on
09-10-2022
Written in
2022/2023

CS 31 Worksheet Week 4 Concepts While Loops, Do While Loops, String Traversal, Functions.

Institution
Course

Content preview

Stuvia.com - The Marketplace to Buy and Sell your Study Material




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

Written for

Course

Document information

Uploaded on
October 9, 2022
Number of pages
7
Written in
2022/2023
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$8.49
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
haileywangui

Get to know the seller

Seller avatar
haileywangui Stanford University
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
3 year
Number of followers
0
Documents
141
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions