Professional Documents
Culture Documents
WK 2 Problems #2
WK 2 Problems #2
WK 2 Problems #2
For the following problems, predict the output and verify with your local machine.
1.
int problem1() {
string s = "\n\n\n"; string s = "nnn"
2.
int problem2() {
string s1 = "I\'m learning strings";
erase - starts with 0 (Up until index 3 but not including index 3
cout << s1.erase(0, 3) << "\n"; s = " learning strings
cout << s1[2]; output = e
return 0;
}
3.
int problem3() {
string s;
getline(cin, s); // input is Hello World![Enter]
s = "Hello World!"
cout << s.substr(4);
return 0; output = "o World!"
}
4.
int problem4() {
int x, y;
6. Output
Hello, my name is [name],
and I'm a [student year].
I would rate PIC10A so far a [score] out of 10.
to the console, where [name], [student year], and [score] are user inputted, separated by
spaces. The variable used to hold score should be an integer. For example, given user
input Alex grad 10[Enter], the desired output is
Hello, my name is Alex,
and I'm a grad.
I would rate PIC10A so far a 10 out of 10.
You may assume that name and student year are just one word each.
7. Take in 5 integers from user input, and output the integer closest to the average of the
given integers. You may assume that the inputted integers are between INT_MIN / 5 and
INT_MAX / 5.
8. Define a string s = "the quick brown fox jumped". Without using any other hard-coded
string literals (i.e. only use string manipulations), define a string holding "the quick fox
picked up". Output the string to double-check.