<commit_before>---
num: "h13"
desc: "TBD"
ready: false
assigned: 2016-11-15 14:00:00.00-8:00
due: 2016-11-17 14:00:00.00-8:00
---
Reading: Read Chapter xx, with a special focus on pages xx-xx.    If you don't have a copy of the textbook yet, there is one on reserve at the library under "COMP000-STAFF - Permanent Reserve".

1.	(0 pts) INSERT QUESTIONS.
	<div style="margin-bottom:4em"></div><commit_msg>new hw13<commit_after>---
num: "h13"
desc: "Homework 13"
ready: false
assigned: 2016-11-15 14:00:00.00-8:00
due: 2016-11-17 14:00:00.00-8:00
---
{% include no_staples_box.html %}
Reading: Read Chapter 8 and the lecture notes.    If you do not have a copy of the textbook yet, there is one on reserve at the library under "COMP000-STAFF - Permanent Reserve".

<b>PLEASE MARK YOUR HOMEWORK CLEARLY, REGARDLESS OF IF YOU WRITE IT OUT IN INK OR PENCIL! FOR BEST RESULTS, SAVE THIS PAGE AS A PDF, THEN PRINT THE PDF.</b>

<div style="margin-bottom:4em"></div>

1.(4 pts) Name 4 reasons why breaking up a program into multiple files can be advantageous.
<div style="margin-bottom:8em"></div>

2.(2 pts) How are ordinary arrays of characters and c-strings similar and how are they dissimilar?
<div style="margin-bottom:4em"></div>

3.(4 pts) What are two (2) things that are wrong with this use of a c-string?

<div markdown="1">
```cpp
char cs[5] = "abcd";
for (int i = 0; i <= 5; i++)
	if (cs[i] != 'a') cs[i] = 'x';
```
</div>
<div style="margin-bottom:8em"></div>

4.(4 pts) What is the output of the following code?

<div markdown="1">
```cpp
char s1[3] = "abc", s2[3] = "ABC";
if (strcmp(s1, s2)) cout << "Yo!";
else cout << "Hey!";
```
</div>
<div class="pagebreak"></div>

5.(8 pts) Given the code shown below, what happens in each of these cases?

a) If the user enters: abc def ghijk
<div style="margin-bottom:4em"></div>
b) If the user enters: abcx123
<div style="margin-bottom:4em"></div>
c) If the user enters: abcxxyz
<div style="margin-bottom:4em"></div>
d) If the user enters: abcx123 456
<div style="margin-bottom:4em"></div>

6.(8 pts) The following code takes in a string input from the user and performs a multiplication, as seen in the example run here:

```
Enter 2 numbers to be multiplied, like this: num1*num2: 15*3
The answer is: 45
```

Complete the missing code below that performs this task (it can be done in 2 lines or more).

<div markdown="1">
```cpp
string s; int k(0);
cout << "Enter 2 numbers to be multiplied, like this: num1*num2: "; 
cin >> s; 
____________________________________
____________________________________

cout << "The answer is: " << k << endl;
```
</div>

7.(10 pts) Write a function called `swapFrontBack` that takes as input a vector of integers. The function should swap the first element in the vector with the last element in the vector. The function should check if the vector is empty to prevent errors.

{'fraction_non_alphanumeric': 0.13517289556409362, 'fraction_numerical': 0.05344044708347887, 'mean_word_length': 4.274401473296501, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2035566', 'n_tokens_mistral': 1075, 'n_tokens_neox': 959, 'n_words': 408}